1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define NOT_IMPLEMENTED(x) \
22 g_error ("FIXME: %s is not yet implemented. (trampoline)", x);
24 #define EMIT_COND_BRANCH(ins,cond) \
26 if (ins->flags & MONO_INST_BRLABEL) { \
27 if (ins->inst_i0->inst_c0) { \
29 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
30 if (s390_is_uimm16(displace)) { \
31 s390_brc (code, cond, displace); \
33 s390_jcl (code, cond, displace); \
36 mono_add_patch_info (cfg, code - cfg->native_code, \
37 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
38 s390_jcl (code, cond, 0); \
41 if (ins->inst_true_bb->native_offset) { \
43 displace = ((cfg->native_code + \
44 ins->inst_true_bb->native_offset) - code) / 2; \
45 if (s390_is_uimm16(displace)) { \
46 s390_brc (code, cond, displace); \
48 s390_jcl (code, cond, displace); \
51 mono_add_patch_info (cfg, code - cfg->native_code, \
52 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
53 s390_jcl (code, cond, 0); \
58 #define EMIT_UNCOND_BRANCH(ins) \
60 if (ins->flags & MONO_INST_BRLABEL) { \
61 if (ins->inst_i0->inst_c0) { \
63 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
64 if (s390_is_uimm16(displace)) { \
65 s390_brc (code, S390_CC_UN, displace); \
67 s390_jcl (code, S390_CC_UN, displace); \
70 mono_add_patch_info (cfg, code - cfg->native_code, \
71 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
72 s390_jcl (code, S390_CC_UN, 0); \
75 if (ins->inst_target_bb->native_offset) { \
77 displace = ((cfg->native_code + \
78 ins->inst_target_bb->native_offset) - code) / 2; \
79 if (s390_is_uimm16(displace)) { \
80 s390_brc (code, S390_CC_UN, displace); \
82 s390_jcl (code, S390_CC_UN, displace); \
85 mono_add_patch_info (cfg, code - cfg->native_code, \
86 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
87 s390_jcl (code, S390_CC_UN, 0); \
92 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
94 mono_add_patch_info (cfg, code - cfg->native_code, \
95 MONO_PATCH_INFO_EXC, exc_name); \
96 s390_jcl (code, cond, 0); \
100 #define DEBUG(a) if (cfg->verbose_level > 1) a
101 #define reg_is_freeable(r) ((r) >= 3 && (r) <= 10)
102 #define freg_is_freeable(r) ((r) >= 1 && (r) <= 14)
104 /*----------------------------------------*/
105 /* use s390_r3-s390_r10 as temp registers */
106 /*----------------------------------------*/
107 #define S390_CALLER_REGS (0x03f8)
109 /*----------------------------------------*/
110 /* use s390_f2-s390_f14 as temp registers */
111 /*----------------------------------------*/
112 #define S390_CALLER_FREGS (0x73f8)
114 #define S390_TRACE_STACK_SIZE (5*sizeof(gint32)+3*sizeof(gdouble))
116 /*========================= End of Defines =========================*/
118 /*------------------------------------------------------------------*/
119 /* I n c l u d e s */
120 /*------------------------------------------------------------------*/
125 #include <mono/metadata/appdomain.h>
126 #include <mono/metadata/debug-helpers.h>
127 #include <mono/metadata/profiler-private.h>
128 #include <mono/utils/mono-math.h>
130 #include "mini-s390.h"
132 #include "cpu-s390.h"
134 /*========================= End of Includes ========================*/
136 /*------------------------------------------------------------------*/
137 /* T y p e d e f s */
138 /*------------------------------------------------------------------*/
147 /*------------------------------------------------------------------*/
148 /* Used by the instrument_emit_epilog */
149 /*------------------------------------------------------------------*/
166 typedef struct InstList InstList;
183 gint32 offset; /* offset from caller's stack */
184 gint32 offparm; /* offset on callee's stack */
185 guint16 vtsize; /* in param area */
187 guint8 regtype; /* See RegType* */
188 guint32 size; /* Size of structure used by RegTypeStructByVal */
200 gint32 gr[5]; /* R2-R6 */
201 gdouble fp[3]; /* F0-F2 */
202 } __attribute__ ((packed)) RegParm;
204 /*========================= End of Typedefs ========================*/
206 /*------------------------------------------------------------------*/
207 /* P r o t o t y p e s */
208 /*------------------------------------------------------------------*/
210 static guint32 *emit_memcpy (guint8 *, int, int, int, int, int);
211 static void indent (int);
212 static void decodeParm (MonoType *, void *, int);
213 static void enter_method (MonoMethod *, RegParm *, char *);
214 static void leave_method (MonoMethod *, ...);
215 static gboolean is_regsize_var (MonoType *);
216 static void add_general (guint *, size_data *, ArgInfo *, gboolean);
217 static CallInfo * calculate_sizes (MonoMethodSignature *, size_data *, gboolean);
218 static void peephole_pass (MonoCompile *, MonoBasicBlock *);
219 static int mono_spillvar_offset (MonoCompile *, int);
220 static int mono_spillvar_offset_float (MonoCompile *, int);
221 static void print_ins (int, MonoInst *);
222 static void print_regtrack (RegTrack *, int);
223 static InstList * inst_list_prepend (MonoMemPool *, InstList *, MonoInst *);
224 static int get_register_force_spilling (MonoCompile *, InstList *, MonoInst *, int);
225 static int get_register_spilling (MonoCompile *, InstList *, MonoInst *, guint32, int);
226 static int get_float_register_spilling (MonoCompile *, InstList *, MonoInst *, guint32, int);
227 static MonoInst * create_copy_ins (MonoCompile *, int, int, MonoInst *);
228 static MonoInst * create_copy_ins_float (MonoCompile *, int, int, MonoInst *);
229 static MonoInst * create_spilled_store (MonoCompile *, int, int, int, MonoInst *);
230 static MonoInst * create_spilled_store_float (MonoCompile *, int, int, int, MonoInst *);
231 static void insert_before_ins (MonoInst *, InstList *, MonoInst *);
232 static int alloc_int_reg (MonoCompile *, InstList *, MonoInst *, int, guint32);
233 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
234 static unsigned char * mono_emit_stack_alloc (guchar *, MonoInst *);
236 /*========================= End of Prototypes ======================*/
238 /*------------------------------------------------------------------*/
239 /* G l o b a l V a r i a b l e s */
240 /*------------------------------------------------------------------*/
242 int mono_exc_esp_offset = 0;
244 static int indent_level = 0;
246 static const char*const * ins_spec = s390;
248 /*====================== End of Global Variables ===================*/
250 /*------------------------------------------------------------------*/
252 /* Name - mono_arch_regname */
254 /* Function - Returns the name of the register specified by */
255 /* the input parameter. */
257 /*------------------------------------------------------------------*/
260 mono_arch_regname (int reg) {
261 static const char * rnames[] = {
262 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
263 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
264 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
267 if (reg >= 0 && reg < 16)
272 /*========================= End of Function ========================*/
274 /*------------------------------------------------------------------*/
276 /* Name - emit_memcpy */
278 /* Function - Emit code to move from memory-to-memory based on */
279 /* the size of the variable. r0 is overwritten. */
281 /*------------------------------------------------------------------*/
284 emit_memcpy (guint8 *code, int size, int dreg, int doffset, int sreg, int soffset)
288 s390_l (code, s390_r0, 0, sreg, soffset);
289 s390_st (code, s390_r0, 0, dreg, doffset);
293 s390_icm (code, s390_r0, 14, sreg, soffset);
294 s390_stcm (code, s390_r0, 14, dreg, doffset);
298 s390_lh (code, s390_r0, 0, sreg, soffset);
299 s390_sth (code, s390_r0, 0, dreg, doffset);
303 s390_ic (code, s390_r0, 0, sreg, soffset);
304 s390_stc (code, s390_r0, 0, dreg, doffset);
315 s390_mvc (code, len, dreg, doffset, sreg, soffset);
322 /*========================= End of Function ========================*/
324 /*------------------------------------------------------------------*/
326 /* Name - arch_get_argument_info */
328 /* Function - Gathers information on parameters such as size, */
329 /* alignment, and padding. arg_info should be large */
330 /* enough to hold param_count + 1 entries. */
332 /* Parameters - @csig - Method signature */
333 /* @param_count - No. of parameters to consider */
334 /* @arg_info - An array to store the result info */
336 /* Returns - Size of the activation frame */
338 /*------------------------------------------------------------------*/
341 mono_arch_get_argument_info (MonoMethodSignature *csig,
343 MonoJitArgumentInfo *arg_info)
345 int k, frame_size = 0;
346 int size, align, pad;
349 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
350 frame_size += sizeof (gpointer);
354 arg_info [0].offset = offset;
357 frame_size += sizeof (gpointer);
361 arg_info [0].size = frame_size;
363 for (k = 0; k < param_count; k++) {
366 size = mono_type_native_stack_size (csig->params [k], &align);
368 size = mono_type_stack_size (csig->params [k], &align);
370 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
371 arg_info [k].pad = pad;
373 arg_info [k + 1].pad = 0;
374 arg_info [k + 1].size = size;
376 arg_info [k + 1].offset = offset;
380 align = MONO_ARCH_FRAME_ALIGNMENT;
381 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
382 arg_info [k].pad = pad;
387 /*========================= End of Function ========================*/
389 /*------------------------------------------------------------------*/
393 /* Function - Perform nice indenting to current level */
395 /*------------------------------------------------------------------*/
401 indent_level += diff;
408 indent_level += diff;
411 /*========================= End of Function ========================*/
413 /*------------------------------------------------------------------*/
415 /* Name - decodeParm */
417 /* Function - Decode a parameter for the trace. */
419 /*------------------------------------------------------------------*/
422 decodeParm(MonoType *type, void *curParm, int size)
427 printf("[BYREF:%p], ", *((char **) curParm));
429 simpleType = type->type;
431 switch (simpleType) {
433 printf ("[INTPTR:%p], ", *((int **) curParm));
436 printf ("[UINTPTR:%p], ", *((int **) curParm));
438 case MONO_TYPE_BOOLEAN :
439 printf ("[BOOL:%p], ", *((int *) curParm));
441 case MONO_TYPE_CHAR :
442 printf ("[CHAR:%p], ", *((int *) curParm));
445 printf ("[INT1:%d], ", *((int *) curParm+3));
448 printf ("[INT2:%d], ", *((int *) curParm+2));
451 printf ("[INT4:%d], ", *((int *) curParm));
454 printf ("[UINT1:%ud], ", *((unsigned int *) curParm));
457 printf ("[UINT2:%ud], ", *((unsigned int *) curParm));
460 printf ("[UINT4:%ud], ", *((unsigned int *) curParm));
462 case MONO_TYPE_STRING : {
463 MonoString *s = *((MonoString **) curParm);
465 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
466 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
468 printf("[STRING:null], ");
472 case MONO_TYPE_CLASS :
473 case MONO_TYPE_OBJECT : {
474 MonoObject *obj = *((MonoObject **) curParm);
477 printf("[CLASS/OBJ:");
478 class = obj->vtable->klass;
479 if (class == mono_defaults.string_class) {
480 printf("[STRING:%p:%s]",
481 *obj, mono_string_to_utf8 (obj));
482 } else if (class == mono_defaults.int32_class) {
483 printf("[INT32:%p:%d]",
484 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
487 class->name_space, class->name, obj);
490 printf("[OBJECT:null], ");
495 printf("[PTR:%p], ", *((gpointer **) (curParm)));
497 case MONO_TYPE_FNPTR :
498 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
500 case MONO_TYPE_ARRAY :
501 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
503 case MONO_TYPE_SZARRAY :
504 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
507 printf("[INT8:%lld], ", *((gint64 *) (curParm)));
510 printf("[FLOAT4:%f], ", *((float *) (curParm)));
513 printf("[FLOAT8:%g], ", *((double *) (curParm)));
515 case MONO_TYPE_VALUETYPE : {
517 if (type->data.klass->enumtype) {
518 simpleType = type->data.klass->enum_basetype->type;
519 printf("{VALUETYPE} - ");
522 printf("[VALUETYPE:");
523 for (i = 0; i < size; i++)
524 printf("%02x,", *((guint8 *)curParm+i));
529 printf("[?? - %d], ",simpleType);
534 /*========================= End of Function ========================*/
536 /*------------------------------------------------------------------*/
538 /* Name - enter_method */
540 /* Function - Perform tracing of the entry to the current */
543 /*------------------------------------------------------------------*/
546 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
548 int i, oParm = 0, iParm = 0;
551 MonoJitArgumentInfo *arg_info;
552 MonoMethodSignature *sig;
559 fname = mono_method_full_name (method, TRUE);
561 printf ("ENTER: %s(", fname);
564 printf (") ip: %p sp: %p\n", __builtin_return_address (1), sp);
569 sig = method->signature;
571 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
573 if (cinfo->struct_ret) {
574 printf ("[VALUERET:%p], ", rParm->gr[0]);
579 gpointer *this = (gpointer *) rParm->gr[iParm];
580 obj = (MonoObject *) this;
581 if (method->klass->valuetype) {
583 printf("this:[value:%p:%08x], ",
584 this, *((guint32 *)(this+sizeof(MonoObject))));
586 printf ("this:[NULL], ");
589 class = obj->vtable->klass;
590 if (class == mono_defaults.string_class) {
591 printf ("this:[STRING:%p:%s], ",
592 obj, mono_string_to_utf8 ((MonoString *)obj));
594 printf ("this:%p[%s.%s], ",
595 obj, class->name_space, class->name);
598 printf ("this:NULL, ");
603 for (i = 0; i < sig->param_count; ++i) {
604 ainfo = cinfo->args + (i + oParm);
605 switch (ainfo->regtype) {
606 case RegTypeGeneral :
607 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
610 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
613 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
615 case RegTypeStructByVal :
616 if (ainfo->reg != STK_BASE)
617 curParm = &(rParm->gr[ainfo->reg-2]);
619 curParm = sp+ainfo->offset;
621 switch (ainfo->vtsize) {
627 decodeParm(sig->params[i],
632 decodeParm(sig->params[i],
633 *((char **) curParm),
645 /*========================= End of Function ========================*/
647 /*------------------------------------------------------------------*/
649 /* Name - leave_method */
653 /*------------------------------------------------------------------*/
656 leave_method (MonoMethod *method, ...)
662 va_start(ap, method);
664 fname = mono_method_full_name (method, TRUE);
666 printf ("LEAVE: %s", fname);
669 type = method->signature->ret;
672 switch (type->type) {
675 case MONO_TYPE_BOOLEAN: {
676 int val = va_arg (ap, int);
678 printf ("[TRUE:%d]", val);
684 case MONO_TYPE_CHAR: {
685 int val = va_arg (ap, int);
686 printf ("[CHAR:%d]", val);
690 int val = va_arg (ap, int);
691 printf ("[INT1:%d]", val);
695 int val = va_arg (ap, int);
696 printf ("[UINT1:%d]", val);
700 int val = va_arg (ap, int);
701 printf ("[INT2:%d]", val);
705 int val = va_arg (ap, int);
706 printf ("[UINT2:%d]", val);
710 int val = va_arg (ap, int);
711 printf ("[INT4:%d]", val);
715 int val = va_arg (ap, int);
716 printf ("[UINT4:%d]", val);
720 int *val = va_arg (ap, int*);
721 printf ("[INT:%p]", val);
726 int *val = va_arg (ap, int*);
727 printf ("[UINT:%p]", val);
731 case MONO_TYPE_STRING: {
732 MonoString *s = va_arg (ap, MonoString *);
735 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
736 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
738 printf ("[STRING:null], ");
741 case MONO_TYPE_CLASS:
742 case MONO_TYPE_OBJECT: {
743 MonoObject *o = va_arg (ap, MonoObject *);
746 if (o->vtable->klass == mono_defaults.boolean_class) {
747 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
748 } else if (o->vtable->klass == mono_defaults.int32_class) {
749 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
750 } else if (o->vtable->klass == mono_defaults.int64_class) {
751 printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
753 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
755 printf ("[OBJECT:%p]", o);
760 case MONO_TYPE_FNPTR:
761 case MONO_TYPE_ARRAY:
762 case MONO_TYPE_SZARRAY: {
763 gpointer p = va_arg (ap, gpointer);
764 printf ("[result=%p]", p);
768 gint64 l = va_arg (ap, gint64);
769 printf ("[LONG:%lld]", l);
773 double f = va_arg (ap, double);
774 printf ("[FP:%g]\n", f);
777 case MONO_TYPE_VALUETYPE:
778 if (type->data.klass->enumtype) {
779 type = type->data.klass->enum_basetype;
782 guint8 *p = va_arg (ap, gpointer);
784 size = mono_type_size (type, &align);
786 for (j = 0; p && j < size; j++)
787 printf ("%02x,", p [j]);
792 printf ("(unknown return type %x)", method->signature->ret->type);
795 printf (" ip: %p\n", __builtin_return_address (0));
798 /*========================= End of Function ========================*/
800 /*------------------------------------------------------------------*/
802 /* Name - mono_arch_cpu_init */
804 /* Function - Perform CPU specific initialization to execute */
807 /*------------------------------------------------------------------*/
810 mono_arch_cpu_init (void)
814 /*========================= End of Function ========================*/
816 /*------------------------------------------------------------------*/
818 /* Name - mono_arch_cpu_optimizazions */
820 /* Function - Returns the optimizations supported on this CPU */
822 /*------------------------------------------------------------------*/
825 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
829 /* no s390-specific optimizations yet */
830 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
834 /*========================= End of Function ========================*/
836 /*------------------------------------------------------------------*/
842 /*------------------------------------------------------------------*/
845 is_regsize_var (MonoType *t) {
854 case MONO_TYPE_OBJECT:
855 case MONO_TYPE_STRING:
856 case MONO_TYPE_CLASS:
857 case MONO_TYPE_SZARRAY:
858 case MONO_TYPE_ARRAY:
860 case MONO_TYPE_VALUETYPE:
861 if (t->data.klass->enumtype)
862 return is_regsize_var (t->data.klass->enum_basetype);
868 /*========================= End of Function ========================*/
870 /*------------------------------------------------------------------*/
872 /* Name - mono_arch_get_allocatable_int_vars */
876 /*------------------------------------------------------------------*/
879 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
884 for (i = 0; i < cfg->num_varinfo; i++) {
885 MonoInst *ins = cfg->varinfo [i];
886 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
889 if (vmv->range.first_use.abs_pos > vmv->range.last_use.abs_pos)
892 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) || (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
895 /* we can only allocate 32 bit values */
896 if (is_regsize_var (ins->inst_vtype)) {
897 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
898 g_assert (i == vmv->idx);
899 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
906 /*========================= End of Function ========================*/
908 /*------------------------------------------------------------------*/
910 /* Name - mono_arch_global_int_regs */
912 /* Function - Return a list of usable integer registers. */
914 /*------------------------------------------------------------------*/
917 mono_arch_get_global_int_regs (MonoCompile *cfg)
922 for (i = 3; i < top; ++i)
923 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
928 /*========================= End of Function ========================*/
930 /*------------------------------------------------------------------*/
932 /* Name - mono_arch_flush_icache */
934 /* Function - Flush the CPU icache. */
936 /*------------------------------------------------------------------*/
939 mono_arch_flush_icache (guint8 *code, gint size)
943 /*========================= End of Function ========================*/
945 /*------------------------------------------------------------------*/
947 /* Name - add_general */
949 /* Function - Determine code and stack size incremements for a */
952 /*------------------------------------------------------------------*/
955 add_general (guint *gr, size_data *sz, ArgInfo *ainfo, gboolean simple)
958 if (*gr > S390_LAST_ARG_REG) {
959 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
960 ainfo->offset = sz->stack_size;
961 ainfo->reg = STK_BASE;
962 ainfo->regtype = RegTypeBase;
963 sz->stack_size += sizeof(int);
970 if (*gr > S390_LAST_ARG_REG - 1) {
971 sz->stack_size = S390_ALIGN(sz->stack_size, S390_STACK_ALIGNMENT);
972 ainfo->offset = sz->stack_size;
973 ainfo->reg = STK_BASE;
974 ainfo->regtype = RegTypeBase;
975 sz->stack_size += sizeof(long long);
986 /*========================= End of Function ========================*/
988 /*------------------------------------------------------------------*/
990 /* Name - calculate_sizes */
992 /* Function - Determine the amount of space required for code */
993 /* and stack. In addition determine starting points */
994 /* for stack-based parameters, and area for struct- */
995 /* ures being returned on the stack. */
997 /*------------------------------------------------------------------*/
1000 calculate_sizes (MonoMethodSignature *sig, size_data *sz,
1001 gboolean string_ctor)
1003 guint i, fr, gr, size, nWords;
1004 int nParm = sig->hasthis + sig->param_count;
1005 guint32 simpletype, align;
1006 CallInfo *cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1010 cinfo->struct_ret = 0;
1012 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1017 /*----------------------------------------------------------*/
1018 /* We determine the size of the return code/stack in case we*/
1019 /* need to reserve a register to be used to address a stack */
1020 /* area that the callee will use. */
1021 /*----------------------------------------------------------*/
1023 // if (sig->ret->byref || string_ctor) {
1024 // sz->code_size += 8;
1025 // add_general (&gr, sz, cinfo->args+nParm, TRUE);
1026 // cinfo->args[nParm].size = sizeof(gpointer);
1030 simpletype = sig->ret->type;
1032 switch (simpletype) {
1033 case MONO_TYPE_BOOLEAN:
1038 case MONO_TYPE_CHAR:
1043 case MONO_TYPE_CLASS:
1044 case MONO_TYPE_OBJECT:
1045 case MONO_TYPE_SZARRAY:
1046 case MONO_TYPE_ARRAY:
1048 case MONO_TYPE_STRING:
1049 cinfo->ret.reg = s390_r2;
1054 cinfo->ret.reg = s390_f0;
1059 cinfo->ret.reg = s390_r2;
1062 case MONO_TYPE_VALUETYPE:
1063 if (sig->ret->data.klass->enumtype) {
1064 simpletype = sig->ret->data.klass->enum_basetype->type;
1068 size = mono_class_native_size (sig->ret->data.klass, &align);
1070 size = mono_class_value_size (sig->ret->data.klass, &align);
1071 cinfo->ret.reg = s390_r2;
1072 cinfo->struct_ret = 1;
1073 cinfo->ret.size = size;
1074 cinfo->ret.vtsize = size;
1075 cinfo->ret.offset = sz->stack_size;
1076 sz->stack_size += S390_ALIGN(size, align);
1079 case MONO_TYPE_VOID:
1082 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1087 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1088 cinfo->args[nParm].size = sizeof(gpointer);
1092 /*----------------------------------------------------------*/
1093 /* We determine the size of the parameter code and stack */
1094 /* requirements by checking the types and sizes of the */
1096 /*----------------------------------------------------------*/
1098 for (i = 0; i < sig->param_count; ++i) {
1099 if (sig->params [i]->byref) {
1100 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1101 cinfo->args[nParm].size = sizeof(gpointer);
1105 simpletype = sig->params [i]->type;
1107 switch (simpletype) {
1108 case MONO_TYPE_BOOLEAN:
1111 cinfo->args[nParm].size = sizeof(char);
1112 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1117 case MONO_TYPE_CHAR:
1118 cinfo->args[nParm].size = sizeof(short);
1119 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1124 cinfo->args[nParm].size = sizeof(int);
1125 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1131 case MONO_TYPE_CLASS:
1132 case MONO_TYPE_OBJECT:
1133 case MONO_TYPE_STRING:
1134 case MONO_TYPE_SZARRAY:
1135 case MONO_TYPE_ARRAY:
1136 cinfo->args[nParm].size = sizeof(gpointer);
1137 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1140 case MONO_TYPE_VALUETYPE:
1141 if (sig->params [i]->data.klass->enumtype) {
1142 simpletype = sig->params [i]->data.klass->enum_basetype->type;
1143 goto enum_calc_size;
1146 size = mono_class_native_size (sig->params [i]->data.klass, &align);
1148 size = mono_class_value_size (sig->params [i]->data.klass, &align);
1149 nWords = (size + sizeof(gpointer) - 1) /
1152 cinfo->args[nParm].vtsize = 0;
1153 cinfo->args[nParm].size = 0;
1154 cinfo->args[nParm].offparm = sz->local_size;
1157 /*----------------------------------*/
1158 /* On S/390, structures of size 1, */
1159 /* 2, 4, and 8 bytes are passed in */
1160 /* (a) register(s). */
1161 /*----------------------------------*/
1166 add_general(&gr, sz, cinfo->args+nParm, TRUE);
1167 cinfo->args[nParm].size = sizeof(int);
1168 cinfo->args[nParm].regtype = RegTypeStructByVal;
1170 sz->local_size += sizeof(long);
1173 add_general(&gr, sz, cinfo->args+nParm, FALSE);
1174 cinfo->args[nParm].size = sizeof(long long);
1175 cinfo->args[nParm].regtype = RegTypeStructByVal;
1177 sz->local_size += sizeof(long);
1180 add_general(&gr, sz, cinfo->args+nParm, TRUE);
1181 cinfo->args[nParm].size = sizeof(int);
1182 cinfo->args[nParm].regtype = RegTypeStructByVal;
1183 cinfo->args[nParm].vtsize = size;
1184 sz->code_size += 40;
1185 sz->local_size += size;
1186 if (cinfo->args[nParm].reg == STK_BASE)
1187 sz->local_size += sizeof(gpointer);
1193 cinfo->args[nParm].size = sizeof(long long);
1194 add_general (&gr, sz, cinfo->args+nParm, FALSE);
1198 cinfo->args[nParm].size = sizeof(float);
1199 if (fr <= S390_LAST_FPARG_REG) {
1200 cinfo->args[nParm].regtype = RegTypeFP;
1201 cinfo->args[nParm].reg = fr;
1206 cinfo->args[nParm].offset = sz->stack_size;
1207 cinfo->args[nParm].reg = STK_BASE;
1208 cinfo->args[nParm].regtype = RegTypeBase;
1210 sz->stack_size += sizeof(float);
1215 cinfo->args[nParm].size = sizeof(double);
1216 if (fr <= S390_LAST_FPARG_REG) {
1217 cinfo->args[nParm].regtype = RegTypeFP;
1218 cinfo->args[nParm].reg = fr;
1222 sz->stack_size = S390_ALIGN(sz->stack_size,
1223 S390_STACK_ALIGNMENT);
1224 cinfo->args[nParm].offset = sz->stack_size;
1225 cinfo->args[nParm].reg = STK_BASE;
1226 cinfo->args[nParm].regtype = RegTypeBase;
1228 sz->stack_size += sizeof(double);
1233 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1238 /* align stack size */
1239 cinfo->stack_usage = S390_ALIGN(sz->stack_size+sz->local_size,
1240 S390_STACK_ALIGNMENT);
1244 /*========================= End of Function ========================*/
1246 /*------------------------------------------------------------------*/
1248 /* Name - mono_arch_allocate_vars */
1250 /* Function - Set var information according to the calling */
1251 /* convention for S/390. The local var stuff should */
1252 /* most likely be split in another method. */
1254 /* Parameter - @m - Compile unit. */
1256 /*------------------------------------------------------------------*/
1259 mono_arch_allocate_vars (MonoCompile *m)
1261 MonoMethodSignature *sig;
1262 MonoMethodHeader *header;
1266 int iParm, iVar, offset, size, align, curinst;
1267 int frame_reg = STK_BASE;
1270 header = ((MonoMethodNormal *)m->method)->header;
1273 * We use the frame register also for any method that has
1274 * filter clauses. This way, when the handlers are called,
1275 * the code will reference local variables using the frame reg instead of
1276 * the stack pointer: if we had to restore the stack pointer, we'd
1277 * corrupt the method frames that are already on the stack (since
1278 * filters get called before stack unwinding happens) when the filter
1279 * code would call any method.
1281 // if ((m->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1282 if (m->flags & MONO_CFG_HAS_ALLOCA)
1283 frame_reg = s390_r11;
1285 m->frame_reg = frame_reg;
1287 if (frame_reg != STK_BASE)
1288 m->used_int_regs |= 1 << frame_reg;
1290 sig = m->method->signature;
1292 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1294 if (cinfo->struct_ret) {
1295 m->ret->opcode = OP_REGVAR;
1296 m->ret->inst_c0 = s390_r2;
1298 /* FIXME: handle long and FP values */
1299 switch (sig->ret->type) {
1300 case MONO_TYPE_VOID:
1303 m->ret->opcode = OP_REGVAR;
1304 m->ret->dreg = s390_r2;
1309 /*--------------------------------------------------------------*/
1310 /* local vars are at a positive offset from the stack pointer */
1312 /* also note that if the function uses alloca, we use s390_r11 */
1313 /* to point at the local variables. */
1314 /* add parameter area size for called functions */
1315 /*--------------------------------------------------------------*/
1316 offset = (m->param_area + S390_MINIMAL_STACK_SIZE);
1318 if (cinfo->struct_ret) {
1320 offset = S390_ALIGN(offset, sizeof(gpointer));
1321 inst->inst_offset = offset;
1322 inst->opcode = OP_REGOFFSET;
1323 inst->inst_basereg = frame_reg;
1324 offset += sizeof(gpointer);
1328 inst = m->varinfo [0];
1329 if (inst->opcode != OP_REGVAR) {
1330 inst->opcode = OP_REGOFFSET;
1331 inst->inst_basereg = frame_reg;
1332 offset = S390_ALIGN(offset, sizeof(gpointer));
1333 inst->inst_offset = offset;
1334 offset += sizeof (gpointer);
1341 eArg = sig->param_count + sArg;
1343 for (iParm = sArg; iParm < eArg; ++iParm) {
1344 inst = m->varinfo [curinst];
1345 if (inst->opcode != OP_REGVAR) {
1346 if (cinfo->args[iParm].regtype == RegTypeStructByVal) {
1347 if (cinfo->args[iParm].vtsize != 0) {
1348 inst->opcode = OP_S390_LOADARG;
1349 inst->inst_basereg = frame_reg;
1350 size = sizeof(long);
1351 offset = S390_ALIGN(offset, size);
1352 inst->inst_offset = offset;
1354 inst->opcode = OP_S390_ARGPTR;
1355 inst->inst_basereg = frame_reg;
1356 size = cinfo->args[iParm].size;
1357 offset = S390_ALIGN(offset, size);
1358 inst->inst_offset = offset;
1361 if (cinfo->args[iParm].reg != STK_BASE) {
1362 inst->opcode = OP_REGOFFSET;
1363 inst->inst_basereg = frame_reg;
1364 size = (cinfo->args[iParm].size < 8
1366 : sizeof(long long));
1367 offset = S390_ALIGN(offset, size);
1368 inst->inst_offset = offset;
1370 inst->opcode = OP_S390_STKARG;
1371 inst->inst_basereg = frame_reg;
1372 size = (cinfo->args[iParm].size < 4
1373 ? 4 - cinfo->args[iParm].size
1375 inst->inst_offset = cinfo->args[iParm].offset +
1377 // inst->unused = stackOffset;
1379 size = sizeof(long);
1387 curinst = m->locals_start;
1388 for (iVar = curinst; iVar < m->num_varinfo; ++iVar) {
1389 inst = m->varinfo [iVar];
1390 if (inst->opcode == OP_REGVAR)
1393 /* inst->unused indicates native sized value types, this is used by the
1394 * pinvoke wrappers when they call functions returning structure */
1395 if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1396 size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
1398 size = mono_type_size (inst->inst_vtype, &align);
1400 offset = S390_ALIGN(offset, align);
1401 inst->inst_offset = offset;
1402 inst->opcode = OP_REGOFFSET;
1403 inst->inst_basereg = frame_reg;
1405 //DEBUG (g_print("allocating local %d to %d\n", iVar, inst->inst_offset));
1408 // if (sig->hasthis)
1409 // curinst = sArg = 1;
1411 // curinst = sArg = 0;
1414 /*------------------------------------------------------*/
1415 /* Allow space for the trace method stack area if needed*/
1416 /*------------------------------------------------------*/
1417 if (mono_jit_trace_calls != NULL && mono_trace_eval (m))
1418 offset += S390_TRACE_STACK_SIZE;
1420 /*------------------------------------------------------*/
1421 /* Reserve space to save LMF and caller saved registers */
1422 /*------------------------------------------------------*/
1423 if (m->method->save_lmf)
1424 offset += sizeof (MonoLMF);
1426 /*------------------------------------------------------*/
1427 /* align the offset */
1428 /*------------------------------------------------------*/
1429 m->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1433 /*========================= End of Function ========================*/
1435 /*------------------------------------------------------------------*/
1437 /* Name - mono_arch_call_opcode */
1439 /* Function - Take the arguments and generate the arch-specific */
1440 /* instructions to properly call the function. This */
1441 /* includes pushing, moving argments to the correct */
1444 /* Note - FIXME: We need an alignment solution for */
1445 /* enter_method and mono_arch_call_opcode, currently */
1446 /* alignment in mono_arch_call_opcode is computed */
1447 /* without arch_get_argument_info. */
1449 /*------------------------------------------------------------------*/
1452 mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
1454 MonoMethodSignature *sig;
1455 int i, n, lParamArea;
1460 sig = call->signature;
1461 n = sig->param_count + sig->hasthis;
1462 DEBUG (g_print ("Call requires: %d parameters\n",n));
1464 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1466 call->stack_usage = cinfo->stack_usage;
1467 lParamArea = cinfo->stack_usage - S390_MINIMAL_STACK_SIZE;
1468 cfg->param_area = MAX (cfg->param_area, lParamArea);
1469 cfg->flags |= MONO_CFG_HAS_CALLS;
1470 /*----------------------------------------------------------*/
1471 /* should set more info in call, such as the stack space */
1472 /* used by the args that needs to be added back to esp */
1473 /*----------------------------------------------------------*/
1475 if (cinfo->struct_ret)
1476 call->used_iregs |= 1 << cinfo->struct_ret;
1478 for (i = 0; i < n; ++i) {
1479 ainfo = cinfo->args + i;
1480 DEBUG (g_print ("Parameter %d - Register: %d Type: %d\n",
1481 i+1,ainfo->reg,ainfo->regtype));
1482 if (is_virtual && i == 0) {
1483 /* the argument will be attached to the call instrucion */
1484 in = call->args [i];
1485 call->used_iregs |= 1 << ainfo->reg;
1487 MONO_INST_NEW (cfg, arg, OP_OUTARG);
1488 in = call->args [i];
1489 arg->cil_code = in->cil_code;
1490 arg->inst_left = in;
1491 arg->type = in->type;
1492 /* prepend, we'll need to reverse them later */
1493 arg->next = call->out_args;
1494 call->out_args = arg;
1495 if (ainfo->regtype == RegTypeGeneral) {
1496 arg->unused = ainfo->reg;
1497 call->used_iregs |= 1 << ainfo->reg;
1498 if (arg->type == STACK_I8)
1499 call->used_iregs |= 1 << (ainfo->reg + 1);
1500 } else if (ainfo->regtype == RegTypeStructByAddr) {
1501 arg->unused = ainfo->reg;
1502 call->used_iregs |= 1 << ainfo->reg;
1503 } else if (ainfo->regtype == RegTypeStructByVal) {
1504 if (ainfo->reg != STK_BASE) {
1505 switch (ainfo->size) {
1510 call->used_iregs |= 1 << ainfo->reg;
1513 call->used_iregs |= 1 << ainfo->reg;
1514 call->used_iregs |= 1 << (ainfo->reg+1);
1517 call->used_iregs |= 1 << ainfo->reg;
1520 arg->sreg1 = ainfo->reg;
1521 arg->opcode = OP_OUTARG_VT;
1522 if (ainfo->vtsize != 0)
1523 arg->unused = -ainfo->vtsize;
1525 arg->unused = ainfo->size;
1526 arg->inst_imm = ainfo->offset;
1527 arg->sreg2 = ainfo->offparm + S390_MINIMAL_STACK_SIZE;
1528 } else if (ainfo->regtype == RegTypeBase) {
1529 arg->opcode = OP_OUTARG;
1530 arg->unused = ainfo->reg | (ainfo->size << 8);
1531 arg->inst_imm = ainfo->offset;
1532 call->used_fregs |= 1 << ainfo->reg;
1533 } else if (ainfo->regtype == RegTypeFP) {
1534 arg->opcode = OP_OUTARG_R8;
1535 arg->unused = ainfo->reg;
1536 call->used_fregs |= 1 << ainfo->reg;
1537 if (ainfo->size == 4) {
1538 /* we reduce the precision */
1540 MONO_INST_NEW (cfg, conv, OP_FCONV_TO_R4);
1541 conv->inst_left = arg->inst_left;
1542 arg->inst_left = conv;
1545 g_assert_not_reached ();
1550 * Reverse the call->out_args list.
1553 MonoInst *prev = NULL, *list = call->out_args, *next;
1560 call->out_args = prev;
1567 /*========================= End of Function ========================*/
1569 /*------------------------------------------------------------------*/
1571 /* Name - mono_arch_instrument_mem_needs */
1573 /* Function - Allow tracing to work with this interface (with */
1574 /* an optional argument). */
1576 /*------------------------------------------------------------------*/
1579 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
1581 /* no stack room needed now (may be needed for FASTCALL-trace support) */
1583 /* split prolog-epilog requirements? */
1584 *code = 50; /* max bytes needed: check this number */
1587 /*========================= End of Function ========================*/
1589 /*------------------------------------------------------------------*/
1591 /* Name - mono_arch_instrument_prolog */
1593 /* Function - Create an "instrumented" prolog. */
1595 /*------------------------------------------------------------------*/
1598 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
1599 gboolean enable_arguments)
1605 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
1606 if (cfg->method->save_lmf)
1607 parmOffset -= sizeof(MonoLMF);
1608 fpOffset = parmOffset + (5*sizeof(gint32));
1610 s390_stm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1611 s390_std (code, s390_f0, 0, STK_BASE, fpOffset);
1612 s390_std (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1613 s390_std (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1614 s390_basr (code, s390_r13, 0);
1616 s390_word (code, cfg->method);
1617 s390_word (code, func);
1618 s390_l (code, s390_r2, 0, s390_r13, 4);
1619 s390_la (code, s390_r3, 0, STK_BASE, parmOffset);
1620 s390_lr (code, s390_r4, STK_BASE);
1621 s390_ahi (code, s390_r4, cfg->stack_usage);
1622 s390_l (code, s390_r1, 0, s390_r13, 8);
1623 s390_basr (code, s390_r14, s390_r1);
1624 s390_ld (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1625 s390_ld (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1626 s390_ld (code, s390_f0, 0, STK_BASE, fpOffset);
1627 s390_lm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1632 /*========================= End of Function ========================*/
1634 /*------------------------------------------------------------------*/
1636 /* Name - mono_arch_instrument_epilog */
1638 /* Function - Create an epilog that will handle the returned */
1639 /* values used in instrumentation. */
1641 /*------------------------------------------------------------------*/
1644 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
1647 int save_mode = SAVE_NONE,
1649 MonoMethod *method = cfg->method;
1650 int rtype = method->signature->ret->type;
1652 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
1653 if (method->save_lmf)
1654 saveOffset -= sizeof(MonoLMF);
1658 case MONO_TYPE_VOID:
1659 /* special case string .ctor icall */
1660 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
1661 save_mode = SAVE_ONE;
1663 save_mode = SAVE_NONE;
1667 save_mode = SAVE_TWO;
1671 save_mode = SAVE_FP;
1673 case MONO_TYPE_VALUETYPE:
1674 if (method->signature->ret->data.klass->enumtype) {
1675 rtype = method->signature->ret->data.klass->enum_basetype->type;
1678 save_mode = SAVE_STRUCT;
1681 save_mode = SAVE_ONE;
1685 switch (save_mode) {
1687 s390_stm (code, s390_r2, s390_r3, cfg->frame_reg, saveOffset);
1688 if (enable_arguments) {
1689 s390_lr (code, s390_r4, s390_r3);
1690 s390_lr (code, s390_r3, s390_r2);
1694 s390_st (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1695 if (enable_arguments) {
1696 s390_lr (code, s390_r3, s390_r2);
1700 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
1701 if (enable_arguments) {
1702 /* FIXME: what reg? */
1703 s390_ldr (code, s390_f2, s390_f0);
1704 s390_lm (code, s390_r3, s390_r4, cfg->frame_reg, saveOffset);
1708 s390_st (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1709 if (enable_arguments) {
1710 s390_l (code, s390_r3, 0, cfg->frame_reg,
1711 S390_MINIMAL_STACK_SIZE+cfg->param_area);
1719 s390_basr (code, s390_r13, 0);
1721 s390_word (code, cfg->method);
1722 s390_word (code, func);
1723 s390_l (code, s390_r2, 0, s390_r13, 4);
1724 s390_l (code, s390_r1, 0, s390_r13, 8);
1725 s390_basr (code, s390_r14, s390_r1);
1727 switch (save_mode) {
1729 s390_lm (code, s390_r2, s390_r3, cfg->frame_reg, saveOffset);
1732 s390_l (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1735 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
1738 s390_l (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1748 /*========================= End of Function ========================*/
1750 /*------------------------------------------------------------------*/
1752 /* Name - peephole_pass */
1754 /* Function - Form a peephole pass at the code looking for */
1755 /* simple optimizations. */
1757 /*------------------------------------------------------------------*/
1760 peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
1762 MonoInst *ins, *last_ins = NULL;
1767 switch (ins->opcode) {
1769 /* remove unnecessary multiplication with 1 */
1770 if (ins->inst_imm == 1) {
1771 if (ins->dreg != ins->sreg1) {
1772 ins->opcode = OP_MOVE;
1774 last_ins->next = ins->next;
1780 case OP_LOAD_MEMBASE:
1781 case OP_LOADI4_MEMBASE:
1783 * OP_STORE_MEMBASE_REG reg, offset(basereg)
1784 * OP_LOAD_MEMBASE offset(basereg), reg
1786 if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG
1787 || last_ins->opcode == OP_STORE_MEMBASE_REG) &&
1788 ins->inst_basereg == last_ins->inst_destbasereg &&
1789 ins->inst_offset == last_ins->inst_offset) {
1790 if (ins->dreg == last_ins->sreg1) {
1791 last_ins->next = ins->next;
1795 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1796 ins->opcode = OP_MOVE;
1797 ins->sreg1 = last_ins->sreg1;
1801 * Note: reg1 must be different from the basereg in the second load
1802 * OP_LOAD_MEMBASE offset(basereg), reg1
1803 * OP_LOAD_MEMBASE offset(basereg), reg2
1805 * OP_LOAD_MEMBASE offset(basereg), reg1
1806 * OP_MOVE reg1, reg2
1808 } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
1809 || last_ins->opcode == OP_LOAD_MEMBASE) &&
1810 ins->inst_basereg != last_ins->dreg &&
1811 ins->inst_basereg == last_ins->inst_basereg &&
1812 ins->inst_offset == last_ins->inst_offset) {
1814 if (ins->dreg == last_ins->dreg) {
1815 last_ins->next = ins->next;
1819 ins->opcode = OP_MOVE;
1820 ins->sreg1 = last_ins->dreg;
1823 //g_assert_not_reached ();
1827 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1828 * OP_LOAD_MEMBASE offset(basereg), reg
1830 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1831 * OP_ICONST reg, imm
1833 } else if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_IMM
1834 || last_ins->opcode == OP_STORE_MEMBASE_IMM) &&
1835 ins->inst_basereg == last_ins->inst_destbasereg &&
1836 ins->inst_offset == last_ins->inst_offset) {
1837 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1838 ins->opcode = OP_ICONST;
1839 ins->inst_c0 = last_ins->inst_imm;
1840 g_assert_not_reached (); // check this rule
1844 case OP_LOADU1_MEMBASE:
1845 case OP_LOADI1_MEMBASE:
1846 if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
1847 ins->inst_basereg == last_ins->inst_destbasereg &&
1848 ins->inst_offset == last_ins->inst_offset) {
1849 if (ins->dreg == last_ins->sreg1) {
1850 last_ins->next = ins->next;
1854 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1855 ins->opcode = OP_MOVE;
1856 ins->sreg1 = last_ins->sreg1;
1860 case OP_LOADU2_MEMBASE:
1861 case OP_LOADI2_MEMBASE:
1862 if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) &&
1863 ins->inst_basereg == last_ins->inst_destbasereg &&
1864 ins->inst_offset == last_ins->inst_offset) {
1865 if (ins->dreg == last_ins->sreg1) {
1866 last_ins->next = ins->next;
1870 ins->opcode = OP_MOVE;
1871 ins->sreg1 = last_ins->sreg1;
1881 if (ins->dreg == ins->sreg1) {
1883 last_ins->next = ins->next;
1888 * OP_MOVE sreg, dreg
1889 * OP_MOVE dreg, sreg
1891 if (last_ins && last_ins->opcode == OP_MOVE &&
1892 ins->sreg1 == last_ins->dreg &&
1893 ins->dreg == last_ins->sreg1) {
1894 last_ins->next = ins->next;
1903 bb->last_ins = last_ins;
1906 /*========================= End of Function ========================*/
1908 /*------------------------------------------------------------------*/
1910 /* Name - mono_spillvar_offset */
1912 /* Function - Returns the offset used by spillvar. It allocates */
1913 /* a new spill variable if necessary. */
1915 /*------------------------------------------------------------------*/
1918 mono_spillvar_offset (MonoCompile *cfg, int spillvar)
1920 MonoSpillInfo **si, *info;
1923 si = &cfg->spill_info;
1925 while (i <= spillvar) {
1928 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1930 info->offset = cfg->stack_offset;
1931 cfg->stack_offset += sizeof (gpointer);
1935 return (*si)->offset;
1941 g_assert_not_reached ();
1945 /*========================= End of Function ========================*/
1947 /*------------------------------------------------------------------*/
1949 /* Name - mono_spillvar_offset_float */
1953 /*------------------------------------------------------------------*/
1956 mono_spillvar_offset_float (MonoCompile *cfg, int spillvar)
1958 MonoSpillInfo **si, *info;
1961 si = &cfg->spill_info_float;
1963 while (i <= spillvar) {
1966 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1968 cfg->stack_offset = S390_ALIGN(cfg->stack_offset, S390_STACK_ALIGNMENT);
1969 info->offset = cfg->stack_offset;
1970 cfg->stack_offset += sizeof (double);
1974 return (*si)->offset;
1980 g_assert_not_reached ();
1984 /*========================= End of Function ========================*/
1986 /*------------------------------------------------------------------*/
1988 /* Name - print_ins */
1990 /* Function - Decode and print the instruction for tracing. */
1992 /*------------------------------------------------------------------*/
1995 print_ins (int i, MonoInst *ins)
1997 const char *spec = ins_spec [ins->opcode];
1998 g_print ("\t%-2d %s", i, mono_inst_name (ins->opcode));
1999 if (spec [MONO_INST_DEST]) {
2000 if (ins->dreg >= MONO_MAX_IREGS)
2001 g_print (" R%d <-", ins->dreg);
2003 g_print (" %s <-", mono_arch_regname (ins->dreg));
2005 if (spec [MONO_INST_SRC1]) {
2006 if (ins->sreg1 >= MONO_MAX_IREGS)
2007 g_print (" R%d", ins->sreg1);
2009 g_print (" %s", mono_arch_regname (ins->sreg1));
2011 if (spec [MONO_INST_SRC2]) {
2012 if (ins->sreg2 >= MONO_MAX_IREGS)
2013 g_print (" R%d", ins->sreg2);
2015 g_print (" %s", mono_arch_regname (ins->sreg2));
2017 if (spec [MONO_INST_CLOB])
2018 g_print (" clobbers: %c", spec [MONO_INST_CLOB]);
2022 /*========================= End of Function ========================*/
2024 /*------------------------------------------------------------------*/
2026 /* Name - print_regtrack. */
2030 /*------------------------------------------------------------------*/
2033 print_regtrack (RegTrack *t, int num)
2039 for (i = 0; i < num; ++i) {
2042 if (i >= MONO_MAX_IREGS) {
2043 g_snprintf (buf, sizeof(buf), "R%d", i);
2046 r = mono_arch_regname (i);
2047 g_print ("liveness: %s [%d - %d]\n", r, t [i].born_in, t[i].last_use);
2051 /*========================= End of Function ========================*/
2053 /*------------------------------------------------------------------*/
2055 /* Name - inst_list_prepend */
2057 /* Function - Prepend an instruction to the list. */
2059 /*------------------------------------------------------------------*/
2061 static inline InstList*
2062 inst_list_prepend (MonoMemPool *pool, InstList *list, MonoInst *data)
2064 InstList *item = mono_mempool_alloc (pool, sizeof (InstList));
2073 /*========================= End of Function ========================*/
2075 /*------------------------------------------------------------------*/
2077 /* Name - get_register_force_spilling */
2079 /* Function - Force the spilling of the variable in the */
2080 /* symbolic register 'reg'. */
2082 /*------------------------------------------------------------------*/
2085 get_register_force_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, int reg)
2090 sel = cfg->rs->iassign [reg];
2092 spill = ++cfg->spill_count;
2093 cfg->rs->iassign [i] = -spill - 1;
2094 mono_regstate_free_int (cfg->rs, sel);
2095 /*----------------------------------------------------------*/
2096 /* we need to create a spill var and insert a load to sel */
2097 /* after the current instruction */
2098 /*----------------------------------------------------------*/
2099 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2101 load->inst_basereg = cfg->frame_reg;
2102 load->inst_offset = mono_spillvar_offset (cfg, spill);
2104 while (ins->next != item->prev->data)
2107 load->next = ins->next;
2109 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n",
2110 spill, load->inst_offset, i, mono_arch_regname (sel)));
2111 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2112 g_assert (i == sel);
2117 /*========================= End of Function ========================*/
2119 /*------------------------------------------------------------------*/
2121 /* Name - get_register_spilling */
2125 /*------------------------------------------------------------------*/
2128 get_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2133 DEBUG (g_print ("start regmask to assign R%d: 0x%08x (R%d <- R%d R%d)\n", reg, regmask, ins->dreg, ins->sreg1, ins->sreg2));
2134 /* exclude the registers in the current instruction */
2135 if (reg != ins->sreg1 &&
2136 (reg_is_freeable (ins->sreg1) ||
2137 (ins->sreg1 >= MONO_MAX_IREGS &&
2138 cfg->rs->iassign [ins->sreg1] >= 0))) {
2139 if (ins->sreg1 >= MONO_MAX_IREGS)
2140 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg1]);
2142 regmask &= ~ (1 << ins->sreg1);
2143 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2145 if (reg != ins->sreg2 &&
2146 (reg_is_freeable (ins->sreg2) ||
2147 (ins->sreg2 >= MONO_MAX_IREGS &&
2148 cfg->rs->iassign [ins->sreg2] >= 0))) {
2149 if (ins->sreg2 >= MONO_MAX_IREGS)
2150 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg2]);
2152 regmask &= ~ (1 << ins->sreg2);
2153 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2155 if (reg != ins->dreg && reg_is_freeable (ins->dreg)) {
2156 regmask &= ~ (1 << ins->dreg);
2157 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2160 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2161 g_assert (regmask); /* need at least a register we can free */
2163 /* we should track prev_use and spill the register that's farther */
2164 for (i = 0; i < MONO_MAX_IREGS; ++i) {
2165 if (regmask & (1 << i)) {
2167 DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->iassign [sel]));
2171 i = cfg->rs->isymbolic [sel];
2172 spill = ++cfg->spill_count;
2173 cfg->rs->iassign [i] = -spill - 1;
2174 mono_regstate_free_int (cfg->rs, sel);
2175 /* we need to create a spill var and insert a load to sel after the current instruction */
2176 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2178 load->inst_basereg = cfg->frame_reg;
2179 load->inst_offset = mono_spillvar_offset (cfg, spill);
2181 while (ins->next != item->prev->data)
2184 load->next = ins->next;
2186 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2187 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2188 g_assert (i == sel);
2193 /*========================= End of Function ========================*/
2195 /*------------------------------------------------------------------*/
2197 /* Name - get_float_register_spilling */
2201 /*------------------------------------------------------------------*/
2204 get_float_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2209 DEBUG (g_print ("start regmask to assign R%d: 0x%08x (R%d <- R%d R%d)\n", reg, regmask, ins->dreg, ins->sreg1, ins->sreg2));
2210 /* exclude the registers in the current instruction */
2211 if (reg != ins->sreg1 &&
2212 (freg_is_freeable (ins->sreg1) ||
2213 (ins->sreg1 >= MONO_MAX_FREGS &&
2214 cfg->rs->fassign [ins->sreg1] >= 0))) {
2215 if (ins->sreg1 >= MONO_MAX_FREGS)
2216 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg1]);
2218 regmask &= ~ (1 << ins->sreg1);
2219 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2221 if (reg != ins->sreg2 &&
2222 (freg_is_freeable (ins->sreg2) ||
2223 (ins->sreg2 >= MONO_MAX_FREGS &&
2224 cfg->rs->fassign [ins->sreg2] >= 0))) {
2225 if (ins->sreg2 >= MONO_MAX_FREGS)
2226 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg2]);
2228 regmask &= ~ (1 << ins->sreg2);
2229 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2231 if (reg != ins->dreg && freg_is_freeable (ins->dreg)) {
2232 regmask &= ~ (1 << ins->dreg);
2233 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2236 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2237 g_assert (regmask); /* need at least a register we can free */
2239 /* we should track prev_use and spill the register that's farther */
2240 for (i = 0; i < MONO_MAX_FREGS; ++i) {
2241 if (regmask & (1 << i)) {
2243 DEBUG (g_print ("selected register %s has assignment %d\n",
2244 mono_arch_regname (sel), cfg->rs->fassign [sel]));
2248 i = cfg->rs->fsymbolic [sel];
2249 spill = ++cfg->spill_count;
2250 cfg->rs->fassign [i] = -spill - 1;
2251 mono_regstate_free_float(cfg->rs, sel);
2252 /* we need to create a spill var and insert a load to sel after the current instruction */
2253 MONO_INST_NEW (cfg, load, OP_LOADR8_MEMBASE);
2255 load->inst_basereg = cfg->frame_reg;
2256 load->inst_offset = mono_spillvar_offset_float (cfg, spill);
2258 while (ins->next != item->prev->data)
2261 load->next = ins->next;
2263 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2264 i = mono_regstate_alloc_float (cfg->rs, 1 << sel);
2265 g_assert (i == sel);
2270 /*========================= End of Function ========================*/
2272 /*------------------------------------------------------------------*/
2274 /* Name - create_copy_ins */
2276 /* Function - Create an instruction to copy from reg to reg. */
2278 /*------------------------------------------------------------------*/
2281 create_copy_ins (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2284 MONO_INST_NEW (cfg, copy, OP_MOVE);
2288 copy->next = ins->next;
2291 DEBUG (g_print ("\tforced copy from %s to %s\n",
2292 mono_arch_regname (src), mono_arch_regname (dest)));
2296 /*========================= End of Function ========================*/
2298 /*------------------------------------------------------------------*/
2300 /* Name - create_copy_ins_float */
2302 /* Function - Create an instruction to copy from float reg to */
2305 /*------------------------------------------------------------------*/
2308 create_copy_ins_float (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2311 MONO_INST_NEW (cfg, copy, OP_FMOVE);
2315 copy->next = ins->next;
2318 DEBUG (g_print ("\tforced copy from %s to %s\n",
2319 mono_arch_regname (src), mono_arch_regname (dest)));
2323 /*========================= End of Function ========================*/
2325 /*------------------------------------------------------------------*/
2327 /* Name - create_spilled_store */
2329 /* Function - Spill register to storage. */
2331 /*------------------------------------------------------------------*/
2334 create_spilled_store (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2337 MONO_INST_NEW (cfg, store, OP_STORE_MEMBASE_REG);
2339 store->inst_destbasereg = cfg->frame_reg;
2340 store->inst_offset = mono_spillvar_offset (cfg, spill);
2342 store->next = ins->next;
2345 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2346 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2350 /*========================= End of Function ========================*/
2352 /*------------------------------------------------------------------*/
2354 /* Name - create_spilled_store_float */
2356 /* Function - Spill floating point register to storage. */
2358 /*------------------------------------------------------------------*/
2361 create_spilled_store_float (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2364 MONO_INST_NEW (cfg, store, OP_STORER8_MEMBASE_REG);
2366 store->inst_destbasereg = cfg->frame_reg;
2367 store->inst_offset = mono_spillvar_offset_float (cfg, spill);
2369 store->next = ins->next;
2372 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2373 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2377 /*========================= End of Function ========================*/
2379 /*------------------------------------------------------------------*/
2381 /* Name - insert_before_ins */
2383 /* Function - Insert an instruction before another. */
2385 /*------------------------------------------------------------------*/
2388 insert_before_ins (MonoInst *ins, InstList *item, MonoInst* to_insert)
2391 g_assert (item->next);
2392 prev = item->next->data;
2394 while (prev->next != ins)
2396 to_insert->next = ins;
2397 prev->next = to_insert;
2399 * needed otherwise in the next instruction we can add an ins to the
2400 * end and that would get past this instruction.
2402 item->data = to_insert;
2405 /*========================= End of Function ========================*/
2407 /*------------------------------------------------------------------*/
2409 /* Name - alloc_int_reg */
2411 /* Function - Allocate a general register. */
2413 /*------------------------------------------------------------------*/
2416 alloc_int_reg (MonoCompile *cfg, InstList *curinst, MonoInst *ins, int sym_reg, guint32 allow_mask)
2418 int val = cfg->rs->iassign [sym_reg];
2419 DEBUG (g_print ("Allocating a general register for %d (%d) with mask %08x\n",val,sym_reg,allow_mask));
2423 /* the register gets spilled after this inst */
2426 val = mono_regstate_alloc_int (cfg->rs, allow_mask);
2428 val = get_register_spilling (cfg, curinst, ins, allow_mask, sym_reg);
2429 cfg->rs->iassign [sym_reg] = val;
2430 /* add option to store before the instruction for src registers */
2432 create_spilled_store (cfg, spill, val, sym_reg, ins);
2434 DEBUG (g_print ("Allocated %d for %d\n",val,sym_reg));
2435 cfg->rs->isymbolic [val] = sym_reg;
2439 /*========================= End of Function ========================*/
2441 /*------------------------------------------------------------------*/
2443 /* Name - mono_arch_local_regalloc. */
2445 /* Function - We first scan the list of instructions and we */
2446 /* save the liveness information of each register */
2447 /* (when the register is first used, when its value */
2448 /* is set etc.). We also reverse the list of instr- */
2449 /* uctions (in the InstList list) because assigning */
2450 /* registers backwards allows for more tricks to be */
2453 /*------------------------------------------------------------------*/
2456 mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
2459 MonoRegState *rs = cfg->rs;
2461 RegTrack *reginfo, *reginfof;
2462 RegTrack *reginfo1, *reginfo2, *reginfod;
2463 InstList *tmp, *reversed = NULL;
2465 guint32 src1_mask, src2_mask, dest_mask;
2466 guint32 cur_iregs, cur_fregs;
2470 rs->next_vireg = bb->max_ireg;
2471 rs->next_vfreg = bb->max_freg;
2472 mono_regstate_assign (rs);
2473 reginfo = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vireg);
2474 reginfof = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vfreg);
2475 rs->ifree_mask = S390_CALLER_REGS;
2476 rs->ffree_mask = S390_CALLER_FREGS;
2480 DEBUG (g_print ("LOCAL regalloc: basic block: %d\n", bb->block_num));
2481 /* forward pass on the instructions to collect register liveness info */
2483 spec = ins_spec [ins->opcode];
2484 DEBUG (print_ins (i, ins));
2485 if (spec [MONO_INST_CLOB] == 'c') {
2486 MonoCallInst * call = (MonoCallInst*)ins;
2489 if (spec [MONO_INST_SRC1]) {
2490 if (spec [MONO_INST_SRC1] == 'f')
2491 reginfo1 = reginfof;
2494 reginfo1 [ins->sreg1].prev_use = reginfo1 [ins->sreg1].last_use;
2495 reginfo1 [ins->sreg1].last_use = i;
2499 if (spec [MONO_INST_SRC2]) {
2500 if (spec [MONO_INST_SRC2] == 'f')
2501 reginfo2 = reginfof;
2504 reginfo2 [ins->sreg2].prev_use = reginfo2 [ins->sreg2].last_use;
2505 reginfo2 [ins->sreg2].last_use = i;
2509 if (spec [MONO_INST_DEST]) {
2510 if (spec [MONO_INST_DEST] == 'f')
2511 reginfod = reginfof;
2514 if (spec [MONO_INST_DEST] != 'b') /* it's not just a base register */
2515 reginfod [ins->dreg].killed_in = i;
2516 reginfod [ins->dreg].prev_use = reginfod [ins->dreg].last_use;
2517 reginfod [ins->dreg].last_use = i;
2518 if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
2519 reginfod [ins->dreg].born_in = i;
2520 if (spec [MONO_INST_DEST] == 'l') {
2521 /* result in eax:edx, the virtual register is allocated sequentially */
2522 reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
2523 reginfod [ins->dreg + 1].last_use = i;
2524 if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
2525 reginfod [ins->dreg + 1].born_in = i;
2530 reversed = inst_list_prepend (cfg->mempool, reversed, ins);
2535 cur_iregs = S390_CALLER_REGS;
2536 cur_fregs = S390_CALLER_FREGS;
2538 DEBUG (print_regtrack (reginfo, rs->next_vireg));
2539 DEBUG (print_regtrack (reginfof, rs->next_vfreg));
2542 int prev_dreg, prev_sreg1, prev_sreg2;
2545 spec = ins_spec [ins->opcode];
2546 DEBUG (g_print ("processing:"));
2547 DEBUG (print_ins (i, ins));
2548 /* make the register available for allocation: FIXME add fp reg */
2549 if (ins->opcode == OP_SETREG || ins->opcode == OP_SETREGIMM) {
2550 cur_iregs |= 1 << ins->dreg;
2551 DEBUG (g_print ("adding %d to cur_iregs\n", ins->dreg));
2552 } else if (ins->opcode == OP_SETFREG) {
2553 cur_fregs |= 1 << ins->dreg;
2554 DEBUG (g_print ("adding %d to cur_fregs\n", ins->dreg));
2555 } else if (spec [MONO_INST_CLOB] == 'c') {
2556 MonoCallInst *cinst = (MonoCallInst*)ins;
2557 DEBUG (g_print ("excluding regs 0x%x from cur_iregs (0x%x)\n",
2558 cinst->used_iregs, cur_iregs));
2559 DEBUG (g_print ("excluding fpregs 0x%x from cur_fregs (0x%x)\n",
2560 cinst->used_fregs, cur_fregs));
2561 cur_iregs &= ~cinst->used_iregs;
2562 cur_fregs &= ~cinst->used_fregs;
2563 DEBUG (g_print ("available cur_iregs: 0x%x\n", cur_iregs));
2564 DEBUG (g_print ("available cur_fregs: 0x%x\n", cur_fregs));
2565 /*------------------------------------------------------------*/
2566 /* registers used by the calling convention are excluded from */
2567 /* allocation: they will be selectively enabled when they are */
2568 /* assigned by the special SETREG opcodes. */
2569 /*------------------------------------------------------------*/
2571 dest_mask = src1_mask = src2_mask = cur_iregs;
2572 /*------------------------------------------------------*/
2573 /* update for use with FP regs... */
2574 /*------------------------------------------------------*/
2575 if (spec [MONO_INST_DEST] == 'f') {
2576 dest_mask = cur_fregs;
2577 if (ins->dreg >= MONO_MAX_FREGS) {
2578 val = rs->fassign [ins->dreg];
2579 prev_dreg = ins->dreg;
2583 /* the register gets spilled after this inst */
2586 val = mono_regstate_alloc_float (rs, dest_mask);
2588 val = get_float_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2589 rs->fassign [ins->dreg] = val;
2591 create_spilled_store_float (cfg, spill, val, prev_dreg, ins);
2593 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n",
2594 mono_arch_regname (val), ins->dreg));
2595 rs->fsymbolic [val] = prev_dreg;
2597 if (spec [MONO_INST_CLOB] == 'c' && ins->dreg != s390_f0) {
2598 /* this instruction only outputs to s390_f0, need to copy */
2599 create_copy_ins_float (cfg, ins->dreg, s390_f0, ins);
2604 if (freg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfof [prev_dreg].born_in >= i || !(cur_fregs & (1 << ins->dreg)))) {
2605 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2606 mono_regstate_free_float (rs, ins->dreg);
2608 } else if (ins->dreg >= MONO_MAX_IREGS) {
2609 val = rs->iassign [ins->dreg];
2610 prev_dreg = ins->dreg;
2614 /* the register gets spilled after this inst */
2617 val = mono_regstate_alloc_int (rs, dest_mask);
2619 val = get_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2620 rs->iassign [ins->dreg] = val;
2622 create_spilled_store (cfg, spill, val, prev_dreg, ins);
2624 DEBUG (g_print ("\tassigned dreg %s to dest R%d (prev: R%d)\n",
2625 mono_arch_regname (val), ins->dreg, prev_dreg));
2626 rs->isymbolic [val] = prev_dreg;
2628 if (spec [MONO_INST_DEST] == 'l') {
2629 int hreg = prev_dreg + 1;
2630 val = rs->iassign [hreg];
2634 /* the register gets spilled after this inst */
2637 val = mono_regstate_alloc_int (rs, dest_mask);
2639 val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
2640 rs->iassign [hreg] = val;
2642 create_spilled_store (cfg, spill, val, hreg, ins);
2644 DEBUG (g_print ("\tassigned hreg %s to dest R%d\n", mono_arch_regname (val), hreg));
2645 rs->isymbolic [val] = hreg;
2646 /* FIXME:? ins->dreg = val; */
2647 if (ins->dreg == s390_r3) {
2649 create_copy_ins (cfg, val, s390_r2, ins);
2650 } else if (ins->dreg == s390_r2) {
2651 if (val == s390_r3) {
2653 create_copy_ins (cfg, s390_r3, s390_r0, ins);
2654 create_copy_ins (cfg, s390_r2, s390_r3, ins);
2655 create_copy_ins (cfg, s390_r0, s390_r2, ins);
2657 /* two forced copies */
2658 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2659 create_copy_ins (cfg, val, s390_r2, ins);
2662 if (val == s390_r2) {
2663 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2665 /* two forced copies */
2666 create_copy_ins (cfg, val, s390_r2, ins);
2667 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2670 if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
2671 DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
2672 mono_regstate_free_int (rs, val);
2674 } else if (spec [MONO_INST_DEST] == 'a' && ins->dreg != s390_r2 && spec [MONO_INST_CLOB] != 'd') {
2675 /* this instruction only outputs to s390_r2, need to copy */
2676 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2681 if (spec [MONO_INST_DEST] == 'f' &&
2682 freg_is_freeable (ins->dreg) &&
2683 prev_dreg >= 0 && (reginfof [prev_dreg].born_in >= i)) {
2684 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2685 mono_regstate_free_float (rs, ins->dreg);
2686 } else if (spec [MONO_INST_DEST] != 'f' &&
2687 reg_is_freeable (ins->dreg) &&
2688 prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i)) {
2689 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2690 mono_regstate_free_int (rs, ins->dreg);
2692 if (spec [MONO_INST_SRC1] == 'f') {
2693 src1_mask = cur_fregs;
2694 if (ins->sreg1 >= MONO_MAX_FREGS) {
2695 val = rs->fassign [ins->sreg1];
2696 prev_sreg1 = ins->sreg1;
2700 /* the register gets spilled after this inst */
2703 //g_assert (val == -1); /* source cannot be spilled */
2704 val = mono_regstate_alloc_float (rs, src1_mask);
2706 val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
2707 rs->fassign [ins->sreg1] = val;
2708 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2710 MonoInst *store = create_spilled_store_float (cfg, spill, val, prev_sreg1, NULL);
2711 insert_before_ins (ins, tmp, store);
2714 rs->fsymbolic [val] = prev_sreg1;
2719 } else if (ins->sreg1 >= MONO_MAX_IREGS) {
2720 val = rs->iassign [ins->sreg1];
2721 prev_sreg1 = ins->sreg1;
2725 /* the register gets spilled after this inst */
2728 val = mono_regstate_alloc_int (rs, src1_mask);
2730 val = get_register_spilling (cfg, tmp, ins,
2733 rs->iassign [ins->sreg1] = val;
2734 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n",
2735 mono_arch_regname (val), ins->sreg1));
2738 store = create_spilled_store (cfg, spill, val,
2740 insert_before_ins (ins, tmp, store);
2743 rs->isymbolic [val] = prev_sreg1;
2748 /*----------------------------------------------*/
2749 /* handle clobbering of sreg1 */
2750 /*----------------------------------------------*/
2751 if ((spec [MONO_INST_CLOB] == '1' ||
2752 spec [MONO_INST_CLOB] == 's') &&
2753 ins->dreg != ins->sreg1) {
2755 copy = create_copy_ins (cfg, ins->dreg, ins->sreg1, NULL);
2756 DEBUG (g_print ("\tneed to copy sreg1 %s to dreg %s\n",
2757 mono_arch_regname (ins->sreg1),
2758 mono_arch_regname (ins->dreg)));
2759 if (ins->sreg2 == -1 || spec [MONO_INST_CLOB] == 's') {
2760 /* note: the copy is inserted before the current instruction! */
2761 insert_before_ins (ins, tmp, copy);
2762 /* we set sreg1 to dest as well */
2763 prev_sreg1 = ins->sreg1 = ins->dreg;
2765 /* inserted after the operation */
2766 copy->next = ins->next;
2771 if (spec [MONO_INST_SRC2] == 'f') {
2772 src2_mask = cur_fregs;
2773 if (ins->sreg2 >= MONO_MAX_FREGS) {
2774 val = rs->fassign [ins->sreg2];
2775 prev_sreg2 = ins->sreg2;
2779 /* the register gets spilled after this inst */
2782 val = mono_regstate_alloc_float (rs, src2_mask);
2784 val = get_float_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2785 rs->fassign [ins->sreg2] = val;
2786 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2788 create_spilled_store_float (cfg, spill, val, prev_sreg2, ins);
2790 rs->fsymbolic [val] = prev_sreg2;
2795 } else if (ins->sreg2 >= MONO_MAX_IREGS) {
2796 val = rs->iassign [ins->sreg2];
2797 prev_sreg2 = ins->sreg2;
2801 /* the register gets spilled after this inst */
2804 val = mono_regstate_alloc_int (rs, src2_mask);
2806 val = get_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2807 rs->iassign [ins->sreg2] = val;
2808 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2810 create_spilled_store (cfg, spill, val, prev_sreg2, ins);
2812 rs->isymbolic [val] = prev_sreg2;
2818 if (spec [MONO_INST_CLOB] == 'c') {
2820 guint32 clob_mask = S390_CALLER_REGS;
2821 for (j = 0; j < MONO_MAX_IREGS; ++j) {
2823 if ((clob_mask & s) && !(rs->ifree_mask & s) && j != ins->sreg1) {
2824 //g_warning ("register %s busy at call site\n", mono_arch_regname (j));
2828 /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
2829 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
2830 mono_regstate_free_int (rs, ins->sreg1);
2832 if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
2833 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
2834 mono_regstate_free_int (rs, ins->sreg2);
2837 //DEBUG (print_ins (i, ins));
2842 /*========================= End of Function ========================*/
2844 /*------------------------------------------------------------------*/
2846 /* Name - emit_float_to_int */
2848 /* Function - Create instructions which will convert a floating */
2849 /* point value to integer. */
2851 /*------------------------------------------------------------------*/
2854 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2856 /* sreg is a float, dreg is an integer reg. */
2858 s390_cfdbr (code, dreg, 5, sreg);
2860 s390_basr (code, s390_r13, 0);
2862 s390_double (code, 0x41e0000000000000);
2863 s390_double (code, 0x41f0000000000000);
2864 s390_ldr (code, s390_f0, sreg);
2865 s390_cdb (code, s390_f0, 0, s390_r13, 0);
2867 s390_sdb (code, s390_f0, 0, s390_r13, 8);
2868 s390_cfdbr (code, dreg, 7, s390_f0);
2870 s390_cfdbr (code, dreg, 5, sreg);
2875 /*========================= End of Function ========================*/
2877 /*------------------------------------------------------------------*/
2879 /* Name - mono_emit_stack_alloc */
2883 /*------------------------------------------------------------------*/
2885 static unsigned char*
2886 mono_emit_stack_alloc (guchar *code, MonoInst* tree)
2891 /*========================= End of Function ========================*/
2893 /*------------------------------------------------------------------*/
2895 /* Name - mono_arch_output_basic_block */
2897 /* Function - Perform the "real" work of emitting instructions */
2898 /* that will do the work of in the basic block. */
2900 /*------------------------------------------------------------------*/
2903 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2908 guint8 *code = cfg->native_code + cfg->code_len;
2909 MonoInst *last_ins = NULL;
2910 guint last_offset = 0;
2914 if (cfg->opt & MONO_OPT_PEEPHOLE)
2915 peephole_pass (cfg, bb);
2917 /* we don't align basic blocks of loops on s390 */
2919 if (cfg->verbose_level > 2)
2920 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2922 cpos = bb->max_offset;
2924 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2925 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2926 //g_assert (!mono_compile_aot);
2929 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2930 /* this is not thread save, but good enough */
2931 /* fixme: howto handle overflows? */
2932 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2937 offset = code - cfg->native_code;
2939 max_len = ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
2941 if (offset > (cfg->code_size - max_len - 16)) {
2942 cfg->code_size *= 2;
2943 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2944 code = cfg->native_code + offset;
2947 mono_debug_record_line_number (cfg, ins, offset);
2949 switch (ins->opcode) {
2950 case OP_STOREI1_MEMBASE_IMM: {
2951 s390_lhi (code, s390_r14, ins->inst_imm);
2952 if (s390_is_uimm12(ins->inst_offset))
2953 s390_stc (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2955 s390_basr (code, s390_r13, 0);
2957 s390_word (code, ins->inst_offset);
2958 s390_l (code, s390_r13, 0, s390_r13, 4);
2959 s390_stc (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2963 case OP_STOREI2_MEMBASE_IMM: {
2964 s390_lhi (code, s390_r14, ins->inst_imm);
2965 if (s390_is_uimm12(ins->inst_offset)) {
2966 s390_sth (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2968 s390_basr (code, s390_r14, 0);
2970 s390_word (code, ins->inst_offset);
2971 s390_l (code, s390_r13, 0, s390_r13, 4);
2972 s390_sth (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2976 case OP_STORE_MEMBASE_IMM:
2977 case OP_STOREI4_MEMBASE_IMM: {
2978 if (s390_is_imm16(ins->inst_imm)) {
2979 s390_lhi (code, s390_r14, ins->inst_imm);
2981 s390_basr (code, s390_r13, 0);
2983 s390_word (code, ins->inst_imm);
2984 s390_l (code, s390_r14, 0, s390_r13, 4);
2986 if (s390_is_uimm12(ins->inst_offset)) {
2987 s390_st (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2989 s390_basr (code, s390_r13, 0);
2991 s390_word (code, ins->inst_offset);
2992 s390_l (code, s390_r13, 0, s390_r13, 4);
2993 s390_st (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2997 case OP_STOREI1_MEMBASE_REG: {
2998 if (s390_is_uimm12(ins->inst_offset)) {
2999 s390_stc (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3001 s390_basr (code, s390_r13, 0);
3003 s390_word (code, ins->inst_offset);
3004 s390_l (code, s390_r13, 0, s390_r13, 4);
3005 s390_stc (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3009 case OP_STOREI2_MEMBASE_REG: {
3010 if (s390_is_uimm12(ins->inst_offset)) {
3011 s390_sth (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3013 s390_basr (code, s390_r13, 0);
3015 s390_word (code, ins->inst_offset);
3016 s390_l (code, s390_r13, 0, s390_r13, 4);
3017 s390_sth (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3021 case OP_STORE_MEMBASE_REG:
3022 case OP_STOREI4_MEMBASE_REG: {
3023 if (s390_is_uimm12(ins->inst_offset)) {
3024 s390_st (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3026 s390_basr (code, s390_r13, 0);
3028 s390_word (code, ins->inst_offset);
3029 s390_l (code, s390_r13, 0, s390_r13, 4);
3030 s390_st (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3036 case CEE_LDIND_U4: {
3037 s390_basr (code, s390_r13, 0);
3039 s390_word (code, ins->inst_p0);
3040 s390_l (code, s390_r13, 0, s390_r13, 4);
3041 s390_l (code, ins->dreg, 0, s390_r13, 0);
3045 g_assert_not_reached ();
3047 case OP_LOAD_MEMBASE:
3048 case OP_LOADI4_MEMBASE:
3049 case OP_LOADU4_MEMBASE: {
3050 if (s390_is_uimm12(ins->inst_offset))
3051 s390_l (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3053 if (s390_is_imm16(ins->inst_offset)) {
3054 s390_lhi (code, s390_r13, ins->inst_offset);
3055 s390_l (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3057 s390_basr (code, s390_r13, 0);
3059 s390_word (code, ins->inst_offset);
3060 s390_l (code, s390_r13, 0, s390_r13, 4);
3061 s390_l (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3066 case OP_LOADU1_MEMBASE: {
3067 s390_lhi (code, s390_r0, 0);
3068 if (s390_is_uimm12(ins->inst_offset))
3069 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3071 s390_basr (code, s390_r13, 0);
3073 s390_word (code, ins->inst_offset);
3074 s390_l (code, s390_r13, 0, s390_r13, 4);
3075 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3077 s390_lr (code, ins->dreg, s390_r0);
3080 case OP_LOADI1_MEMBASE: {
3081 s390_lhi (code, s390_r0, 0);
3082 if (s390_is_uimm12(ins->inst_offset))
3083 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3085 s390_basr (code, s390_r13, 0);
3087 s390_word (code, ins->inst_offset);
3088 s390_l (code, s390_r13, 0, s390_r13, 4);
3089 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3091 s390_lhi (code, s390_r13, 0x80);
3092 s390_nr (code, s390_r13, s390_r0);
3094 s390_lhi (code, s390_r13, 0xff00);
3095 s390_or (code, s390_r0, s390_r13);
3096 s390_lr (code, ins->dreg, s390_r0);
3099 case OP_LOADU2_MEMBASE: {
3100 s390_lhi (code, s390_r0, 0);
3101 if (s390_is_uimm12(ins->inst_offset))
3102 s390_icm (code, s390_r0, 3, ins->inst_basereg, ins->inst_offset);
3104 s390_basr (code, s390_r13, 0);
3106 s390_word (code, ins->inst_offset);
3107 s390_l (code, s390_r13, 0, s390_r13, 4);
3108 s390_ar (code, s390_r13, ins->inst_basereg);
3109 s390_icm (code, s390_r0, 3, s390_r13, 0);
3111 s390_lr (code, ins->dreg, s390_r0);
3114 case OP_LOADI2_MEMBASE: {
3115 s390_lhi (code, s390_r0, 0);
3116 if (s390_is_uimm12(ins->inst_offset))
3117 s390_lh (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3119 s390_basr (code, s390_r13, 0);
3121 s390_word (code, ins->inst_offset);
3122 s390_l (code, s390_r13, 0, s390_r13, 4);
3123 s390_lh (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3125 s390_lr (code, ins->dreg, s390_r0);
3129 s390_lhi (code, s390_r0, 0x80);
3130 if (ins->dreg != ins->sreg1) {
3131 s390_lr (code, ins->dreg, ins->sreg1);
3133 s390_nr (code, s390_r0, ins->sreg1);
3135 s390_lhi (code, s390_r13, -1);
3136 s390_sll (code, s390_r13, 0, 8);
3137 s390_or (code, ins->dreg, s390_r13);
3141 s390_lhi (code, s390_r0, 0x80);
3142 if (ins->dreg != ins->sreg1) {
3143 s390_lr (code, ins->dreg, ins->sreg1);
3145 s390_nr (code, s390_r0, ins->sreg1);
3147 s390_lhi (code, s390_r13, -1);
3148 s390_sll (code, s390_r13, 0, 16);
3149 s390_or (code, ins->dreg, s390_r13);
3153 s390_lhi (code, s390_r0, 0xff);
3154 if (ins->dreg != ins->sreg1) {
3155 s390_lr (code, ins->dreg, ins->sreg1);
3157 s390_nr (code, ins->dreg, s390_r0);
3161 s390_lhi (code, s390_r0, -1);
3162 s390_sll (code, s390_r0, 0, 16);
3163 s390_srl (code, s390_r0, 0, 16);
3164 if (ins->dreg != ins->sreg1) {
3165 s390_lr (code, ins->dreg, ins->sreg1);
3167 s390_nr (code, ins->dreg, s390_r0);
3172 ((ins->next->opcode >= CEE_BNE_UN) &&
3173 (ins->next->opcode <= CEE_BLT_UN)))
3174 s390_clr (code, ins->sreg1, ins->sreg2);
3176 s390_cr (code, ins->sreg1, ins->sreg2);
3179 case OP_COMPARE_IMM: {
3180 if (s390_is_imm16 (ins->inst_imm)) {
3181 s390_lhi (code, s390_r0, ins->inst_imm);
3183 ((ins->next->opcode >= CEE_BNE_UN) &&
3184 (ins->next->opcode <= CEE_BLT_UN)))
3185 s390_clr (code, ins->sreg1, s390_r0);
3187 s390_cr (code, ins->sreg1, s390_r0);
3190 s390_basr (code, s390_r13, 0);
3192 s390_word (code, ins->inst_imm);
3194 ((ins->next->opcode >= CEE_BNE_UN) &&
3195 (ins->next->opcode <= CEE_BLT_UN)))
3196 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3198 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3202 case OP_X86_TEST_NULL: {
3203 s390_ltr (code, ins->sreg1, ins->sreg1);
3211 if (ins->dreg != ins->sreg1) {
3212 s390_lr (code, ins->dreg, ins->sreg1);
3214 s390_alr (code, ins->dreg, ins->sreg2);
3218 if (ins->dreg != ins->sreg1) {
3219 s390_lr (code, ins->dreg, ins->sreg1);
3221 s390_ar (code, ins->dreg, ins->sreg2);
3225 if (ins->dreg != ins->sreg1) {
3226 s390_lr (code, ins->dreg, ins->sreg1);
3228 s390_alcr (code, ins->dreg, ins->sreg2);
3234 (ins->next->opcode == OP_ADC_IMM)) {
3235 s390_basr (code, s390_r13, 0);
3237 s390_word (code, ins->inst_imm);
3238 if (ins->dreg != ins->sreg1) {
3239 s390_lr (code, ins->dreg, ins->sreg1);
3241 s390_al (code, ins->dreg, 0, s390_r13, 4);
3243 if (s390_is_imm16 (ins->inst_imm)) {
3244 if (ins->dreg != ins->sreg1) {
3245 s390_lr (code, ins->dreg, ins->sreg1);
3247 s390_ahi (code, ins->dreg, ins->inst_imm);
3249 s390_basr (code, s390_r13, 0);
3251 s390_word (code, ins->inst_imm);
3252 if (ins->dreg != ins->sreg1) {
3253 s390_lr (code, ins->dreg, ins->sreg1);
3255 s390_a (code, ins->dreg, 0, s390_r13, 4);
3261 if (s390_is_imm16 (ins->inst_imm)) {
3262 if (ins->dreg != ins->sreg1) {
3263 s390_lr (code, ins->dreg, ins->sreg1);
3265 s390_lhi (code, s390_r0, ins->inst_imm);
3266 s390_alcr (code, ins->dreg, s390_r0);
3268 s390_basr (code, s390_r13, 0);
3270 s390_word (code, ins->inst_imm);
3271 s390_l (code, s390_r13, 0, s390_r13, 4);
3272 s390_alcr (code, ins->dreg, s390_r13);
3277 if (ins->dreg != ins->sreg1) {
3278 s390_lr (code, ins->dreg, ins->sreg1);
3280 s390_sr (code, ins->dreg, ins->sreg2);
3284 if (ins->dreg != ins->sreg1) {
3285 s390_lr (code, ins->dreg, ins->sreg1);
3287 s390_sr (code, ins->dreg, ins->sreg2);
3291 if (ins->dreg != ins->sreg1) {
3292 s390_lr (code, ins->dreg, ins->sreg1);
3294 s390_slbr (code, ins->dreg, ins->sreg2);
3299 if (s390_is_imm16 (-ins->inst_imm)) {
3300 if (ins->dreg != ins->sreg1) {
3301 s390_lr (code, ins->dreg, ins->sreg1);
3303 s390_ahi (code, ins->dreg, -ins->inst_imm);
3305 s390_basr (code, s390_r13, 0);
3307 s390_word (code, ins->inst_imm);
3308 if (ins->dreg != ins->sreg1) {
3309 s390_lr (code, ins->dreg, ins->sreg1);
3311 s390_s (code, ins->dreg, 0, s390_r13, 4);
3316 s390_basr (code, s390_r13, 0);
3318 s390_word (code, ins->inst_imm);
3319 s390_sl (code, ins->dreg, 0, s390_r13, 4);
3323 if (ins->sreg1 == ins->dreg) {
3324 s390_nr (code, ins->dreg, ins->sreg2);
3327 if (ins->sreg2 == ins->dreg) {
3328 s390_nr (code, ins->dreg, ins->sreg1);
3331 s390_lr (code, ins->dreg, ins->sreg1);
3332 s390_nr (code, ins->dreg, ins->sreg2);
3338 if (s390_is_imm16 (ins->inst_imm)) {
3339 s390_lhi (code, s390_r0, ins->inst_imm);
3340 if (ins->dreg != ins->sreg1) {
3341 s390_lr (code, ins->dreg, ins->sreg1);
3343 s390_nr (code, ins->dreg, s390_r0);
3345 s390_basr (code, s390_r13, 0);
3347 s390_word (code, ins->inst_imm);
3348 if (ins->dreg != ins->sreg1) {
3349 s390_lr (code, ins->dreg, ins->sreg1);
3351 s390_n (code, ins->dreg, 0, s390_r13, 4);
3356 s390_lr (code, s390_r0, ins->sreg1);
3357 s390_srda (code, s390_r0, 0, 32);
3358 s390_dr (code, s390_r0, ins->sreg2);
3359 s390_lr (code, ins->dreg, s390_r1);
3363 s390_lr (code, s390_r0, ins->sreg1);
3364 s390_srdl (code, s390_r0, 0, 32);
3365 s390_dlr (code, s390_r0, ins->sreg2);
3366 s390_lr (code, ins->dreg, s390_r1);
3370 if (s390_is_imm16 (ins->inst_imm)) {
3371 s390_lhi (code, s390_r13, ins->inst_imm);
3372 s390_lr (code, s390_r0, ins->sreg1);
3374 s390_basr (code, s390_r13, 0);
3376 s390_word (code, ins->inst_imm);
3377 s390_lr (code, s390_r0, ins->sreg1);
3378 s390_l (code, s390_r13, 0, s390_r13, 4);
3380 s390_srda (code, s390_r0, 0, 32);
3381 s390_dr (code, s390_r0, ins->sreg2);
3382 s390_lr (code, ins->dreg, s390_r1);
3386 s390_lr (code, s390_r0, ins->sreg1);
3387 s390_srda (code, s390_r0, 0, 32);
3388 s390_dr (code, s390_r0, ins->sreg2);
3389 s390_lr (code, ins->dreg, s390_r0);
3392 s390_lr (code, s390_r0, ins->sreg1);
3393 s390_srdl (code, s390_r0, 0, 32);
3394 s390_dlr (code, s390_r0, ins->sreg2);
3395 s390_lr (code, ins->dreg, s390_r0);
3399 if (s390_is_imm16 (ins->inst_imm)) {
3400 s390_lhi (code, s390_r13, ins->inst_imm);
3401 s390_lr (code, s390_r0, ins->sreg1);
3403 s390_basr (code, s390_r13, 0);
3405 s390_word (code, ins->inst_imm);
3406 s390_lr (code, s390_r0, ins->sreg1);
3407 s390_l (code, s390_r13, 0, s390_r13, 4);
3409 s390_srda (code, s390_r0, 0, 32);
3410 s390_dr (code, s390_r0, ins->sreg2);
3411 s390_lr (code, ins->dreg, s390_r0);
3415 if (ins->sreg1 == ins->dreg) {
3416 s390_or (code, ins->dreg, ins->sreg2);
3419 if (ins->sreg2 == ins->dreg) {
3420 s390_or (code, ins->dreg, ins->sreg1);
3423 s390_lr (code, ins->dreg, ins->sreg1);
3424 s390_or (code, ins->dreg, ins->sreg2);
3430 if (s390_is_imm16 (ins->inst_imm)) {
3431 s390_lhi (code, s390_r0, ins->inst_imm);
3432 if (ins->dreg != ins->sreg1) {
3433 s390_lr (code, ins->dreg, ins->sreg1);
3435 s390_or (code, ins->dreg, s390_r0);
3437 s390_bras (code, s390_r13, 4);
3438 s390_word (code, ins->inst_imm);
3439 if (ins->dreg != ins->sreg1) {
3440 s390_lr (code, ins->dreg, ins->sreg1);
3442 s390_o (code, ins->dreg, 0, s390_r13, 0);
3447 if (ins->sreg1 == ins->dreg) {
3448 s390_xr (code, ins->dreg, ins->sreg2);
3451 if (ins->sreg2 == ins->dreg) {
3452 s390_xr (code, ins->dreg, ins->sreg1);
3455 s390_lr (code, ins->dreg, ins->sreg1);
3456 s390_xr (code, ins->dreg, ins->sreg2);
3462 if (s390_is_imm16 (ins->inst_imm)) {
3463 s390_lhi (code, s390_r0, ins->inst_imm);
3464 if (ins->dreg != ins->sreg1) {
3465 s390_lr (code, ins->dreg, ins->sreg1);
3467 s390_xr (code, ins->dreg, s390_r0);
3469 s390_basr (code, s390_r13, 0);
3471 s390_word (code, ins->inst_imm);
3472 if (ins->dreg != ins->sreg1) {
3473 s390_lr (code, ins->dreg, ins->sreg1);
3475 s390_x (code, ins->dreg, 0, s390_r13, 4);
3480 if (ins->sreg1 != ins->dreg) {
3481 s390_lr (code, ins->dreg, ins->sreg1);
3483 s390_sll (code, ins->dreg, ins->sreg2, 0);
3487 if (ins->sreg1 != ins->dreg) {
3488 s390_lr (code, ins->dreg, ins->sreg1);
3490 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3494 if (ins->sreg1 != ins->dreg) {
3495 s390_lr (code, ins->dreg, ins->sreg1);
3497 s390_sra (code, ins->dreg, ins->sreg2, 0);
3501 if (ins->sreg1 != ins->dreg) {
3502 s390_lr (code, ins->dreg, ins->sreg1);
3504 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3507 case OP_SHR_UN_IMM: {
3508 if (ins->sreg1 != ins->dreg) {
3509 s390_lr (code, ins->dreg, ins->sreg1);
3511 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3515 if (ins->sreg1 != ins->dreg) {
3516 s390_lr (code, ins->dreg, ins->sreg1);
3518 s390_srl (code, ins->dreg, ins->sreg2, 0);
3522 if (ins->sreg1 != ins->dreg) {
3523 s390_lr (code, ins->dreg, ins->sreg1);
3525 s390_lhi (code, s390_r0, -1);
3526 s390_xr (code, ins->dreg, s390_r0);
3530 s390_lcr (code, ins->dreg, ins->sreg1);
3534 if (ins->sreg1 == ins->dreg) {
3535 s390_msr (code, ins->dreg, ins->sreg2);
3538 if (ins->sreg2 == ins->dreg) {
3539 s390_msr (code, ins->dreg, ins->sreg1);
3542 s390_lr (code, ins->dreg, ins->sreg1);
3543 s390_msr (code, ins->dreg, ins->sreg2);
3549 if (s390_is_imm16 (ins->inst_imm)) {
3550 s390_lhi (code, s390_r13, ins->inst_imm);
3552 s390_basr (code, s390_r13, 0);
3554 s390_word (code, ins->inst_imm);
3555 if (ins->dreg != ins->sreg1) {
3556 s390_lr (code, ins->dreg, ins->sreg1);
3558 s390_l (code, s390_r13, 0, s390_r13, 4);
3560 s390_msr (code, ins->dreg, s390_r13);
3564 s390_lhi (code, s390_r0, 0);
3565 s390_lr (code, s390_r1, ins->sreg1);
3566 s390_mr (code, s390_r0, ins->sreg2);
3567 s390_ltr (code, s390_r0, s390_r0);
3568 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3569 s390_lr (code, ins->dreg, s390_r1);
3572 case CEE_MUL_OVF_UN: {
3573 s390_lhi (code, s390_r0, 0);
3574 s390_lr (code, s390_r1, ins->sreg1);
3575 s390_mlr (code, s390_r0, ins->sreg2);
3576 s390_ltr (code, s390_r0, s390_r0);
3577 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3578 s390_lr (code, ins->dreg, s390_r1);
3582 s390_l (code, s390_r0, 0, ins->sreg1, 4);
3583 s390_lr (code, s390_r14, s390_r0);
3584 s390_srda (code, s390_r0, 0, 32);
3585 s390_m (code, s390_r0, 0, ins->sreg2, 4);
3586 s390_srl (code, s390_r14, 0, 31);
3587 s390_a (code, s390_r14, 0, ins->sreg1, 0);
3588 s390_l (code, s390_r13, 0, ins->sreg2, 0);
3589 s390_srl (code, s390_r13, 0, 31);
3590 s390_ms (code, s390_r13, 0, ins->sreg1, 4);
3591 s390_ar (code, s390_r14, s390_r13);
3592 s390_st (code, s390_r14, 0, ins->dreg, 0);
3593 s390_st (code, s390_r1, 0, ins->dreg, 4);
3597 case OP_SETREGIMM: {
3598 if (s390_is_imm16(ins->inst_c0)) {
3599 s390_lhi (code, ins->dreg, ins->inst_c0);
3601 s390_basr (code, s390_r13, 0);
3603 s390_word (code, ins->inst_c0);
3604 s390_l (code, ins->dreg, 0, s390_r13, 4);
3609 s390_basr (code, s390_r13, 0);
3611 mono_add_patch_info (cfg, code - cfg->native_code,
3612 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3613 s390_word (code, 0);
3614 s390_l (code,ins->dreg, 0, s390_r13, 4);
3621 if (ins->dreg != ins->sreg1) {
3622 s390_lr (code, ins->dreg, ins->sreg1);
3627 int saved = ins->sreg1;
3628 if (ins->sreg1 == s390_r2) {
3629 s390_lr (code, s390_r0, ins->sreg1);
3632 if (ins->sreg2 != s390_r2)
3633 s390_lr (code, s390_r2, ins->sreg2);
3634 if (saved != s390_r3)
3635 s390_lr (code, s390_r3, saved);
3640 if (ins->dreg != ins->sreg1) {
3641 s390_ldr (code, ins->dreg, ins->sreg1);
3645 case OP_FCONV_TO_R4: {
3646 s390_ledbr (code, ins->dreg, ins->sreg1);
3650 g_assert_not_reached ();
3652 case OP_CHECK_THIS: {
3653 /* ensure ins->sreg1 is not NULL */
3654 s390_icm (code, s390_r0, 15, ins->sreg1, 0);
3662 call = (MonoCallInst*)ins;
3663 if (ins->flags & MONO_INST_HAS_METHOD)
3664 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method);
3666 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr);
3667 s390_brasl (code, s390_r14, 0);
3673 case OP_VOIDCALL_REG:
3675 s390_lr (code, s390_r1, ins->sreg1);
3676 s390_basr (code, s390_r14, s390_r1);
3679 case OP_FCALL_MEMBASE:
3680 case OP_LCALL_MEMBASE:
3681 case OP_VCALL_MEMBASE:
3682 case OP_VOIDCALL_MEMBASE:
3683 case OP_CALL_MEMBASE: {
3684 s390_l (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3685 s390_basr (code, s390_r14, s390_r1);
3689 g_assert_not_reached ();
3692 s390_lr (code, s390_r1, ins->sreg1);
3693 s390_ahi (code, s390_r1, 14);
3694 s390_srl (code, s390_r1, 0, 3);
3695 s390_sll (code, s390_r1, 0, 3);
3696 s390_l (code, s390_r13, 0, STK_BASE, 0);
3697 s390_lcr (code, s390_r1, s390_r1);
3698 s390_la (code, STK_BASE, STK_BASE, s390_r1, 0);
3699 s390_st (code, s390_r13, 0, STK_BASE, 0);
3700 s390_la (code, ins->dreg, 0, STK_BASE, S390_MINIMAL_STACK_SIZE+7);
3701 s390_srl (code, ins->dreg, 0, 3);
3702 s390_sll (code, ins->dreg, 0, 3);
3706 s390_br (code, s390_r14);
3710 s390_lr (code, s390_r2, ins->sreg1);
3711 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3712 (gpointer)"mono_arch_throw_exception");
3713 s390_brasl (code, s390_r14, 0);
3716 case OP_START_HANDLER: {
3717 s390_lr (code, s390_r0, s390_r14);
3718 s390_st (code, s390_r0, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3721 case OP_ENDFILTER: {
3722 if (ins->sreg1 != s390_r2)
3723 s390_lr (code, s390_r2, ins->sreg1);
3724 s390_l (code, STK_BASE, 0, STK_BASE, 0);
3725 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
3726 s390_br (code, s390_r14);
3729 case CEE_ENDFINALLY: {
3730 s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3731 s390_br (code, s390_r14);
3734 case OP_CALL_HANDLER: {
3735 mono_add_patch_info (cfg, code-cfg->native_code,
3736 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3737 s390_brasl (code, s390_r14, 0);
3741 ins->inst_c0 = code - cfg->native_code;
3745 EMIT_UNCOND_BRANCH(ins);
3748 s390_br (code, ins->sreg1);
3752 s390_lhi (code, ins->dreg, 1);
3754 s390_lhi (code, ins->dreg, 0);
3758 s390_lhi (code, ins->dreg, 1);
3760 s390_lhi (code, ins->dreg, 0);
3764 s390_lhi (code, ins->dreg, 1);
3766 s390_lhi (code, ins->dreg, 0);
3770 s390_lhi (code, ins->dreg, 1);
3772 s390_lhi (code, ins->dreg, 0);
3776 s390_lhi (code, ins->dreg, 1);
3778 s390_lhi (code, ins->dreg, 0);
3781 case OP_COND_EXC_EQ:
3782 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
3784 case OP_COND_EXC_NE_UN:
3785 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
3787 case OP_COND_EXC_LT:
3788 case OP_COND_EXC_LT_UN:
3789 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
3791 case OP_COND_EXC_GT:
3792 case OP_COND_EXC_GT_UN:
3793 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
3795 case OP_COND_EXC_GE:
3796 case OP_COND_EXC_GE_UN:
3797 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
3799 case OP_COND_EXC_LE:
3800 case OP_COND_EXC_LE_UN:
3801 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
3803 case OP_COND_EXC_OV:
3804 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
3806 case OP_COND_EXC_NO:
3807 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
3810 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
3812 case OP_COND_EXC_NC:
3813 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
3816 EMIT_COND_BRANCH (ins, S390_CC_EQ);
3819 EMIT_COND_BRANCH (ins, S390_CC_NE);
3823 EMIT_COND_BRANCH (ins, S390_CC_LT);
3827 EMIT_COND_BRANCH (ins, S390_CC_GT);
3831 EMIT_COND_BRANCH (ins, S390_CC_GE);
3835 EMIT_COND_BRANCH (ins, S390_CC_LE);
3838 /* floating point opcodes */
3840 if (*((float *) ins->inst_p0) == 0) {
3841 s390_lzdr (code, ins->dreg);
3843 s390_basr (code, s390_r13, 0);
3845 s390_word (code, ins->inst_p0);
3846 s390_l (code, s390_r13, 0, s390_r13, 4);
3847 s390_ld (code, ins->dreg, 0, s390_r13, 0);
3852 if (*((float *) ins->inst_p0) == 0) {
3853 s390_lzer (code, ins->dreg);
3855 s390_basr (code, s390_r13, 0);
3857 s390_word (code, ins->inst_p0);
3858 s390_l (code, s390_r13, 0, s390_r13, 4);
3859 s390_le (code, ins->dreg, 0, s390_r13, 0);
3860 s390_ldebr(code, ins->dreg, ins->dreg);
3864 case OP_STORER8_MEMBASE_REG: {
3865 if (s390_is_uimm12(ins->inst_offset)) {
3866 s390_std (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3868 s390_basr (code, s390_r13, 0);
3870 s390_word (code, ins->inst_offset);
3871 s390_l (code, s390_r13, 0, s390_r13, 4);
3872 s390_std (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3876 case OP_LOADR8_MEMBASE: {
3877 if (s390_is_uimm12(ins->inst_offset)) {
3878 s390_ld (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3880 s390_basr (code, s390_r13, 0);
3882 s390_word (code, ins->inst_offset);
3883 s390_l (code, s390_r13, 0, s390_r13, 4);
3884 s390_ld (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3888 case OP_STORER4_MEMBASE_REG: {
3889 if (s390_is_uimm12(ins->inst_offset)) {
3890 s390_ledbr(code, s390_f0, ins->sreg1);
3891 s390_ste (code, s390_f0, 0, ins->inst_destbasereg, ins->inst_offset);
3893 s390_basr (code, s390_r13, 0);
3895 s390_word (code, ins->inst_offset);
3896 s390_l (code, s390_r13, 0, s390_r13, 4);
3897 s390_ledbr(code, s390_f0, ins->sreg1);
3898 s390_ste (code, s390_f0, s390_r13, ins->inst_destbasereg, 0);
3902 case OP_LOADR4_MEMBASE: {
3903 if (s390_is_uimm12(ins->inst_offset)) {
3904 s390_le (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3906 s390_basr (code, s390_r13, 0);
3908 s390_word (code, ins->inst_offset);
3909 s390_l (code, s390_r13, 0, s390_r13, 4);
3910 s390_le (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3912 s390_ldebr (code, ins->dreg, ins->dreg);
3915 case CEE_CONV_R_UN: {
3916 s390_cdfbr (code, ins->dreg, ins->sreg1);
3917 s390_ltr (code, ins->sreg1, ins->sreg1);
3918 s390_jnl (code, 12);
3919 s390_basr (code, s390_r13, 0);
3921 s390_word (code, 0x41f00000);
3922 s390_word (code, 0);
3923 s390_adb (code, ins->dreg, 0, s390_r13, 4);
3927 s390_cdfbr (code, ins->dreg, ins->sreg1);
3931 s390_cdfbr (code, ins->dreg, ins->sreg1);
3934 case OP_FCONV_TO_I1:
3935 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
3937 case OP_FCONV_TO_U1:
3938 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
3940 case OP_FCONV_TO_I2:
3941 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
3943 case OP_FCONV_TO_U2:
3944 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
3946 case OP_FCONV_TO_I4:
3948 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
3950 case OP_FCONV_TO_U4:
3952 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
3954 case OP_FCONV_TO_I8:
3955 case OP_FCONV_TO_U8:
3956 g_assert_not_reached ();
3957 /* Implemented as helper calls */
3959 case OP_LCONV_TO_R_UN:
3960 g_assert_not_reached ();
3961 /* Implemented as helper calls */
3963 case OP_LCONV_TO_OVF_I: {
3964 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
3966 s390_ltr (code, ins->sreg2, ins->sreg2);
3967 s390_jnl (code, 0); CODEPTR(code, o[0]);
3968 s390_ltr (code, ins->sreg1, ins->sreg1);
3969 s390_jnl (code, 0); CODEPTR(code, o[1]);
3970 s390_lhi (code, s390_r13, -1);
3971 s390_cr (code, ins->sreg1, s390_r13);
3972 s390_jnz (code, 0); CODEPTR(code, o[2]);
3973 if (ins->dreg != ins->sreg2)
3974 s390_lr (code, ins->dreg, ins->sreg2);
3975 s390_j (code, 0); CODEPTR(code, o[3]);
3976 PTRSLOT(code, o[0]);
3977 s390_jz (code, 0); CODEPTR(code, o[4]);
3978 PTRSLOT(code, o[1]);
3979 PTRSLOT(code, o[2]);
3980 mono_add_patch_info (cfg, code - cfg->native_code,
3981 MONO_PATCH_INFO_EXC, "OverflowException");
3982 s390_brasl (code, s390_r14, 0);
3983 PTRSLOT(code, o[3]);
3984 PTRSLOT(code, o[4]);
3988 s390_sqdbr (code, ins->dreg, ins->sreg1);
3992 if (ins->dreg == ins->sreg1)
3993 s390_adbr (code, ins->dreg, ins->sreg2);
3995 if (ins->dreg == ins->sreg2)
3996 s390_adbr (code, ins->dreg, ins->sreg1);
3998 s390_ldr (code, ins->dreg, ins->sreg1);
3999 s390_adbr (code, ins->dreg, ins->sreg2);
4005 if (ins->dreg == ins->sreg1)
4006 s390_sdbr (code, ins->dreg, ins->sreg2);
4008 s390_ldr (code, ins->dreg, ins->sreg1);
4009 s390_sdbr (code, ins->dreg, ins->sreg2);
4014 if (ins->dreg == ins->sreg1)
4015 s390_mdbr (code, ins->dreg, ins->sreg2);
4017 if (ins->dreg == ins->sreg2)
4018 s390_mdbr (code, ins->dreg, ins->sreg1);
4020 s390_ldr (code, ins->dreg, ins->sreg1);
4021 s390_mdbr (code, ins->dreg, ins->sreg2);
4027 if (ins->dreg == ins->sreg1)
4028 s390_ddbr (code, ins->dreg, ins->sreg2);
4030 s390_ldr (code, ins->dreg, ins->sreg1);
4031 s390_ddbr (code, ins->dreg, ins->sreg2);
4036 s390_lcdbr (code, ins->dreg, ins->sreg1);
4040 if (ins->dreg != ins->sreg1) {
4041 s390_ldr (code, ins->dreg, ins->sreg1);
4043 s390_didbr (code, ins->dreg, ins->sreg2, 5, s390_f15);
4047 s390_cdbr (code, ins->sreg1, ins->sreg2);
4051 s390_cdbr (code, ins->sreg1, ins->sreg2);
4052 s390_lhi (code, ins->dreg, 1);
4054 s390_lhi (code, ins->dreg, 0);
4058 s390_cdbr (code, ins->sreg1, ins->sreg2);
4059 s390_lhi (code, ins->dreg, 1);
4061 s390_lhi (code, ins->dreg, 0);
4065 s390_cdbr (code, ins->sreg1, ins->sreg2);
4066 s390_lhi (code, ins->dreg, 1);
4068 s390_lhi (code, ins->dreg, 0);
4072 s390_cdbr (code, ins->sreg1, ins->sreg2);
4073 s390_lhi (code, ins->dreg, 1);
4075 s390_lhi (code, ins->dreg, 0);
4079 s390_cdbr (code, ins->sreg1, ins->sreg2);
4080 s390_lhi (code, ins->dreg, 1);
4082 s390_lhi (code, ins->dreg, 0);
4086 EMIT_COND_BRANCH (ins, S390_CC_EQ|S390_CC_OV);
4089 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4092 EMIT_COND_BRANCH (ins, S390_CC_LT);
4095 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4098 EMIT_COND_BRANCH (ins, S390_CC_GT);
4101 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4104 EMIT_COND_BRANCH (ins, S390_CC_GE);
4107 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4110 EMIT_COND_BRANCH (ins, S390_CC_LE);
4113 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4115 case CEE_CKFINITE: {
4117 s390_lhi (code, s390_r13, 0xfc0);
4118 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4119 s390_jz (code, 0); CODEPTR(code, o);
4120 mono_add_patch_info (cfg, code - cfg->native_code + 2,
4121 MONO_PATCH_INFO_EXC, "ArithmeticException");
4122 s390_brasl (code, s390_r14,0);
4127 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4128 g_assert_not_reached ();
4131 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4132 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
4133 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4134 g_assert_not_reached ();
4140 last_offset = offset;
4145 cfg->code_len = code - cfg->native_code;
4148 /*========================= End of Function ========================*/
4150 /*------------------------------------------------------------------*/
4152 /* Name - mono_arch_register_lowlevel_calls */
4154 /* Function - Register routines to help with --trace operation. */
4156 /*------------------------------------------------------------------*/
4159 mono_arch_register_lowlevel_calls (void)
4161 mono_register_jit_icall (enter_method, "mono_enter_method", NULL, TRUE);
4162 mono_register_jit_icall (leave_method, "mono_leave_method", NULL, TRUE);
4165 /*========================= End of Function ========================*/
4167 /*------------------------------------------------------------------*/
4169 /* Name - mono_arch_patch_code */
4171 /* Function - Process the patch data created during the */
4172 /* instruction build process. This resolves jumps, */
4173 /* calls, variables etc. */
4175 /*------------------------------------------------------------------*/
4178 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4180 MonoJumpInfo *patch_info;
4182 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4183 unsigned char *ip = patch_info->ip.i + code;
4186 switch (patch_info->type) {
4187 case MONO_PATCH_INFO_BB:
4188 target = S390_RELATIVE((patch_info->data.bb->native_offset+code),
4190 ip += 2; /* Skip over op-code */
4192 case MONO_PATCH_INFO_ABS:
4193 target = S390_RELATIVE(patch_info->data.target, ip);
4194 ip += 2; /* Skip over op-code */
4196 case MONO_PATCH_INFO_LABEL:
4197 target = S390_RELATIVE((patch_info->data.inst->inst_c0+code),ip);
4198 ip += 2; /* Skip over op-code */
4200 case MONO_PATCH_INFO_IP:
4203 case MONO_PATCH_INFO_METHOD_REL:
4204 g_assert_not_reached ();
4205 *((gpointer *)(ip)) = code + patch_info->data.offset;
4207 case MONO_PATCH_INFO_INTERNAL_METHOD: {
4208 MonoJitICallInfo *mi = mono_find_jit_icall_by_name (patch_info->data.name);
4210 g_warning ("unknown MONO_PATCH_INFO_INTERNAL_METHOD %s", patch_info->data.name);
4211 g_assert_not_reached ();
4213 target = S390_RELATIVE(mono_icall_get_wrapper (mi), ip);
4214 ip += 2; /* Skip over op-code */
4217 case MONO_PATCH_INFO_METHOD_JUMP:
4218 g_assert_not_reached ();
4220 case MONO_PATCH_INFO_METHOD:
4221 if (patch_info->data.method == method) {
4222 target = S390_RELATIVE(code, ip);
4224 /* get the trampoline to the method from the domain */
4225 target = S390_RELATIVE(mono_arch_create_jit_trampoline (patch_info->data.method), ip);
4226 target = mono_arch_create_jit_trampoline(patch_info->data.method);
4227 target = S390_RELATIVE(target, ip);
4229 ip += 2; /* Skip over op-code */
4231 case MONO_PATCH_INFO_SWITCH: {
4232 gpointer *table = (gpointer *)patch_info->data.target;
4234 /*------------------------------------------------------*/
4235 /* ip is pointing at the basr r13,0/j +4 instruction */
4236 /* the vtable value follows this (i.e. ip+6) */
4237 /*------------------------------------------------------*/
4238 *((gconstpointer *)(ip+6)) = table;
4240 for (i = 0; i < patch_info->table_size; i++) {
4241 table [i] = (int)patch_info->data.table [i] + code;
4245 case MONO_PATCH_INFO_METHODCONST:
4246 case MONO_PATCH_INFO_CLASS:
4247 case MONO_PATCH_INFO_IMAGE:
4248 case MONO_PATCH_INFO_FIELD:
4249 target = S390_RELATIVE(patch_info->data.target, ip);
4251 case MONO_PATCH_INFO_R4:
4252 case MONO_PATCH_INFO_R8:
4253 g_assert_not_reached ();
4254 *((gconstpointer *)(ip + 2)) = patch_info->data.target;
4256 case MONO_PATCH_INFO_IID:
4257 mono_class_init (patch_info->data.klass);
4258 target = S390_RELATIVE(patch_info->data.klass->interface_id, ip);
4260 case MONO_PATCH_INFO_VTABLE:
4261 target = S390_RELATIVE(mono_class_vtable (domain, patch_info->data.klass),ip);
4264 case MONO_PATCH_INFO_CLASS_INIT:
4265 target = S390_RELATIVE(mono_create_class_init_trampoline (mono_class_vtable (domain, patch_info->data.klass)), ip);
4268 case MONO_PATCH_INFO_SFLDA: {
4269 MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
4270 if (!vtable->initialized && !(vtable->klass->flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT) && mono_class_needs_cctor_run (vtable->klass, method))
4271 /* Done by the generated code */
4275 mono_runtime_class_init (vtable);
4277 target = S390_RELATIVE((char*)vtable->data + patch_info->data.field->offset, ip);
4281 case MONO_PATCH_INFO_EXC_NAME:
4282 *((gconstpointer *)(ip)) = patch_info->data.name;
4284 case MONO_PATCH_INFO_LDSTR:
4285 target = mono_ldstr (domain, patch_info->data.token->image,
4286 mono_metadata_token_index (patch_info->data.token->token));
4288 case MONO_PATCH_INFO_TYPE_FROM_HANDLE: {
4290 MonoClass *handle_class;
4292 handle = mono_ldtoken (patch_info->data.token->image,
4293 patch_info->data.token->token,
4294 &handle_class, NULL);
4295 mono_class_init (handle_class);
4296 mono_class_init (mono_class_from_mono_type (handle));
4301 case MONO_PATCH_INFO_LDTOKEN: {
4303 MonoClass *handle_class;
4305 handle = mono_ldtoken (patch_info->data.token->image,
4306 patch_info->data.token->token,
4307 &handle_class, NULL);
4308 mono_class_init (handle_class);
4313 case MONO_PATCH_INFO_EXC:
4314 /* everything is dealt with at epilog output time */
4317 g_assert_not_reached ();
4319 s390_patch (ip, target);
4323 /*========================= End of Function ========================*/
4325 /*------------------------------------------------------------------*/
4327 /* Name - mono_arch_max_epilog_size */
4329 /* Function - Determine the maximum size of the epilog code. */
4331 /*------------------------------------------------------------------*/
4334 mono_arch_max_epilog_size (MonoCompile *cfg)
4336 int max_epilog_size = 96;
4337 MonoJumpInfo *patch_info;
4339 if (cfg->method->save_lmf)
4340 max_epilog_size += 128;
4342 if (mono_jit_trace_calls != NULL)
4343 max_epilog_size += 128;
4345 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4346 max_epilog_size += 128;
4348 /* count the number of exception infos */
4350 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4351 if (patch_info->type == MONO_PATCH_INFO_EXC)
4352 max_epilog_size += 26;
4355 return max_epilog_size;
4358 /*========================= End of Function ========================*/
4360 /*------------------------------------------------------------------*/
4362 /* Name - mono_arch_emit_prolog */
4364 /* Function - Create the instruction sequence for a function */
4367 /*------------------------------------------------------------------*/
4370 mono_arch_emit_prolog (MonoCompile *cfg)
4372 MonoMethod *method = cfg->method;
4374 MonoMethodSignature *sig;
4376 int alloc_size, pos, max_offset, i, lmfOffset;
4382 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
4385 cfg->code_size = 256;
4386 cfg->native_code = code = g_malloc (cfg->code_size);
4388 s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4390 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4391 cfg->used_int_regs |= 1 << 11;
4394 alloc_size = cfg->stack_offset;
4396 // alloc_size += S390_TRACE_STACK_SIZE;
4398 /* reserve room to save return value */
4402 // alloc_size += pos;
4404 // if (method->save_lmf)
4405 // alloc_size += sizeof(MonoLMF);
4407 // alloc_size = S390_ALIGN(alloc_size, S390_STACK_ALIGNMENT);
4409 cfg->stack_usage = alloc_size;
4410 s390_lr (code, s390_r11, STK_BASE);
4411 if (s390_is_imm16 (-alloc_size)) {
4412 s390_ahi (code, STK_BASE, -alloc_size);
4414 int stackSize = alloc_size;
4415 while (stackSize > 32767) {
4416 s390_ahi (code, STK_BASE, -32767);
4419 s390_ahi (code, STK_BASE, -stackSize);
4421 s390_st (code, s390_r11, 0, STK_BASE, 0);
4423 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
4424 s390_lr (code, s390_r11, STK_BASE);
4426 /* compute max_offset in order to use short forward jumps
4427 * we always do it on s390 because the immediate displacement
4428 * for jumps is too small
4431 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4432 MonoInst *ins = bb->code;
4433 bb->max_offset = max_offset;
4435 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4439 max_offset += ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
4444 /* load arguments allocated to register from the stack */
4445 sig = method->signature;
4448 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
4450 if (cinfo->struct_ret) {
4451 ArgInfo *ainfo = &cinfo->ret;
4453 inst->unused = ainfo->vtsize;
4454 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4457 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4458 ArgInfo *ainfo = cinfo->args + i;
4459 inst = cfg->varinfo [pos];
4461 if (inst->opcode == OP_REGVAR) {
4462 if (ainfo->regtype == RegTypeGeneral)
4463 s390_lr (code, inst->dreg, ainfo->reg);
4464 else if (ainfo->regtype == RegTypeFP) {
4465 if (ainfo->size == 4) {
4466 s390_ledbr (code, inst->dreg, ainfo->reg);
4468 s390_ldr (code, inst->dreg, ainfo->reg);
4471 else if (ainfo->regtype == RegTypeBase) {
4472 s390_lr (code, s390_r13, STK_BASE);
4473 s390_ahi (code, s390_r13, alloc_size);
4474 s390_l (code, inst->dreg, 0, s390_r13, ainfo->offset);
4476 g_assert_not_reached ();
4478 if (cfg->verbose_level > 2)
4479 g_print ("Argument %d assigned to register %s\n",
4480 pos, mono_arch_regname (inst->dreg));
4482 if (ainfo->regtype == RegTypeGeneral) {
4483 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4484 g_assert_not_reached();
4485 switch (ainfo->size) {
4487 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4490 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4493 s390_stm (code, ainfo->reg, ainfo->reg + 1,
4494 inst->inst_basereg, inst->inst_offset);
4497 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4499 } else if (ainfo->regtype == RegTypeBase) {
4500 } else if (ainfo->regtype == RegTypeFP) {
4501 if (ainfo->size == 8)
4502 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4503 else if (ainfo->size == 4)
4504 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4506 g_assert_not_reached ();
4507 } else if (ainfo->regtype == RegTypeStructByVal) {
4508 int doffset = inst->inst_offset;
4510 if (ainfo->reg != STK_BASE)
4514 s390_lr (code, s390_r13, STK_BASE);
4515 s390_ahi (code, s390_r13, alloc_size);
4517 switch (ainfo->size) {
4519 if (ainfo->reg == STK_BASE)
4520 s390_ic (code, reg, 0, s390_r13, ainfo->offset+3);
4521 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4524 if (ainfo->reg == STK_BASE)
4525 s390_lh (code, reg, 0, s390_r13, ainfo->offset+2);
4526 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4529 if (ainfo->reg == STK_BASE)
4530 s390_l (code, reg, 0, s390_r13, ainfo->offset);
4531 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4534 if (ainfo->reg == STK_BASE)
4535 s390_lm (code, s390_r0, s390_r1, s390_r13, ainfo->offset);
4536 s390_stm (code, reg, reg+1, inst->inst_basereg, doffset);
4539 } else if (ainfo->regtype == RegTypeStructByAddr) {
4540 code = emit_memcpy (code, ainfo->vtsize,
4541 inst->inst_basereg, inst->inst_offset, ainfo->reg, 0);
4543 g_assert_not_reached ();
4548 if (method->save_lmf) {
4549 /*---------------------------------------------------------------*/
4550 /* Preserve the parameter registers while we fix up the lmf */
4551 /*---------------------------------------------------------------*/
4552 s390_lr (code, s390_r7, s390_r2);
4553 s390_lr (code, s390_r8, s390_r3);
4554 s390_lr (code, s390_r9, s390_r4);
4555 s390_lr (code, s390_r10, s390_r5);
4557 mono_add_patch_info (cfg, code - cfg->native_code,
4558 MONO_PATCH_INFO_INTERNAL_METHOD,
4559 (gpointer)"mono_get_lmf_addr");
4560 /*---------------------------------------------------------------*/
4561 /* On return from this call r2 have the address of the &lmf */
4562 /*---------------------------------------------------------------*/
4563 s390_brasl (code, s390_r14, 0);
4565 /*---------------------------------------------------------------*/
4566 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4567 /*---------------------------------------------------------------*/
4568 lmfOffset = alloc_size - sizeof(MonoLMF);
4570 s390_lr (code, s390_r13, cfg->frame_reg);
4571 s390_ahi (code, s390_r13, lmfOffset);
4573 /*---------------------------------------------------------------*/
4574 /* Set lmf.lmf_addr = jit_tls->lmf */
4575 /*---------------------------------------------------------------*/
4576 s390_st (code, s390_r2, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4578 /*---------------------------------------------------------------*/
4579 /* Get current lmf */
4580 /*---------------------------------------------------------------*/
4581 s390_l (code, s390_r0, 0, s390_r2, 0);
4583 /*---------------------------------------------------------------*/
4584 /* Set our lmf as the current lmf */
4585 /*---------------------------------------------------------------*/
4586 s390_st (code, s390_r13, 0, s390_r2, 0);
4588 /*---------------------------------------------------------------*/
4589 /* Have our lmf.previous_lmf point to the last lmf */
4590 /*---------------------------------------------------------------*/
4591 s390_st (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4593 /*---------------------------------------------------------------*/
4594 /* save method info */
4595 /*---------------------------------------------------------------*/
4596 s390_basr (code, s390_r1, 0);
4598 s390_word (code, method);
4599 s390_l (code, s390_r1, 0, s390_r1, 4);
4600 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, method));
4602 /*---------------------------------------------------------------*/
4603 /* save the current IP */
4604 /*---------------------------------------------------------------*/
4605 s390_lr (code, s390_r1, cfg->frame_reg);
4606 // s390_ahi (code, s390_r1, alloc_size);
4607 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4608 s390_l (code, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
4609 s390_la (code, s390_r1, 0, s390_r1, 0);
4610 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4612 /*---------------------------------------------------------------*/
4613 /* Save general and floating point registers */
4614 /*---------------------------------------------------------------*/
4615 s390_stm (code, s390_r2, s390_r6, s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4616 for (i = 0; i < 16; i++) {
4617 s390_std (code, i, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4620 /*---------------------------------------------------------------*/
4621 /* Restore the parameter registers now that we've set up the lmf */
4622 /*---------------------------------------------------------------*/
4623 s390_lr (code, s390_r2, s390_r7);
4624 s390_lr (code, s390_r3, s390_r8);
4625 s390_lr (code, s390_r4, s390_r9);
4626 s390_lr (code, s390_r5, s390_r10);
4630 code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
4632 cfg->code_len = code - cfg->native_code;
4638 /*========================= End of Function ========================*/
4640 /*------------------------------------------------------------------*/
4642 /* Name - mono_arch_emit_epilog */
4644 /* Function - Emit the instructions for a function epilog. */
4646 /*------------------------------------------------------------------*/
4649 mono_arch_emit_epilog (MonoCompile *cfg)
4651 MonoJumpInfo *patch_info;
4652 MonoMethod *method = cfg->method;
4653 MonoMethodSignature *sig = method->signature;
4655 int i, lmfOffset, tracing = 0;
4658 code = cfg->native_code + cfg->code_len;
4660 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4661 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
4665 if (method->save_lmf) {
4666 s390_lr (code, s390_r13, cfg->frame_reg);
4668 lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4670 /*-------------------------------------------------*/
4672 /*-------------------------------------------------*/
4673 s390_ahi (code, s390_r13, lmfOffset);
4675 /*-------------------------------------------------*/
4676 /* r6 = &jit_tls->lmf */
4677 /*-------------------------------------------------*/
4678 s390_l (code, s390_r6, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4680 /*-------------------------------------------------*/
4681 /* r0 = lmf.previous_lmf */
4682 /*-------------------------------------------------*/
4683 s390_l (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4685 /*-------------------------------------------------*/
4686 /* jit_tls->lmf = previous_lmf */
4687 /*-------------------------------------------------*/
4688 s390_l (code, s390_r13, 0, s390_r6, 0);
4689 s390_st (code, s390_r0, 0, s390_r6, 0);
4692 if (cfg->frame_reg != STK_BASE)
4693 s390_lr (code, STK_BASE, cfg->frame_reg);
4695 s390_ahi (code, STK_BASE, cfg->stack_usage);
4696 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4697 s390_br (code, s390_r14);
4699 /* add code to raise exceptions */
4700 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4701 switch (patch_info->type) {
4702 case MONO_PATCH_INFO_EXC: {
4703 /*-----------------------------------------------------*/
4704 /* Patch the branch in epilog to come here */
4705 /*-----------------------------------------------------*/
4706 s390_patch (patch_info->ip.i+cfg->native_code+2,
4707 S390_RELATIVE(code,patch_info->ip.i+cfg->native_code));
4708 /*-----------------------------------------------------*/
4709 /* Patch the parameter passed to the handler */
4710 /*-----------------------------------------------------*/
4711 s390_basr (code, s390_r13, 0);
4713 mono_add_patch_info (cfg, code - cfg->native_code,
4714 MONO_PATCH_INFO_EXC_NAME,
4715 patch_info->data.target);
4716 s390_word (code, 0);
4717 /*-----------------------------------------------------*/
4718 /* Load the return address and the parameter register */
4719 /*-----------------------------------------------------*/
4720 s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
4721 cfg->native_code + 8), code));
4722 s390_l (code, s390_r2, 0, s390_r13, 4);
4723 /*-----------------------------------------------------*/
4724 /* Reuse the current patch to set the jump */
4725 /*-----------------------------------------------------*/
4726 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
4727 patch_info->data.name = "mono_arch_throw_exception_by_name";
4728 patch_info->ip.i = code - cfg->native_code;
4729 s390_jcl (code, S390_CC_UN, 0);
4738 cfg->code_len = code - cfg->native_code;
4740 g_assert (cfg->code_len < cfg->code_size);
4744 /*========================= End of Function ========================*/
4746 /*------------------------------------------------------------------*/
4748 /* Name - mono_arch_setup_jit_tls_data */
4750 /* Function - Setup the JIT's Thread Level Specific Data. */
4752 /*------------------------------------------------------------------*/
4755 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
4759 /*========================= End of Function ========================*/
4761 /*------------------------------------------------------------------*/
4763 /* Name - mono_arch_free_jit_tls_data */
4765 /* Function - Free tls data. */
4767 /*------------------------------------------------------------------*/
4770 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
4774 /*========================= End of Function ========================*/
4776 /*------------------------------------------------------------------*/
4778 /* Name - mono_arch_emit_this_vret_args */
4782 /*------------------------------------------------------------------*/
4785 mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
4787 int this_dreg = s390_r2;
4790 this_dreg = s390_r3;
4792 /* add the this argument */
4793 if (this_reg != -1) {
4795 MONO_INST_NEW (cfg, this, OP_SETREG);
4796 this->type = this_type;
4797 this->sreg1 = this_reg;
4798 this->dreg = this_dreg;
4799 mono_bblock_add_inst (cfg->cbb, this);
4804 MONO_INST_NEW (cfg, vtarg, OP_SETREG);
4805 vtarg->type = STACK_MP;
4806 vtarg->sreg1 = vt_reg;
4807 vtarg->dreg = s390_r2;
4808 mono_bblock_add_inst (cfg->cbb, vtarg);
4812 /*========================= End of Function ========================*/
4814 /*------------------------------------------------------------------*/
4816 /* Name - mono_arch_get_opcode_for_method */
4818 /* Function - Check for opcodes we can handle directly in */
4821 /*------------------------------------------------------------------*/
4824 mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
4826 if (cmethod->klass == mono_defaults.math_class) {
4827 if (strcmp (cmethod->name, "Sqrt") == 0)
4833 /*========================= End of Function ========================*/
4835 /*------------------------------------------------------------------*/
4837 /* Name - mono_arch_print_tree */
4839 /* Function - Print platform-specific opcode details. */
4841 /* Returns - 1 - opcode details have been printed */
4842 /* 0 - opcode details have not been printed */
4844 /*------------------------------------------------------------------*/
4847 mono_arch_print_tree (MonoInst *tree, int arity)
4851 switch (tree->opcode) {
4852 case OP_S390_LOADARG:
4853 case OP_S390_ARGPTR:
4854 case OP_S390_STKARG:
4855 printf ("[0x%x(%s)]", tree->inst_offset,
4856 mono_arch_regname (tree->inst_basereg));
4865 /*========================= End of Function ========================*/
4867 /*------------------------------------------------------------------*/
4869 /* Name - mono_arch_regalloc_cost */
4871 /* Function - Determine the cost, in the number of memory */
4872 /* references, of the action of allocating the var- */
4873 /* iable VMV into a register during global register */
4876 /* Returns - Cost */
4878 /*------------------------------------------------------------------*/
4881 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
4887 /*========================= End of Function ========================*/