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) \
25 if (ins->flags & MONO_INST_BRLABEL) { \
26 if (ins->inst_i0->inst_c0) { \
28 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
29 if (s390_is_uimm16(displace)) { \
30 s390_brc (code, cond, displace); \
32 s390_jcl (code, cond, displace); \
35 mono_add_patch_info (cfg, code - cfg->native_code, \
36 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
37 s390_jcl (code, cond, 0); \
40 if (ins->inst_true_bb->native_offset) { \
42 displace = ((cfg->native_code + \
43 ins->inst_true_bb->native_offset) - code) / 2; \
44 if (s390_is_uimm16(displace)) { \
45 s390_brc (code, cond, displace); \
47 s390_jcl (code, cond, displace); \
50 mono_add_patch_info (cfg, code - cfg->native_code, \
51 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
52 s390_jcl (code, cond, 0); \
56 #define EMIT_UNCOND_BRANCH(ins) \
57 if (ins->flags & MONO_INST_BRLABEL) { \
58 if (ins->inst_i0->inst_c0) { \
60 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
61 if (s390_is_uimm16(displace)) { \
62 s390_brc (code, S390_CC_UN, displace); \
64 s390_jcl (code, S390_CC_UN, displace); \
67 mono_add_patch_info (cfg, code - cfg->native_code, \
68 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
69 s390_jcl (code, S390_CC_UN, 0); \
72 if (ins->inst_target_bb->native_offset) { \
74 displace = ((cfg->native_code + \
75 ins->inst_target_bb->native_offset) - code) / 2; \
76 if (s390_is_uimm16(displace)) { \
77 s390_brc (code, S390_CC_UN, displace); \
79 s390_jcl (code, S390_CC_UN, displace); \
82 mono_add_patch_info (cfg, code - cfg->native_code, \
83 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
84 s390_jcl (code, S390_CC_UN, 0); \
88 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
90 mono_add_patch_info (cfg, code - cfg->native_code, \
91 MONO_PATCH_INFO_EXC, exc_name); \
92 s390_jcl (code, cond, 0); \
96 #define DEBUG(a) if (cfg->verbose_level > 1) a
97 #define reg_is_freeable(r) ((r) >= 3 && (r) <= 10)
98 #define freg_is_freeable(r) ((r) >= 1 && (r) <= 14)
100 /*----------------------------------------*/
101 /* use s390_r3-s390_r10 as temp registers */
102 /*----------------------------------------*/
103 #define S390_CALLER_REGS (0x03f8)
105 /*----------------------------------------*/
106 /* use s390_f2-s390_f14 as temp registers */
107 /*----------------------------------------*/
108 #define S390_CALLER_FREGS (0x73f8)
110 #define S390_TRACE_STACK_SIZE (5*sizeof(gint32)+3*sizeof(gdouble))
112 /*========================= End of Defines =========================*/
114 /*------------------------------------------------------------------*/
115 /* I n c l u d e s */
116 /*------------------------------------------------------------------*/
121 #include <mono/metadata/appdomain.h>
122 #include <mono/metadata/debug-helpers.h>
124 #include "mini-s390.h"
126 #include "cpu-s390.h"
128 /*========================= End of Includes ========================*/
130 /*------------------------------------------------------------------*/
131 /* T y p e d e f s */
132 /*------------------------------------------------------------------*/
141 /*------------------------------------------------------------------*/
142 /* Used by the instrument_emit_epilog */
143 /*------------------------------------------------------------------*/
160 typedef struct InstList InstList;
177 gint32 offset; /* offset from caller's stack */
178 gint32 offparm; /* offset on callee's stack */
179 guint16 vtsize; /* in param area */
181 guint8 regtype; /* See RegType* */
182 guint32 size; /* Size of structure used by RegTypeStructByVal */
198 /*========================= End of Typedefs ========================*/
200 /*------------------------------------------------------------------*/
201 /* P r o t o t y p e s */
202 /*------------------------------------------------------------------*/
204 static guint32 *emit_memcpy (guint8 *, int, int, int, int, int);
205 static void indent (int);
206 static void decodeParm (MonoType *, void *, int);
207 static void enter_method (MonoMethod *, RegParm *, char *);
208 static void leave_method (MonoMethod *, ...);
209 static gboolean is_regsize_var (MonoType *);
210 static void add_general (guint *, size_data *, ArgInfo *, gboolean);
211 static CallInfo * calculate_sizes (MonoMethodSignature *, size_data *, gboolean);
212 static void peephole_pass (MonoCompile *, MonoBasicBlock *);
213 static int mono_spillvar_offset (MonoCompile *, int);
214 static int mono_spillvar_offset_float (MonoCompile *, int);
215 static void print_ins (int, MonoInst *);
216 static void print_regtrack (RegTrack *, int);
217 static InstList * inst_list_prepend (MonoMemPool *, InstList *, MonoInst *);
218 static int get_register_force_spilling (MonoCompile *, InstList *, MonoInst *, int);
219 static int get_register_spilling (MonoCompile *, InstList *, MonoInst *, guint32, int);
220 static int get_float_register_spilling (MonoCompile *, InstList *, MonoInst *, guint32, int);
221 static MonoInst * create_copy_ins (MonoCompile *, int, int, MonoInst *);
222 static MonoInst * create_copy_ins_float (MonoCompile *, int, int, MonoInst *);
223 static MonoInst * create_spilled_store (MonoCompile *, int, int, int, MonoInst *);
224 static MonoInst * create_spilled_store_float (MonoCompile *, int, int, int, MonoInst *);
225 static void insert_before_ins (MonoInst *, InstList *, MonoInst *);
226 static int alloc_int_reg (MonoCompile *, InstList *, MonoInst *, int, guint32);
227 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
228 static unsigned char * mono_emit_stack_alloc (guchar *, MonoInst *);
230 /*========================= End of Prototypes ======================*/
232 /*------------------------------------------------------------------*/
233 /* G l o b a l V a r i a b l e s */
234 /*------------------------------------------------------------------*/
236 int mono_exc_esp_offset = 0;
238 static int indent_level = 0;
240 static const char*const * ins_spec = s390;
242 /*====================== End of Global Variables ===================*/
244 /*------------------------------------------------------------------*/
246 /* Name - mono_arch_regname */
248 /* Function - Returns the name of the register specified by */
249 /* the input parameter. */
251 /*------------------------------------------------------------------*/
254 mono_arch_regname (int reg) {
255 static const char * rnames[] = {
256 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
257 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
258 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
261 if (reg >= 0 && reg < 16)
266 /*========================= End of Function ========================*/
268 /*------------------------------------------------------------------*/
270 /* Name - emit_memcpy */
272 /* Function - Emit code to move from memory-to-memory based on */
273 /* the size of the variable. r0 is overwritten. */
275 /*------------------------------------------------------------------*/
278 emit_memcpy (guint8 *code, int size, int dreg, int doffset, int sreg, int soffset)
282 s390_l (code, s390_r0, 0, sreg, soffset);
283 s390_st (code, s390_r0, 0, dreg, doffset);
287 s390_icm (code, s390_r0, 14, sreg, soffset);
288 s390_stcm (code, s390_r0, 14, dreg, doffset);
292 s390_lh (code, s390_r0, 0, sreg, soffset);
293 s390_sth (code, s390_r0, 0, dreg, doffset);
297 s390_ic (code, s390_r0, 0, sreg, soffset);
298 s390_stc (code, s390_r0, 0, dreg, doffset);
309 s390_mvc (code, len, dreg, doffset, sreg, soffset);
316 /*========================= End of Function ========================*/
318 /*------------------------------------------------------------------*/
320 /* Name - arch_get_argument_info */
322 /* Function - Gathers information on parameters such as size, */
323 /* alignment, and padding. arg_info should be large */
324 /* enough to hold param_count + 1 entries. */
326 /* Parameters - @csig - Method signature */
327 /* @param_count - No. of parameters to consider */
328 /* @arg_info - An array to store the result info */
330 /* Returns - Size of the activation frame */
332 /*------------------------------------------------------------------*/
335 mono_arch_get_argument_info (MonoMethodSignature *csig,
337 MonoJitArgumentInfo *arg_info)
339 int k, frame_size = 0;
340 int size, align, pad;
343 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
344 frame_size += sizeof (gpointer);
348 arg_info [0].offset = offset;
351 frame_size += sizeof (gpointer);
355 arg_info [0].size = frame_size;
357 for (k = 0; k < param_count; k++) {
360 size = mono_type_native_stack_size (csig->params [k], &align);
362 size = mono_type_stack_size (csig->params [k], &align);
364 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
365 arg_info [k].pad = pad;
367 arg_info [k + 1].pad = 0;
368 arg_info [k + 1].size = size;
370 arg_info [k + 1].offset = offset;
374 align = MONO_ARCH_FRAME_ALIGNMENT;
375 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
376 arg_info [k].pad = pad;
381 /*========================= End of Function ========================*/
383 /*------------------------------------------------------------------*/
387 /* Function - Perform nice indenting to current level */
389 /*------------------------------------------------------------------*/
395 indent_level += diff;
402 indent_level += diff;
405 /*========================= End of Function ========================*/
407 /*------------------------------------------------------------------*/
409 /* Name - decodeParm */
411 /* Function - Decode a parameter for the trace. */
413 /*------------------------------------------------------------------*/
416 decodeParm(MonoType *type, void *curParm, int size)
421 printf("[BYREF:%p], ", *((char **) curParm));
423 simpleType = type->type;
425 switch (simpleType) {
427 printf ("[INTPTR:%p], ", *((int **) curParm));
430 printf ("[UINTPTR:%p], ", *((int **) curParm));
432 case MONO_TYPE_BOOLEAN :
433 printf ("[BOOL:%p], ", *((int *) curParm));
435 case MONO_TYPE_CHAR :
436 printf ("[CHAR:%p], ", *((int *) curParm));
439 printf ("[INT1:%d], ", *((int *) curParm+3));
442 printf ("[INT2:%d], ", *((int *) curParm+2));
445 printf ("[INT4:%d], ", *((int *) curParm));
448 printf ("[UINT1:%ud], ", *((unsigned int *) curParm));
451 printf ("[UINT2:%ud], ", *((unsigned int *) curParm));
454 printf ("[UINT4:%ud], ", *((unsigned int *) curParm));
456 case MONO_TYPE_STRING : {
457 MonoString *s = *((MonoString **) curParm);
459 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
460 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
462 printf("[STRING:null], ");
466 case MONO_TYPE_CLASS :
467 case MONO_TYPE_OBJECT : {
468 MonoObject *obj = *((MonoObject **) curParm);
471 printf("[CLASS/OBJ:");
472 class = obj->vtable->klass;
473 if (class == mono_defaults.string_class) {
474 printf("[STRING:%p:%s]",
475 *obj, mono_string_to_utf8 (obj));
476 } else if (class == mono_defaults.int32_class) {
477 printf("[INT32:%p:%d]",
478 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
481 class->name_space, class->name, obj);
484 printf("[OBJECT:null], ");
489 printf("[PTR:%p], ", *((gpointer **) (curParm)));
491 case MONO_TYPE_FNPTR :
492 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
494 case MONO_TYPE_ARRAY :
495 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
497 case MONO_TYPE_SZARRAY :
498 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
501 printf("[INT8:%lld], ", *((gint64 *) (curParm)));
504 printf("[FLOAT4:%f], ", *((float *) (curParm)));
507 printf("[FLOAT8:%g], ", *((double *) (curParm)));
509 case MONO_TYPE_VALUETYPE : {
511 if (type->data.klass->enumtype) {
512 simpleType = type->data.klass->enum_basetype->type;
513 printf("{VALUETYPE} - ");
516 printf("[VALUETYPE:");
517 for (i = 0; i < size; i++)
518 printf("%02x,", *((guint8 *)curParm+i));
523 printf("[?? - %d], ",simpleType);
528 /*========================= End of Function ========================*/
530 /*------------------------------------------------------------------*/
532 /* Name - enter_method */
534 /* Function - Perform tracing of the entry to the current */
537 /*------------------------------------------------------------------*/
540 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
545 MonoJitArgumentInfo *arg_info;
546 MonoMethodSignature *sig;
552 fname = mono_method_full_name (method, TRUE);
554 printf ("ENTER: %s(", fname);
557 printf (") ip: %p\n", __builtin_return_address (1));
562 sig = method->signature;
564 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
566 if (cinfo->struct_ret) {
567 printf ("[VALUERET:%p], ", rParm->gr[0]);
572 gpointer *this = (gpointer *) rParm->gr[oParm];
573 obj = (MonoObject *) this;
574 if (method->klass->valuetype) {
576 printf("this:[value:%p:%08x], ",
577 this, *((guint32 *)(this+sizeof(MonoObject))));
579 printf ("this:[NULL], ");
582 class = obj->vtable->klass;
583 if (class == mono_defaults.string_class) {
584 printf ("this:[STRING:%p:%s], ",
585 obj, mono_string_to_utf8 ((MonoString *)obj));
587 printf ("this:%p[%s.%s], ",
588 obj, class->name_space, class->name);
591 printf ("this:NULL, ");
596 for (i = 0; i < sig->param_count; ++i) {
597 ainfo = cinfo->args + i + oParm;
598 switch (ainfo->regtype) {
599 case RegTypeGeneral :
600 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
603 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
606 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
608 case RegTypeStructByVal :
609 if (ainfo->reg != STK_BASE)
610 decodeParm(sig->params[i],
611 &(rParm->gr[ainfo->reg-2]),
614 switch (ainfo->vtsize) {
620 decodeParm(sig->params[i],
625 decodeParm(sig->params[i],
626 *((char **) (sp+ainfo->offset)),
638 /*========================= End of Function ========================*/
640 /*------------------------------------------------------------------*/
642 /* Name - leave_method */
646 /*------------------------------------------------------------------*/
649 leave_method (MonoMethod *method, ...)
655 va_start(ap, method);
657 fname = mono_method_full_name (method, TRUE);
659 printf ("LEAVE: %s", fname);
662 type = method->signature->ret;
665 switch (type->type) {
668 case MONO_TYPE_BOOLEAN: {
669 int val = va_arg (ap, int);
671 printf ("[TRUE:%d]", val);
677 case MONO_TYPE_CHAR: {
678 int val = va_arg (ap, int);
679 printf ("[CHAR:%d]", val);
683 int val = va_arg (ap, int);
684 printf ("[INT1:%d]", val);
688 int val = va_arg (ap, int);
689 printf ("[UINT1:%d]", val);
693 int val = va_arg (ap, int);
694 printf ("[INT2:%d]", val);
698 int val = va_arg (ap, int);
699 printf ("[UINT2:%d]", val);
703 int val = va_arg (ap, int);
704 printf ("[INT4:%d]", val);
708 int val = va_arg (ap, int);
709 printf ("[UINT4:%d]", val);
713 int *val = va_arg (ap, int*);
714 printf ("[INT:%p]", val);
719 int *val = va_arg (ap, int*);
720 printf ("[UINT:%p]", val);
724 case MONO_TYPE_STRING: {
725 MonoString *s = va_arg (ap, MonoString *);
728 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
729 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
731 printf ("[STRING:null], ");
734 case MONO_TYPE_CLASS:
735 case MONO_TYPE_OBJECT: {
736 MonoObject *o = va_arg (ap, MonoObject *);
739 if (o->vtable->klass == mono_defaults.boolean_class) {
740 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
741 } else if (o->vtable->klass == mono_defaults.int32_class) {
742 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
743 } else if (o->vtable->klass == mono_defaults.int64_class) {
744 printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
746 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
748 printf ("[OBJECT:%p]", o);
753 case MONO_TYPE_FNPTR:
754 case MONO_TYPE_ARRAY:
755 case MONO_TYPE_SZARRAY: {
756 gpointer p = va_arg (ap, gpointer);
757 printf ("[result=%p]", p);
761 gint64 l = va_arg (ap, gint64);
762 printf ("[LONG:%lld]", l);
766 double f = va_arg (ap, double);
767 printf ("[FP:%g]\n", f);
770 case MONO_TYPE_VALUETYPE:
771 if (type->data.klass->enumtype) {
772 type = type->data.klass->enum_basetype;
775 guint8 *p = va_arg (ap, gpointer);
777 size = mono_type_size (type, &align);
779 for (j = 0; p && j < size; j++)
780 printf ("%02x,", p [j]);
785 printf ("(unknown return type %x)", method->signature->ret->type);
788 printf (" ip: %p\n", __builtin_return_address (0));
791 /*========================= End of Function ========================*/
793 /*------------------------------------------------------------------*/
795 /* Name - mono_arch_cpu_init */
797 /* Function - Perform CPU specific initialization to execute */
800 /*------------------------------------------------------------------*/
803 mono_arch_cpu_init (void)
807 /*========================= End of Function ========================*/
809 /*------------------------------------------------------------------*/
811 /* Name - mono_arch_cpu_optimizazions */
813 /* Function - Returns the optimizations supported on this CPU */
815 /*------------------------------------------------------------------*/
818 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
822 /* no s390-specific optimizations yet */
823 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
827 /*========================= End of Function ========================*/
829 /*------------------------------------------------------------------*/
835 /*------------------------------------------------------------------*/
838 is_regsize_var (MonoType *t) {
847 case MONO_TYPE_OBJECT:
848 case MONO_TYPE_STRING:
849 case MONO_TYPE_CLASS:
850 case MONO_TYPE_SZARRAY:
851 case MONO_TYPE_ARRAY:
853 case MONO_TYPE_VALUETYPE:
854 if (t->data.klass->enumtype)
855 return is_regsize_var (t->data.klass->enum_basetype);
861 /*========================= End of Function ========================*/
863 /*------------------------------------------------------------------*/
865 /* Name - mono_arch_get_allocatable_int_vars */
869 /*------------------------------------------------------------------*/
872 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
877 for (i = 0; i < cfg->num_varinfo; i++) {
878 MonoInst *ins = cfg->varinfo [i];
879 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
882 if (vmv->range.first_use.abs_pos > vmv->range.last_use.abs_pos)
885 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) || (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
888 /* we can only allocate 32 bit values */
889 if (is_regsize_var (ins->inst_vtype)) {
890 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
891 g_assert (i == vmv->idx);
892 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
899 /*========================= End of Function ========================*/
901 /*------------------------------------------------------------------*/
903 /* Name - mono_arch_global_int_regs */
905 /* Function - Return a list of usable integer registers. */
907 /*------------------------------------------------------------------*/
910 mono_arch_get_global_int_regs (MonoCompile *cfg)
915 for (i = 3; i < top; ++i)
916 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
921 /*========================= End of Function ========================*/
923 /*------------------------------------------------------------------*/
925 /* Name - mono_arch_flush_icache */
927 /* Function - Flush the CPU icache. */
929 /*------------------------------------------------------------------*/
932 mono_arch_flush_icache (guint8 *code, gint size)
936 /*========================= End of Function ========================*/
938 /*------------------------------------------------------------------*/
940 /* Name - add_general */
942 /* Function - Determine code and stack size incremements for a */
945 /*------------------------------------------------------------------*/
948 add_general (guint *gr, size_data *sz, ArgInfo *ainfo, gboolean simple)
951 if (*gr > S390_LAST_ARG_REG) {
952 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
953 ainfo->offset = sz->stack_size;
954 ainfo->reg = STK_BASE;
955 ainfo->regtype = RegTypeBase;
956 sz->stack_size += sizeof(int);
963 if (*gr > S390_LAST_ARG_REG - 1) {
964 sz->stack_size = S390_ALIGN(sz->stack_size, S390_STACK_ALIGNMENT);
965 ainfo->offset = sz->stack_size;
966 ainfo->reg = STK_BASE;
967 ainfo->regtype = RegTypeBase;
968 sz->stack_size += sizeof(long long);
979 /*========================= End of Function ========================*/
981 /*------------------------------------------------------------------*/
983 /* Name - calculate_sizes */
985 /* Function - Determine the amount of space required for code */
986 /* and stack. In addition determine starting points */
987 /* for stack-based parameters, and area for struct- */
988 /* ures being returned on the stack. */
990 /*------------------------------------------------------------------*/
993 calculate_sizes (MonoMethodSignature *sig, size_data *sz,
994 gboolean string_ctor)
996 guint i, fr, gr, size, nWords;
997 int nParm = sig->hasthis + sig->param_count;
998 guint32 simpletype, align;
999 CallInfo *cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1003 cinfo->struct_ret = 0;
1005 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1007 sz->local_size = S390_MINIMAL_STACK_SIZE;
1010 /*----------------------------------------------------------*/
1011 /* We determine the size of the return code/stack in case we*/
1012 /* need to reserve a register to be used to address a stack */
1013 /* area that the callee will use. */
1014 /*----------------------------------------------------------*/
1016 if (sig->ret->byref || string_ctor) {
1019 simpletype = sig->ret->type;
1021 switch (simpletype) {
1022 case MONO_TYPE_BOOLEAN:
1027 case MONO_TYPE_CHAR:
1032 case MONO_TYPE_CLASS:
1033 case MONO_TYPE_OBJECT:
1034 case MONO_TYPE_SZARRAY:
1035 case MONO_TYPE_ARRAY:
1037 case MONO_TYPE_STRING:
1038 cinfo->ret.reg = s390_r2;
1043 cinfo->ret.reg = s390_f0;
1048 cinfo->ret.reg = s390_r2;
1051 case MONO_TYPE_VALUETYPE:
1052 if (sig->ret->data.klass->enumtype) {
1053 simpletype = sig->ret->data.klass->enum_basetype->type;
1057 size = mono_class_native_size (sig->ret->data.klass, &align);
1059 size = mono_class_value_size (sig->ret->data.klass, &align);
1060 cinfo->ret.reg = s390_r2;
1061 cinfo->struct_ret = 1;
1062 cinfo->ret.size = size;
1063 cinfo->ret.vtsize = size;
1064 cinfo->ret.offset = sz->stack_size;
1065 sz->stack_size += S390_ALIGN(size, align);
1068 case MONO_TYPE_VOID:
1071 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1076 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1077 cinfo->args[nParm].size = sizeof(gpointer);
1081 /*----------------------------------------------------------*/
1082 /* We determine the size of the parameter code and stack */
1083 /* requirements by checking the types and sizes of the */
1085 /*----------------------------------------------------------*/
1087 for (i = 0; i < sig->param_count; ++i) {
1088 if (sig->params [i]->byref) {
1089 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1090 cinfo->args[nParm].size = sizeof(gpointer);
1094 simpletype = sig->params [i]->type;
1096 switch (simpletype) {
1097 case MONO_TYPE_BOOLEAN:
1100 cinfo->args[nParm].size = sizeof(char);
1101 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1106 case MONO_TYPE_CHAR:
1107 cinfo->args[nParm].size = sizeof(short);
1108 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1113 cinfo->args[nParm].size = sizeof(int);
1114 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1120 case MONO_TYPE_CLASS:
1121 case MONO_TYPE_OBJECT:
1122 case MONO_TYPE_STRING:
1123 case MONO_TYPE_SZARRAY:
1124 case MONO_TYPE_ARRAY:
1125 cinfo->args[nParm].size = sizeof(gpointer);
1126 add_general (&gr, sz, cinfo->args+nParm, TRUE);
1129 case MONO_TYPE_VALUETYPE:
1130 if (sig->params [i]->data.klass->enumtype) {
1131 simpletype = sig->params [i]->data.klass->enum_basetype->type;
1132 goto enum_calc_size;
1135 size = mono_class_native_size (sig->params [i]->data.klass, &align);
1137 size = mono_class_value_size (sig->params [i]->data.klass, &align);
1138 nWords = (size + sizeof(gpointer) - 1) /
1141 cinfo->args[nParm].vtsize = 0;
1142 cinfo->args[nParm].size = 0;
1143 cinfo->args[nParm].offparm = sz->local_size;
1146 /*----------------------------------*/
1147 /* On S/390, structures of size 1, */
1148 /* 2, 4, and 8 bytes are passed in */
1149 /* (a) register(s). */
1150 /*----------------------------------*/
1155 add_general(&gr, sz, cinfo->args+nParm, TRUE);
1156 cinfo->args[nParm].size = sizeof(int);
1157 cinfo->args[nParm].regtype = RegTypeStructByVal;
1161 add_general(&gr, sz, cinfo->args+nParm, FALSE);
1162 cinfo->args[nParm].size = sizeof(long long);
1163 cinfo->args[nParm].regtype = RegTypeStructByVal;
1167 add_general(&gr, sz, cinfo->args+nParm, TRUE);
1168 cinfo->args[nParm].size = sizeof(int);
1169 cinfo->args[nParm].regtype = RegTypeStructByVal;
1170 cinfo->args[nParm].vtsize = size;
1171 sz->code_size += 40;
1174 sz->local_size += sizeof(long);
1178 cinfo->args[nParm].size = sizeof(long long);
1179 add_general (&gr, sz, cinfo->args+nParm, FALSE);
1183 cinfo->args[nParm].size = sizeof(float);
1184 if (fr <= S390_LAST_FPARG_REG) {
1185 cinfo->args[nParm].regtype = RegTypeFP;
1186 cinfo->args[nParm].reg = fr;
1191 cinfo->args[nParm].offset = sz->stack_size;
1192 cinfo->args[nParm].reg = STK_BASE;
1193 cinfo->args[nParm].regtype = RegTypeBase;
1195 sz->stack_size += 8;
1200 cinfo->args[nParm].size = sizeof(double);
1201 if (fr <= S390_LAST_FPARG_REG) {
1202 cinfo->args[nParm].regtype = RegTypeFP;
1203 cinfo->args[nParm].reg = fr;
1207 sz->stack_size = S390_ALIGN(sz->stack_size,
1208 S390_STACK_ALIGNMENT);
1209 cinfo->args[nParm].offset = sz->stack_size;
1210 cinfo->args[nParm].reg = STK_BASE;
1211 cinfo->args[nParm].regtype = RegTypeBase;
1213 sz->stack_size += 8;
1218 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1223 /* align stack size */
1224 sz->stack_size = S390_ALIGN(sz->stack_size, S390_STACK_ALIGNMENT);
1225 cinfo->stack_usage = sz->stack_size;
1229 /*========================= End of Function ========================*/
1231 /*------------------------------------------------------------------*/
1233 /* Name - mono_arch_allocate_vars */
1235 /* Function - Set var information according to the calling */
1236 /* convention for S/390. The local var stuff should */
1237 /* most likely be split in another method. */
1239 /* Parameter - @m - Compile unit. */
1241 /*------------------------------------------------------------------*/
1244 mono_arch_allocate_vars (MonoCompile *m)
1246 MonoMethodSignature *sig;
1247 MonoMethodHeader *header;
1251 int iParm, iVar, offset, size, align, curinst, stackOffset;
1252 int frame_reg = STK_BASE;
1256 * FIXME: we'll use the frame register also for any method that has
1257 * filter clauses. This way, when the handlers are called,
1258 * the code will reference local variables using the frame reg instead of
1259 * the stack pointer: if we had to restore the stack pointer, we'd
1260 * corrupt the method frames that are already on the stack (since
1261 * filters get called before stack unwinding happens) when the filter
1262 * code would call any method.
1264 if (m->flags & MONO_CFG_HAS_ALLOCA)
1265 frame_reg = s390_r11;
1266 m->frame_reg = frame_reg;
1268 header = ((MonoMethodNormal *)m->method)->header;
1270 sig = m->method->signature;
1272 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1274 if (mono_jit_trace_calls != NULL && mono_trace_eval (m))
1275 stackOffset = S390_ALIGN((S390_TRACE_STACK_SIZE + 8),
1276 S390_STACK_ALIGNMENT);
1280 if (cinfo->struct_ret) {
1281 m->ret->opcode = OP_REGVAR;
1282 m->ret->inst_c0 = s390_r2;
1284 /* FIXME: handle long and FP values */
1285 switch (sig->ret->type) {
1286 case MONO_TYPE_VOID:
1289 m->ret->opcode = OP_REGVAR;
1290 m->ret->dreg = s390_r2;
1294 /* local vars are at a positive offset from the stack pointer
1296 * also note that if the function uses alloca, we use s390_r11
1297 * to point at the local variables.
1299 offset = S390_MINIMAL_STACK_SIZE; /* linkage area */
1301 /* add parameter area size for called functions */
1302 offset += m->param_area;
1303 offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1305 /* FIXME: check how to handle this stuff... reserve space to save LMF and caller saved registers */
1306 if (m->method->save_lmf)
1307 offset += sizeof (MonoLMF);
1309 if (cinfo->struct_ret) {
1311 offset = S390_ALIGN(offset, sizeof(gpointer));
1312 inst->inst_offset = offset;
1313 inst->opcode = OP_REGOFFSET;
1314 inst->inst_basereg = frame_reg;
1315 offset += sizeof(gpointer);
1318 curinst = m->locals_start;
1319 for (iVar = curinst; iVar < m->num_varinfo; ++iVar) {
1320 inst = m->varinfo [iVar];
1321 if (inst->opcode == OP_REGVAR)
1324 /* inst->unused indicates native sized value types, this is used by the
1325 * pinvoke wrappers when they call functions returning structure */
1326 if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1327 size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
1329 size = mono_type_size (inst->inst_vtype, &align);
1331 offset = S390_ALIGN(offset, align);
1332 inst->inst_offset = offset;
1333 inst->opcode = OP_REGOFFSET;
1334 inst->inst_basereg = frame_reg;
1336 //g_print ("allocating local %d to %d\n", i, inst->inst_offset);
1341 inst = m->varinfo [curinst];
1342 if (inst->opcode != OP_REGVAR) {
1343 inst->opcode = OP_REGOFFSET;
1344 inst->inst_basereg = frame_reg;
1345 offset = S390_ALIGN(offset, sizeof(gpointer));
1346 inst->inst_offset = offset;
1347 offset += sizeof (gpointer);
1354 eArg = sig->param_count + sArg;
1356 for (iParm = sArg; iParm < eArg; ++iParm) {
1357 inst = m->varinfo [curinst];
1358 if (inst->opcode != OP_REGVAR) {
1359 if (cinfo->args[iParm].regtype == RegTypeStructByVal) {
1360 if (cinfo->args[iParm].vtsize != 0) {
1361 inst->opcode = OP_S390_LOADARG;
1362 inst->inst_basereg = frame_reg;
1363 size = sizeof(long);
1364 offset = S390_ALIGN(offset, size);
1365 inst->inst_offset = offset;
1367 inst->opcode = OP_S390_ARGPTR;
1368 inst->inst_basereg = frame_reg;
1369 size = cinfo->args[iParm].size;
1370 offset = S390_ALIGN(offset, size);
1371 inst->inst_offset = offset;
1374 if (cinfo->args[iParm].reg != STK_BASE) {
1375 inst->opcode = OP_REGOFFSET;
1376 inst->inst_basereg = frame_reg;
1377 size = (cinfo->args[iParm].size < 8
1379 : sizeof(long long));
1380 offset = S390_ALIGN(offset, size);
1381 inst->inst_offset = offset;
1383 inst->opcode = OP_S390_STKARG;
1384 inst->inst_basereg = frame_reg;
1385 size = (cinfo->args[iParm].size < 4
1386 ? 4 - cinfo->args[iParm].size
1388 inst->inst_offset = cinfo->args[iParm].offset +
1390 inst->unused = stackOffset;
1391 size = sizeof(long);
1399 /* align the offset */
1400 offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1401 m->stack_offset = offset;
1405 /*========================= End of Function ========================*/
1407 /*------------------------------------------------------------------*/
1409 /* Name - mono_arch_call_opcode */
1411 /* Function - Take the arguments and generate the arch-specific */
1412 /* instructions to properly call the function. This */
1413 /* includes pushing, moving argments to the correct */
1416 /* Note - FIXME: We need an alignment solution for */
1417 /* enter_method and mono_arch_call_opcode, currently */
1418 /* alignment in mono_arch_call_opcode is computed */
1419 /* without arch_get_argument_info. */
1421 /*------------------------------------------------------------------*/
1424 mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
1426 MonoMethodSignature *sig;
1432 sig = call->signature;
1433 n = sig->param_count + sig->hasthis;
1435 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1436 if (cinfo->struct_ret)
1437 call->used_iregs |= 1 << cinfo->struct_ret;
1439 for (i = 0; i < n; ++i) {
1440 ainfo = cinfo->args + i;
1441 if (is_virtual && i == 0) {
1442 /* the argument will be attached to the call instrucion */
1443 in = call->args [i];
1444 call->used_iregs |= 1 << ainfo->reg;
1446 MONO_INST_NEW (cfg, arg, OP_OUTARG);
1447 in = call->args [i];
1448 arg->cil_code = in->cil_code;
1449 arg->inst_left = in;
1450 arg->type = in->type;
1451 /* prepend, we'll need to reverse them later */
1452 arg->next = call->out_args;
1453 call->out_args = arg;
1454 if (ainfo->regtype == RegTypeGeneral) {
1455 arg->unused = ainfo->reg;
1456 call->used_iregs |= 1 << ainfo->reg;
1457 if (arg->type == STACK_I8)
1458 call->used_iregs |= 1 << (ainfo->reg + 1);
1459 } else if (ainfo->regtype == RegTypeStructByAddr) {
1460 arg->unused = ainfo->reg;
1461 call->used_iregs |= 1 << ainfo->reg;
1462 } else if (ainfo->regtype == RegTypeStructByVal) {
1463 if (ainfo->reg != STK_BASE) {
1464 switch (ainfo->size) {
1469 call->used_iregs |= 1 << ainfo->reg;
1472 call->used_iregs |= 1 << ainfo->reg;
1473 call->used_iregs |= 1 << (ainfo->reg+1);
1477 arg->sreg2 = ainfo->reg;
1478 arg->opcode = OP_OUTARG_VT;
1479 if (ainfo->vtsize != 0)
1480 arg->unused = -ainfo->vtsize;
1482 arg->unused = ainfo->size;
1483 arg->inst_imm = ainfo->offset;
1484 arg->sreg1 = ainfo->offparm;
1485 } else if (ainfo->regtype == RegTypeBase) {
1486 arg->opcode = OP_OUTARG;
1487 arg->unused = ainfo->reg | (ainfo->size << 8);
1488 arg->inst_imm = ainfo->offset;
1489 } else if (ainfo->regtype == RegTypeFP) {
1490 arg->opcode = OP_OUTARG_R8;
1491 arg->unused = ainfo->reg;
1492 call->used_fregs |= 1 << ainfo->reg;
1493 if (ainfo->size == 4) {
1494 /* we reduce the precision */
1496 MONO_INST_NEW (cfg, conv, OP_FCONV_TO_R4);
1497 conv->inst_left = arg->inst_left;
1498 arg->inst_left = conv;
1501 g_assert_not_reached ();
1506 * Reverse the call->out_args list.
1509 MonoInst *prev = NULL, *list = call->out_args, *next;
1516 call->out_args = prev;
1518 call->stack_usage = cinfo->stack_usage;
1520 cfg->param_area = MAX (cfg->param_area, cinfo->stack_usage);
1521 cfg->flags |= MONO_CFG_HAS_CALLS;
1522 /*----------------------------------------------------------*/
1523 /* should set more info in call, such as the stack space */
1524 /* used by the args that needs to be added back to esp */
1525 /*----------------------------------------------------------*/
1531 /*========================= End of Function ========================*/
1533 /*------------------------------------------------------------------*/
1535 /* Name - mono_arch_instrument_mem_needs */
1537 /* Function - Allow tracing to work with this interface (with */
1538 /* an optional argument). */
1540 /*------------------------------------------------------------------*/
1543 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
1545 /* no stack room needed now (may be needed for FASTCALL-trace support) */
1547 /* split prolog-epilog requirements? */
1548 *code = 50; /* max bytes needed: check this number */
1551 /*========================= End of Function ========================*/
1553 /*------------------------------------------------------------------*/
1555 /* Name - mono_arch_instrument_prolog */
1557 /* Function - Create an "instrumented" prolog. */
1559 /*------------------------------------------------------------------*/
1562 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
1563 gboolean enable_arguments)
1566 int parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
1567 int fpOffset = parmOffset + (5*sizeof(gint32));
1569 s390_stm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1570 s390_std (code, s390_f0, 0, STK_BASE, fpOffset);
1571 s390_std (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1572 s390_std (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1573 s390_basr (code, s390_r13, 0);
1575 s390_word (code, cfg->method);
1576 s390_word (code, func);
1577 s390_l (code, s390_r2, 0, s390_r13, 4);
1578 s390_la (code, s390_r3, 0, STK_BASE, parmOffset);
1579 s390_lr (code, s390_r4, STK_BASE);
1580 s390_ahi (code, s390_r4, cfg->stack_usage);
1581 s390_l (code, s390_r1, 0, s390_r13, 8);
1582 s390_basr (code, s390_r14, s390_r1);
1583 s390_ld (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1584 s390_ld (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1585 s390_ld (code, s390_f0, 0, STK_BASE, fpOffset);
1586 s390_lm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1591 /*========================= End of Function ========================*/
1593 /*------------------------------------------------------------------*/
1595 /* Name - mono_arch_instrument_epilog */
1597 /* Function - Create an epilog that will handle the returned */
1598 /* values used in instrumentation. */
1600 /*------------------------------------------------------------------*/
1603 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
1606 int save_mode = SAVE_NONE;
1607 MonoMethod *method = cfg->method;
1608 int rtype = method->signature->ret->type;
1612 case MONO_TYPE_VOID:
1613 /* special case string .ctor icall */
1614 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
1615 save_mode = SAVE_ONE;
1617 save_mode = SAVE_NONE;
1621 save_mode = SAVE_TWO;
1625 save_mode = SAVE_FP;
1627 case MONO_TYPE_VALUETYPE:
1628 if (method->signature->ret->data.klass->enumtype) {
1629 rtype = method->signature->ret->data.klass->enum_basetype->type;
1632 save_mode = SAVE_STRUCT;
1635 save_mode = SAVE_ONE;
1639 switch (save_mode) {
1641 s390_stm (code, s390_r2, s390_r3, cfg->frame_reg, cfg->stack_usage - 8);
1642 if (enable_arguments) {
1643 s390_lr (code, s390_r4, s390_r3);
1644 s390_lr (code, s390_r3, s390_r2);
1648 s390_st (code, s390_r2, 0, cfg->frame_reg, cfg->stack_usage - 4);
1649 if (enable_arguments) {
1650 s390_lr (code, s390_r3, s390_r2);
1654 s390_std (code, s390_f0, 0, cfg->frame_reg, cfg->stack_usage - 8);
1655 if (enable_arguments) {
1656 /* FIXME: what reg? */
1657 s390_ldr (code, s390_f2, s390_f0);
1658 s390_lm (code, s390_r3, s390_r4, cfg->frame_reg, cfg->stack_usage - 8);
1662 s390_st (code, s390_r2, 0, cfg->frame_reg, cfg->stack_usage - 4);
1663 if (enable_arguments) {
1664 s390_l (code, s390_r3, 0, cfg->frame_reg,
1665 S390_MINIMAL_STACK_SIZE+cfg->param_area);
1673 s390_basr (code, s390_r13, 0);
1675 s390_word (code, cfg->method);
1676 s390_word (code, func);
1677 s390_l (code, s390_r2, 0, s390_r13, 4);
1678 s390_l (code, s390_r1, 0, s390_r13, 8);
1679 s390_basr (code, s390_r14, s390_r1);
1681 switch (save_mode) {
1683 s390_lm (code, s390_r2, s390_r3, cfg->frame_reg, cfg->stack_usage - 8);
1686 s390_l (code, s390_r2, 0, cfg->frame_reg, cfg->stack_usage - 4);
1689 s390_ld (code, s390_f0, 0, cfg->frame_reg, cfg->stack_usage - 8);
1692 s390_l (code, s390_r2, 0, cfg->frame_reg, cfg->stack_usage - 4);
1702 /*========================= End of Function ========================*/
1704 /*------------------------------------------------------------------*/
1706 /* Name - peephole_pass */
1708 /* Function - Form a peephole pass at the code looking for */
1709 /* simple optimizations. */
1711 /*------------------------------------------------------------------*/
1714 peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
1716 MonoInst *ins, *last_ins = NULL;
1721 switch (ins->opcode) {
1723 /* remove unnecessary multiplication with 1 */
1724 if (ins->inst_imm == 1) {
1725 if (ins->dreg != ins->sreg1) {
1726 ins->opcode = OP_MOVE;
1728 last_ins->next = ins->next;
1734 case OP_LOAD_MEMBASE:
1735 case OP_LOADI4_MEMBASE:
1737 * OP_STORE_MEMBASE_REG reg, offset(basereg)
1738 * OP_LOAD_MEMBASE offset(basereg), reg
1740 if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG
1741 || last_ins->opcode == OP_STORE_MEMBASE_REG) &&
1742 ins->inst_basereg == last_ins->inst_destbasereg &&
1743 ins->inst_offset == last_ins->inst_offset) {
1744 if (ins->dreg == last_ins->sreg1) {
1745 last_ins->next = ins->next;
1749 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1750 ins->opcode = OP_MOVE;
1751 ins->sreg1 = last_ins->sreg1;
1755 * Note: reg1 must be different from the basereg in the second load
1756 * OP_LOAD_MEMBASE offset(basereg), reg1
1757 * OP_LOAD_MEMBASE offset(basereg), reg2
1759 * OP_LOAD_MEMBASE offset(basereg), reg1
1760 * OP_MOVE reg1, reg2
1762 } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
1763 || last_ins->opcode == OP_LOAD_MEMBASE) &&
1764 ins->inst_basereg != last_ins->dreg &&
1765 ins->inst_basereg == last_ins->inst_basereg &&
1766 ins->inst_offset == last_ins->inst_offset) {
1768 if (ins->dreg == last_ins->dreg) {
1769 last_ins->next = ins->next;
1773 ins->opcode = OP_MOVE;
1774 ins->sreg1 = last_ins->dreg;
1777 //g_assert_not_reached ();
1781 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1782 * OP_LOAD_MEMBASE offset(basereg), reg
1784 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1785 * OP_ICONST reg, imm
1787 } else if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_IMM
1788 || last_ins->opcode == OP_STORE_MEMBASE_IMM) &&
1789 ins->inst_basereg == last_ins->inst_destbasereg &&
1790 ins->inst_offset == last_ins->inst_offset) {
1791 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1792 ins->opcode = OP_ICONST;
1793 ins->inst_c0 = last_ins->inst_imm;
1794 g_assert_not_reached (); // check this rule
1798 case OP_LOADU1_MEMBASE:
1799 case OP_LOADI1_MEMBASE:
1800 if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
1801 ins->inst_basereg == last_ins->inst_destbasereg &&
1802 ins->inst_offset == last_ins->inst_offset) {
1803 if (ins->dreg == last_ins->sreg1) {
1804 last_ins->next = ins->next;
1808 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1809 ins->opcode = OP_MOVE;
1810 ins->sreg1 = last_ins->sreg1;
1814 case OP_LOADU2_MEMBASE:
1815 case OP_LOADI2_MEMBASE:
1816 if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) &&
1817 ins->inst_basereg == last_ins->inst_destbasereg &&
1818 ins->inst_offset == last_ins->inst_offset) {
1819 if (ins->dreg == last_ins->sreg1) {
1820 last_ins->next = ins->next;
1824 ins->opcode = OP_MOVE;
1825 ins->sreg1 = last_ins->sreg1;
1835 if (ins->dreg == ins->sreg1) {
1837 last_ins->next = ins->next;
1842 * OP_MOVE sreg, dreg
1843 * OP_MOVE dreg, sreg
1845 if (last_ins && last_ins->opcode == OP_MOVE &&
1846 ins->sreg1 == last_ins->dreg &&
1847 ins->dreg == last_ins->sreg1) {
1848 last_ins->next = ins->next;
1857 bb->last_ins = last_ins;
1860 /*========================= End of Function ========================*/
1862 /*------------------------------------------------------------------*/
1864 /* Name - mono_spillvar_offset */
1866 /* Function - Returns the offset used by spillvar. It allocates */
1867 /* a new spill variable if necessary. */
1869 /*------------------------------------------------------------------*/
1872 mono_spillvar_offset (MonoCompile *cfg, int spillvar)
1874 MonoSpillInfo **si, *info;
1877 si = &cfg->spill_info;
1879 while (i <= spillvar) {
1882 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1884 info->offset = cfg->stack_offset;
1885 cfg->stack_offset += sizeof (gpointer);
1889 return (*si)->offset;
1895 g_assert_not_reached ();
1899 /*========================= End of Function ========================*/
1901 /*------------------------------------------------------------------*/
1903 /* Name - mono_spillvar_offset_float */
1907 /*------------------------------------------------------------------*/
1910 mono_spillvar_offset_float (MonoCompile *cfg, int spillvar)
1912 MonoSpillInfo **si, *info;
1915 si = &cfg->spill_info_float;
1917 while (i <= spillvar) {
1920 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1922 cfg->stack_offset = S390_ALIGN(cfg->stack_offset, S390_STACK_ALIGNMENT);
1923 info->offset = cfg->stack_offset;
1924 cfg->stack_offset += sizeof (double);
1928 return (*si)->offset;
1934 g_assert_not_reached ();
1938 /*========================= End of Function ========================*/
1940 /*------------------------------------------------------------------*/
1942 /* Name - print_ins */
1944 /* Function - Decode and print the instruction for tracing. */
1946 /*------------------------------------------------------------------*/
1949 print_ins (int i, MonoInst *ins)
1951 const char *spec = ins_spec [ins->opcode];
1952 g_print ("\t%-2d %s", i, mono_inst_name (ins->opcode));
1953 if (spec [MONO_INST_DEST]) {
1954 if (ins->dreg >= MONO_MAX_IREGS)
1955 g_print (" R%d <-", ins->dreg);
1957 g_print (" %s <-", mono_arch_regname (ins->dreg));
1959 if (spec [MONO_INST_SRC1]) {
1960 if (ins->sreg1 >= MONO_MAX_IREGS)
1961 g_print (" R%d", ins->sreg1);
1963 g_print (" %s", mono_arch_regname (ins->sreg1));
1965 if (spec [MONO_INST_SRC2]) {
1966 if (ins->sreg2 >= MONO_MAX_IREGS)
1967 g_print (" R%d", ins->sreg2);
1969 g_print (" %s", mono_arch_regname (ins->sreg2));
1971 if (spec [MONO_INST_CLOB])
1972 g_print (" clobbers: %c", spec [MONO_INST_CLOB]);
1976 /*========================= End of Function ========================*/
1978 /*------------------------------------------------------------------*/
1980 /* Name - print_regtrack. */
1984 /*------------------------------------------------------------------*/
1987 print_regtrack (RegTrack *t, int num)
1993 for (i = 0; i < num; ++i) {
1996 if (i >= MONO_MAX_IREGS) {
1997 g_snprintf (buf, sizeof(buf), "R%d", i);
2000 r = mono_arch_regname (i);
2001 g_print ("liveness: %s [%d - %d]\n", r, t [i].born_in, t[i].last_use);
2005 /*========================= End of Function ========================*/
2007 /*------------------------------------------------------------------*/
2009 /* Name - inst_list_prepend */
2011 /* Function - Prepend an instruction to the list. */
2013 /*------------------------------------------------------------------*/
2015 static inline InstList*
2016 inst_list_prepend (MonoMemPool *pool, InstList *list, MonoInst *data)
2018 InstList *item = mono_mempool_alloc (pool, sizeof (InstList));
2027 /*========================= End of Function ========================*/
2029 /*------------------------------------------------------------------*/
2031 /* Name - get_register_force_spilling */
2033 /* Function - Force the spilling of the variable in the */
2034 /* symbolic register 'reg'. */
2036 /*------------------------------------------------------------------*/
2039 get_register_force_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, int reg)
2044 sel = cfg->rs->iassign [reg];
2046 spill = ++cfg->spill_count;
2047 cfg->rs->iassign [i] = -spill - 1;
2048 mono_regstate_free_int (cfg->rs, sel);
2049 /*----------------------------------------------------------*/
2050 /* we need to create a spill var and insert a load to sel */
2051 /* after the current instruction */
2052 /*----------------------------------------------------------*/
2053 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2055 load->inst_basereg = cfg->frame_reg;
2056 load->inst_offset = mono_spillvar_offset (cfg, spill);
2058 while (ins->next != item->prev->data)
2061 load->next = ins->next;
2063 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n",
2064 spill, load->inst_offset, i, mono_arch_regname (sel)));
2065 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2066 g_assert (i == sel);
2071 /*========================= End of Function ========================*/
2073 /*------------------------------------------------------------------*/
2075 /* Name - get_register_spilling */
2079 /*------------------------------------------------------------------*/
2082 get_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2087 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));
2088 /* exclude the registers in the current instruction */
2089 if (reg != ins->sreg1 &&
2090 (reg_is_freeable (ins->sreg1) ||
2091 (ins->sreg1 >= MONO_MAX_IREGS &&
2092 cfg->rs->iassign [ins->sreg1] >= 0))) {
2093 if (ins->sreg1 >= MONO_MAX_IREGS)
2094 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg1]);
2096 regmask &= ~ (1 << ins->sreg1);
2097 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2099 if (reg != ins->sreg2 &&
2100 (reg_is_freeable (ins->sreg2) ||
2101 (ins->sreg2 >= MONO_MAX_IREGS &&
2102 cfg->rs->iassign [ins->sreg2] >= 0))) {
2103 if (ins->sreg2 >= MONO_MAX_IREGS)
2104 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg2]);
2106 regmask &= ~ (1 << ins->sreg2);
2107 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2109 if (reg != ins->dreg && reg_is_freeable (ins->dreg)) {
2110 regmask &= ~ (1 << ins->dreg);
2111 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2114 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2115 g_assert (regmask); /* need at least a register we can free */
2117 /* we should track prev_use and spill the register that's farther */
2118 for (i = 0; i < MONO_MAX_IREGS; ++i) {
2119 if (regmask & (1 << i)) {
2121 DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->iassign [sel]));
2125 i = cfg->rs->isymbolic [sel];
2126 spill = ++cfg->spill_count;
2127 cfg->rs->iassign [i] = -spill - 1;
2128 mono_regstate_free_int (cfg->rs, sel);
2129 /* we need to create a spill var and insert a load to sel after the current instruction */
2130 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2132 load->inst_basereg = cfg->frame_reg;
2133 load->inst_offset = mono_spillvar_offset (cfg, spill);
2135 while (ins->next != item->prev->data)
2138 load->next = ins->next;
2140 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2141 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2142 g_assert (i == sel);
2147 /*========================= End of Function ========================*/
2149 /*------------------------------------------------------------------*/
2151 /* Name - get_float_register_spilling */
2155 /*------------------------------------------------------------------*/
2158 get_float_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2163 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));
2164 /* exclude the registers in the current instruction */
2165 if (reg != ins->sreg1 &&
2166 (freg_is_freeable (ins->sreg1) ||
2167 (ins->sreg1 >= MONO_MAX_FREGS &&
2168 cfg->rs->fassign [ins->sreg1] >= 0))) {
2169 if (ins->sreg1 >= MONO_MAX_FREGS)
2170 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg1]);
2172 regmask &= ~ (1 << ins->sreg1);
2173 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2175 if (reg != ins->sreg2 &&
2176 (freg_is_freeable (ins->sreg2) ||
2177 (ins->sreg2 >= MONO_MAX_FREGS &&
2178 cfg->rs->fassign [ins->sreg2] >= 0))) {
2179 if (ins->sreg2 >= MONO_MAX_FREGS)
2180 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg2]);
2182 regmask &= ~ (1 << ins->sreg2);
2183 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2185 if (reg != ins->dreg && freg_is_freeable (ins->dreg)) {
2186 regmask &= ~ (1 << ins->dreg);
2187 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2190 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2191 g_assert (regmask); /* need at least a register we can free */
2193 /* we should track prev_use and spill the register that's farther */
2194 for (i = 0; i < MONO_MAX_FREGS; ++i) {
2195 if (regmask & (1 << i)) {
2197 DEBUG (g_print ("selected register %s has assignment %d\n",
2198 mono_arch_regname (sel), cfg->rs->fassign [sel]));
2202 i = cfg->rs->fsymbolic [sel];
2203 spill = ++cfg->spill_count;
2204 cfg->rs->fassign [i] = -spill - 1;
2205 mono_regstate_free_float(cfg->rs, sel);
2206 /* we need to create a spill var and insert a load to sel after the current instruction */
2207 MONO_INST_NEW (cfg, load, OP_LOADR8_MEMBASE);
2209 load->inst_basereg = cfg->frame_reg;
2210 load->inst_offset = mono_spillvar_offset_float (cfg, spill);
2212 while (ins->next != item->prev->data)
2215 load->next = ins->next;
2217 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2218 i = mono_regstate_alloc_float (cfg->rs, 1 << sel);
2219 g_assert (i == sel);
2224 /*========================= End of Function ========================*/
2226 /*------------------------------------------------------------------*/
2228 /* Name - create_copy_ins */
2230 /* Function - Create an instruction to copy from reg to reg. */
2232 /*------------------------------------------------------------------*/
2235 create_copy_ins (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2238 MONO_INST_NEW (cfg, copy, OP_MOVE);
2242 copy->next = ins->next;
2245 DEBUG (g_print ("\tforced copy from %s to %s\n",
2246 mono_arch_regname (src), mono_arch_regname (dest)));
2250 /*========================= End of Function ========================*/
2252 /*------------------------------------------------------------------*/
2254 /* Name - create_copy_ins_float */
2256 /* Function - Create an instruction to copy from float reg to */
2259 /*------------------------------------------------------------------*/
2262 create_copy_ins_float (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2265 MONO_INST_NEW (cfg, copy, OP_FMOVE);
2269 copy->next = ins->next;
2272 DEBUG (g_print ("\tforced copy from %s to %s\n",
2273 mono_arch_regname (src), mono_arch_regname (dest)));
2277 /*========================= End of Function ========================*/
2279 /*------------------------------------------------------------------*/
2281 /* Name - create_spilled_store */
2283 /* Function - Spill register to storage. */
2285 /*------------------------------------------------------------------*/
2288 create_spilled_store (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2291 MONO_INST_NEW (cfg, store, OP_STORE_MEMBASE_REG);
2293 store->inst_destbasereg = cfg->frame_reg;
2294 store->inst_offset = mono_spillvar_offset (cfg, spill);
2296 store->next = ins->next;
2299 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2300 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2304 /*========================= End of Function ========================*/
2306 /*------------------------------------------------------------------*/
2308 /* Name - create_spilled_store_float */
2310 /* Function - Spill floating point register to storage. */
2312 /*------------------------------------------------------------------*/
2315 create_spilled_store_float (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2318 MONO_INST_NEW (cfg, store, OP_STORER8_MEMBASE_REG);
2320 store->inst_destbasereg = cfg->frame_reg;
2321 store->inst_offset = mono_spillvar_offset_float (cfg, spill);
2323 store->next = ins->next;
2326 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2327 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2331 /*========================= End of Function ========================*/
2333 /*------------------------------------------------------------------*/
2335 /* Name - insert_before_ins */
2337 /* Function - Insert an instruction before another. */
2339 /*------------------------------------------------------------------*/
2342 insert_before_ins (MonoInst *ins, InstList *item, MonoInst* to_insert)
2345 g_assert (item->next);
2346 prev = item->next->data;
2348 while (prev->next != ins)
2350 to_insert->next = ins;
2351 prev->next = to_insert;
2353 * needed otherwise in the next instruction we can add an ins to the
2354 * end and that would get past this instruction.
2356 item->data = to_insert;
2359 /*========================= End of Function ========================*/
2361 /*------------------------------------------------------------------*/
2363 /* Name - alloc_int_reg */
2365 /* Function - Allocate a general register. */
2367 /*------------------------------------------------------------------*/
2370 alloc_int_reg (MonoCompile *cfg, InstList *curinst, MonoInst *ins, int sym_reg, guint32 allow_mask)
2372 int val = cfg->rs->iassign [sym_reg];
2376 /* the register gets spilled after this inst */
2379 val = mono_regstate_alloc_int (cfg->rs, allow_mask);
2381 val = get_register_spilling (cfg, curinst, ins, allow_mask, sym_reg);
2382 cfg->rs->iassign [sym_reg] = val;
2383 /* add option to store before the instruction for src registers */
2385 create_spilled_store (cfg, spill, val, sym_reg, ins);
2387 cfg->rs->isymbolic [val] = sym_reg;
2391 /*========================= End of Function ========================*/
2393 /*------------------------------------------------------------------*/
2395 /* Name - mono_arch_local_regalloc. */
2397 /* Function - We first scan the list of instructions and we */
2398 /* save the liveness information of each register */
2399 /* (when the register is first used, when its value */
2400 /* is set etc.). We also reverse the list of instr- */
2401 /* uctions (in the InstList list) because assigning */
2402 /* registers backwards allows for more tricks to be */
2405 /*------------------------------------------------------------------*/
2408 mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
2411 MonoRegState *rs = cfg->rs;
2413 RegTrack *reginfo, *reginfof;
2414 RegTrack *reginfo1, *reginfo2, *reginfod;
2415 InstList *tmp, *reversed = NULL;
2417 guint32 src1_mask, src2_mask, dest_mask;
2418 guint32 cur_iregs, cur_fregs;
2422 rs->next_vireg = bb->max_ireg;
2423 rs->next_vfreg = bb->max_freg;
2424 mono_regstate_assign (rs);
2425 reginfo = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vireg);
2426 reginfof = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vfreg);
2427 rs->ifree_mask = S390_CALLER_REGS;
2428 rs->ffree_mask = S390_CALLER_FREGS;
2432 DEBUG (g_print ("LOCAL regalloc: basic block: %d\n", bb->block_num));
2433 /* forward pass on the instructions to collect register liveness info */
2435 spec = ins_spec [ins->opcode];
2436 DEBUG (print_ins (i, ins));
2437 if (spec [MONO_INST_CLOB] == 'c') {
2438 MonoCallInst * call = (MonoCallInst*)ins;
2441 if (spec [MONO_INST_SRC1]) {
2442 if (spec [MONO_INST_SRC1] == 'f')
2443 reginfo1 = reginfof;
2446 reginfo1 [ins->sreg1].prev_use = reginfo1 [ins->sreg1].last_use;
2447 reginfo1 [ins->sreg1].last_use = i;
2451 if (spec [MONO_INST_SRC2]) {
2452 if (spec [MONO_INST_SRC2] == 'f')
2453 reginfo2 = reginfof;
2456 reginfo2 [ins->sreg2].prev_use = reginfo2 [ins->sreg2].last_use;
2457 reginfo2 [ins->sreg2].last_use = i;
2461 if (spec [MONO_INST_DEST]) {
2462 if (spec [MONO_INST_DEST] == 'f')
2463 reginfod = reginfof;
2466 if (spec [MONO_INST_DEST] != 'b') /* it's not just a base register */
2467 reginfod [ins->dreg].killed_in = i;
2468 reginfod [ins->dreg].prev_use = reginfod [ins->dreg].last_use;
2469 reginfod [ins->dreg].last_use = i;
2470 if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
2471 reginfod [ins->dreg].born_in = i;
2472 if (spec [MONO_INST_DEST] == 'l') {
2473 /* result in eax:edx, the virtual register is allocated sequentially */
2474 reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
2475 reginfod [ins->dreg + 1].last_use = i;
2476 if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
2477 reginfod [ins->dreg + 1].born_in = i;
2482 reversed = inst_list_prepend (cfg->mempool, reversed, ins);
2487 cur_iregs = S390_CALLER_REGS;
2488 cur_fregs = S390_CALLER_FREGS;
2490 DEBUG (print_regtrack (reginfo, rs->next_vireg));
2491 DEBUG (print_regtrack (reginfof, rs->next_vfreg));
2494 int prev_dreg, prev_sreg1, prev_sreg2;
2497 spec = ins_spec [ins->opcode];
2498 DEBUG (g_print ("processing:"));
2499 DEBUG (print_ins (i, ins));
2500 /* make the register available for allocation: FIXME add fp reg */
2501 if (ins->opcode == OP_SETREG || ins->opcode == OP_SETREGIMM) {
2502 cur_iregs |= 1 << ins->dreg;
2503 DEBUG (g_print ("adding %d to cur_iregs\n", ins->dreg));
2504 } else if (ins->opcode == OP_SETFREG) {
2505 cur_fregs |= 1 << ins->dreg;
2506 DEBUG (g_print ("adding %d to cur_fregs\n", ins->dreg));
2507 } else if (spec [MONO_INST_CLOB] == 'c') {
2508 MonoCallInst *cinst = (MonoCallInst*)ins;
2509 DEBUG (g_print ("excluding regs 0x%x from cur_iregs (0x%x)\n", cinst->used_iregs, cur_iregs));
2510 cur_iregs &= ~cinst->used_iregs;
2511 cur_fregs &= ~cinst->used_fregs;
2512 DEBUG (g_print ("available cur_iregs: 0x%x\n", cur_iregs));
2513 /* registers used by the calling convention are excluded from
2514 * allocation: they will be selectively enabled when they are
2515 * assigned by the special SETREG opcodes.
2518 dest_mask = src1_mask = src2_mask = cur_iregs;
2519 /* update for use with FP regs... */
2520 if (spec [MONO_INST_DEST] == 'f') {
2521 if (ins->dreg >= MONO_MAX_FREGS) {
2522 val = rs->fassign [ins->dreg];
2523 prev_dreg = ins->dreg;
2527 /* the register gets spilled after this inst */
2530 val = mono_regstate_alloc_float (rs, dest_mask);
2532 val = get_float_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2533 rs->fassign [ins->dreg] = val;
2535 create_spilled_store_float (cfg, spill, val, prev_dreg, ins);
2537 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
2538 rs->fsymbolic [val] = prev_dreg;
2540 if (spec [MONO_INST_CLOB] == 'c' && ins->dreg != s390_f0) {
2541 /* this instruction only outputs to s390_f0, need to copy */
2542 create_copy_ins_float (cfg, ins->dreg, s390_f0, ins);
2547 if (freg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i || !(cur_fregs & (1 << ins->dreg)))) {
2548 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2549 mono_regstate_free_float (rs, ins->dreg);
2551 } else if (ins->dreg >= MONO_MAX_IREGS) {
2552 val = rs->iassign [ins->dreg];
2553 prev_dreg = ins->dreg;
2557 /* the register gets spilled after this inst */
2560 val = mono_regstate_alloc_int (rs, dest_mask);
2562 val = get_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2563 rs->iassign [ins->dreg] = val;
2565 create_spilled_store (cfg, spill, val, prev_dreg, ins);
2567 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
2568 rs->isymbolic [val] = prev_dreg;
2570 if (spec [MONO_INST_DEST] == 'l') {
2571 int hreg = prev_dreg + 1;
2572 val = rs->iassign [hreg];
2576 /* the register gets spilled after this inst */
2579 val = mono_regstate_alloc_int (rs, dest_mask);
2581 val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
2582 rs->iassign [hreg] = val;
2584 create_spilled_store (cfg, spill, val, hreg, ins);
2586 DEBUG (g_print ("\tassigned hreg %s to dest R%d\n", mono_arch_regname (val), hreg));
2587 rs->isymbolic [val] = hreg;
2588 /* FIXME:? ins->dreg = val; */
2589 if (ins->dreg == s390_r3) {
2591 create_copy_ins (cfg, val, s390_r2, ins);
2592 } else if (ins->dreg == s390_r2) {
2593 if (val == s390_r3) {
2595 create_copy_ins (cfg, s390_r3, s390_r0, ins);
2596 create_copy_ins (cfg, s390_r2, s390_r3, ins);
2597 create_copy_ins (cfg, s390_r0, s390_r2, ins);
2599 /* two forced copies */
2600 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2601 create_copy_ins (cfg, val, s390_r2, ins);
2604 if (val == s390_r2) {
2605 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2607 /* two forced copies */
2608 create_copy_ins (cfg, val, s390_r2, ins);
2609 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2612 if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
2613 DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
2614 mono_regstate_free_int (rs, val);
2616 } else if (spec [MONO_INST_DEST] == 'a' && ins->dreg != s390_r2 && spec [MONO_INST_CLOB] != 'd') {
2617 /* this instruction only outputs to s390_r2, need to copy */
2618 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2623 if (spec [MONO_INST_DEST] != 'f' && reg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i)) {
2624 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2625 mono_regstate_free_int (rs, ins->dreg);
2627 if (spec [MONO_INST_SRC1] == 'f') {
2628 if (ins->sreg1 >= MONO_MAX_FREGS) {
2629 val = rs->fassign [ins->sreg1];
2630 prev_sreg1 = ins->sreg1;
2634 /* the register gets spilled after this inst */
2637 //g_assert (val == -1); /* source cannot be spilled */
2638 val = mono_regstate_alloc_float (rs, src1_mask);
2640 val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
2641 rs->fassign [ins->sreg1] = val;
2642 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2644 MonoInst *store = create_spilled_store_float (cfg, spill, val, prev_sreg1, NULL);
2645 insert_before_ins (ins, tmp, store);
2648 rs->fsymbolic [val] = prev_sreg1;
2653 } else if (ins->sreg1 >= MONO_MAX_IREGS) {
2654 val = rs->iassign [ins->sreg1];
2655 prev_sreg1 = ins->sreg1;
2659 /* the register gets spilled after this inst */
2662 if (0 && ins->opcode == OP_MOVE) {
2664 * small optimization: the dest register is already allocated
2665 * but the src one is not: we can simply assign the same register
2666 * here and peephole will get rid of the instruction later.
2667 * This optimization may interfere with the clobbering handling:
2668 * it removes a mov operation that will be added again to handle clobbering.
2669 * There are also some other issues that should with make testjit.
2671 mono_regstate_alloc_int (rs, 1 << ins->dreg);
2672 val = rs->iassign [ins->sreg1] = ins->dreg;
2673 //g_assert (val >= 0);
2674 DEBUG (g_print ("\tfast assigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2676 //g_assert (val == -1); /* source cannot be spilled */
2677 val = mono_regstate_alloc_int (rs, src1_mask);
2679 val = get_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
2680 rs->iassign [ins->sreg1] = val;
2681 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2684 MonoInst *store = create_spilled_store (cfg, spill, val, prev_sreg1, NULL);
2685 insert_before_ins (ins, tmp, store);
2688 rs->isymbolic [val] = prev_sreg1;
2693 /*----------------------------------------------*/
2694 /* handle clobbering of sreg1 */
2695 /*----------------------------------------------*/
2696 if ((spec [MONO_INST_CLOB] == '1' ||
2697 spec [MONO_INST_CLOB] == 's') &&
2698 ins->dreg != ins->sreg1) {
2699 MonoInst *copy = create_copy_ins (cfg, ins->dreg, ins->sreg1, NULL);
2700 DEBUG (g_print ("\tneed to copy sreg1 %s to dreg %s\n",
2701 mono_arch_regname (ins->sreg1),
2702 mono_arch_regname (ins->dreg)));
2703 if (ins->sreg2 == -1 || spec [MONO_INST_CLOB] == 's') {
2704 /* note: the copy is inserted before the current instruction! */
2705 insert_before_ins (ins, tmp, copy);
2706 /* we set sreg1 to dest as well */
2707 prev_sreg1 = ins->sreg1 = ins->dreg;
2709 /* inserted after the operation */
2710 copy->next = ins->next;
2715 if (spec [MONO_INST_SRC2] == 'f') {
2716 if (ins->sreg2 >= MONO_MAX_FREGS) {
2717 val = rs->fassign [ins->sreg2];
2718 prev_sreg2 = ins->sreg2;
2722 /* the register gets spilled after this inst */
2725 val = mono_regstate_alloc_float (rs, src2_mask);
2727 val = get_float_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2728 rs->fassign [ins->sreg2] = val;
2729 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2731 create_spilled_store_float (cfg, spill, val, prev_sreg2, ins);
2733 rs->fsymbolic [val] = prev_sreg2;
2738 } else if (ins->sreg2 >= MONO_MAX_IREGS) {
2739 val = rs->iassign [ins->sreg2];
2740 prev_sreg2 = ins->sreg2;
2744 /* the register gets spilled after this inst */
2747 val = mono_regstate_alloc_int (rs, src2_mask);
2749 val = get_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2750 rs->iassign [ins->sreg2] = val;
2751 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2753 create_spilled_store (cfg, spill, val, prev_sreg2, ins);
2755 rs->isymbolic [val] = prev_sreg2;
2761 if (spec [MONO_INST_CLOB] == 'c') {
2763 guint32 clob_mask = S390_CALLER_REGS;
2764 for (j = 0; j < MONO_MAX_IREGS; ++j) {
2766 if ((clob_mask & s) && !(rs->ifree_mask & s) && j != ins->sreg1) {
2767 //g_warning ("register %s busy at call site\n", mono_arch_regname (j));
2771 /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
2772 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
2773 mono_regstate_free_int (rs, ins->sreg1);
2775 if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
2776 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
2777 mono_regstate_free_int (rs, ins->sreg2);
2780 //DEBUG (print_ins (i, ins));
2785 /*========================= End of Function ========================*/
2787 /*------------------------------------------------------------------*/
2789 /* Name - emit_float_to_int */
2791 /* Function - Create instructions which will convert a floating */
2792 /* point value to integer. */
2794 /*------------------------------------------------------------------*/
2797 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2799 /* sreg is a float, dreg is an integer reg. */
2801 s390_cfdbr (code, dreg, 5, sreg);
2803 s390_basr (code, s390_r13, 0);
2805 s390_double (code, 0x41e0000000000000);
2806 s390_double (code, 0x41f0000000000000);
2807 s390_ldr (code, s390_f0, sreg);
2808 s390_cdb (code, s390_f0, 0, s390_r13, 0);
2810 s390_sdb (code, s390_f0, 0, s390_r13, 8);
2811 s390_cfdbr (code, dreg, 7, s390_f0);
2813 s390_cfdbr (code, dreg, 5, sreg);
2818 /*========================= End of Function ========================*/
2820 /*------------------------------------------------------------------*/
2822 /* Name - mono_emit_stack_alloc */
2826 /*------------------------------------------------------------------*/
2828 static unsigned char*
2829 mono_emit_stack_alloc (guchar *code, MonoInst* tree)
2834 /*========================= End of Function ========================*/
2836 /*------------------------------------------------------------------*/
2838 /* Name - mono_arch_output_basic_block */
2840 /* Function - Perform the "real" work of emitting instructions */
2841 /* that will do the work of in the basic block. */
2843 /*------------------------------------------------------------------*/
2846 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2851 guint8 *code = cfg->native_code + cfg->code_len;
2852 MonoInst *last_ins = NULL;
2853 guint last_offset = 0;
2856 if (cfg->opt & MONO_OPT_PEEPHOLE)
2857 peephole_pass (cfg, bb);
2859 /* we don't align basic blocks of loops on s390 */
2861 if (cfg->verbose_level > 2)
2862 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2864 cpos = bb->max_offset;
2866 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2867 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2868 //g_assert (!mono_compile_aot);
2871 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2872 /* this is not thread save, but good enough */
2873 /* fixme: howto handle overflows? */
2874 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2879 offset = code - cfg->native_code;
2881 max_len = ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
2883 if (offset > (cfg->code_size - max_len - 16)) {
2884 cfg->code_size *= 2;
2885 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2886 code = cfg->native_code + offset;
2889 switch (ins->opcode) {
2890 case OP_STOREI1_MEMBASE_IMM:
2891 s390_lhi (code, s390_r14, ins->inst_imm);
2892 if (s390_is_uimm12(ins->inst_offset))
2893 s390_stc (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2895 s390_basr (code, s390_r13, 0);
2897 s390_word (code, ins->inst_offset);
2898 s390_l (code, s390_r13, 0, s390_r13, 4);
2899 s390_stc (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2902 case OP_STOREI2_MEMBASE_IMM:
2903 s390_lhi (code, s390_r14, ins->inst_imm);
2904 if (s390_is_uimm12(ins->inst_offset)) {
2905 s390_sth (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2907 s390_basr (code, s390_r14, 0);
2909 s390_word (code, ins->inst_offset);
2910 s390_l (code, s390_r13, 0, s390_r13, 4);
2911 s390_sth (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2914 case OP_STORE_MEMBASE_IMM:
2915 case OP_STOREI4_MEMBASE_IMM:
2916 if (s390_is_imm16(ins->inst_imm)) {
2917 s390_lhi (code, s390_r14, ins->inst_imm);
2919 s390_basr (code, s390_r13, 0);
2921 s390_word (code, ins->inst_imm);
2922 s390_l (code, s390_r14, 0, s390_r13, 4);
2924 if (s390_is_uimm12(ins->inst_offset)) {
2925 s390_st (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2927 s390_basr (code, s390_r13, 0);
2929 s390_word (code, ins->inst_offset);
2930 s390_l (code, s390_r13, 0, s390_r13, 4);
2931 s390_st (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2934 case OP_STOREI1_MEMBASE_REG:
2935 if (s390_is_uimm12(ins->inst_offset)) {
2936 s390_stc (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
2938 s390_basr (code, s390_r13, 0);
2940 s390_word (code, ins->inst_offset);
2941 s390_l (code, s390_r13, 0, s390_r13, 4);
2942 s390_stc (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2945 case OP_STOREI2_MEMBASE_REG:
2946 if (s390_is_uimm12(ins->inst_offset)) {
2947 s390_sth (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
2949 s390_basr (code, s390_r13, 0);
2951 s390_word (code, ins->inst_offset);
2952 s390_l (code, s390_r13, 0, s390_r13, 4);
2953 s390_sth (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2956 case OP_STORE_MEMBASE_REG:
2957 case OP_STOREI4_MEMBASE_REG:
2958 if (s390_is_uimm12(ins->inst_offset)) {
2959 s390_st (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
2961 s390_basr (code, s390_r13, 0);
2963 s390_word (code, ins->inst_offset);
2964 s390_l (code, s390_r13, 0, s390_r13, 4);
2965 s390_st (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2971 s390_basr (code, s390_r13, 0);
2973 s390_word (code, ins->inst_p0);
2974 s390_l (code, s390_r13, 0, s390_r13, 4);
2975 s390_l (code, ins->dreg, 0, s390_r13, 0);
2978 g_assert_not_reached ();
2980 case OP_LOAD_MEMBASE:
2981 case OP_LOADI4_MEMBASE:
2982 case OP_LOADU4_MEMBASE:
2983 if (s390_is_uimm12(ins->inst_offset))
2984 s390_l (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
2986 s390_basr (code, s390_r13, 0);
2988 s390_word (code, ins->inst_offset);
2989 s390_l (code, s390_r13, 0, s390_r13, 4);
2990 s390_l (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
2993 case OP_LOADU1_MEMBASE:
2994 s390_lhi (code, s390_r0, 0);
2995 if (s390_is_uimm12(ins->inst_offset))
2996 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
2998 s390_basr (code, s390_r13, 0);
3000 s390_word (code, ins->inst_offset);
3001 s390_l (code, s390_r13, 0, s390_r13, 4);
3002 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3004 s390_lr (code, ins->dreg, s390_r0);
3006 case OP_LOADI1_MEMBASE:
3007 s390_lhi (code, s390_r0, 0);
3008 if (s390_is_uimm12(ins->inst_offset))
3009 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3011 s390_basr (code, s390_r13, 0);
3013 s390_word (code, ins->inst_offset);
3014 s390_l (code, s390_r13, 0, s390_r13, 4);
3015 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3017 s390_lhi (code, s390_r13, 0x80);
3018 s390_nr (code, s390_r13, s390_r0);
3020 s390_lhi (code, s390_r13, 0xff00);
3021 s390_or (code, s390_r0, s390_r13);
3022 s390_lr (code, ins->dreg, s390_r0);
3024 case OP_LOADU2_MEMBASE:
3025 s390_lhi (code, s390_r0, 0);
3026 if (s390_is_uimm12(ins->inst_offset))
3027 s390_icm (code, s390_r0, 3, ins->inst_basereg, ins->inst_offset);
3029 s390_basr (code, s390_r13, 0);
3031 s390_word (code, ins->inst_offset);
3032 s390_l (code, s390_r13, 0, s390_r13, 4);
3033 s390_ar (code, s390_r13, ins->inst_basereg);
3034 s390_icm (code, s390_r0, 3, s390_r13, 0);
3036 s390_lr (code, ins->dreg, s390_r0);
3038 case OP_LOADI2_MEMBASE:
3039 s390_lhi (code, s390_r0, 0);
3040 if (s390_is_uimm12(ins->inst_offset))
3041 s390_lh (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3043 s390_basr (code, s390_r13, 0);
3045 s390_word (code, ins->inst_offset);
3046 s390_l (code, s390_r13, 0, s390_r13, 4);
3047 s390_lh (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3049 s390_lr (code, ins->dreg, s390_r0);
3052 s390_lhi (code, s390_r0, 0x80);
3053 if (ins->dreg != ins->sreg1) {
3054 s390_lr (code, ins->dreg, ins->sreg1);
3056 s390_nr (code, s390_r0, ins->sreg1);
3058 s390_lhi (code, s390_r13, -1);
3059 s390_sll (code, s390_r13, 0, 8);
3060 s390_or (code, ins->dreg, s390_r13);
3063 s390_lhi (code, s390_r0, 0x80);
3064 s390_lr (code, ins->dreg, ins->sreg1);
3065 s390_nr (code, s390_r0, ins->sreg1);
3067 s390_lhi (code, s390_r13, -1);
3068 s390_sll (code, s390_r13, 0, 16);
3069 s390_or (code, ins->dreg, s390_r13);
3072 s390_lhi (code, s390_r0, 0xff);
3073 if (ins->dreg != ins->sreg1) {
3074 s390_lr (code, ins->dreg, ins->sreg1);
3076 s390_nr (code, ins->dreg, s390_r0);
3079 s390_lhi (code, s390_r0, -1);
3080 s390_sll (code, s390_r0, 0, 16);
3081 s390_srl (code, s390_r0, 0, 16);
3082 if (ins->dreg != ins->sreg1) {
3083 s390_lr (code, ins->dreg, ins->sreg1);
3085 s390_nr (code, ins->dreg, s390_r0);
3089 ((ins->next->opcode >= CEE_BNE_UN) &&
3090 (ins->next->opcode <= CEE_BLT_UN)))
3091 s390_clr (code, ins->sreg1, ins->sreg2);
3093 s390_cr (code, ins->sreg1, ins->sreg2);
3095 case OP_COMPARE_IMM:
3096 if (s390_is_imm16 (ins->inst_imm)) {
3097 s390_lhi (code, s390_r0, ins->inst_imm);
3099 ((ins->next->opcode >= CEE_BNE_UN) &&
3100 (ins->next->opcode <= CEE_BLT_UN)))
3101 s390_clr (code, ins->sreg1, s390_r0);
3103 s390_cr (code, ins->sreg1, s390_r0);
3106 s390_basr (code, s390_r13, 0);
3108 s390_word (code, ins->inst_imm);
3110 ((ins->next->opcode >= CEE_BNE_UN) &&
3111 (ins->next->opcode <= CEE_BLT_UN)))
3112 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3114 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3117 case OP_X86_TEST_NULL:
3118 s390_ltr (code, ins->sreg1, ins->sreg1);
3124 if (ins->dreg != ins->sreg1) {
3125 s390_lr (code, ins->dreg, ins->sreg1);
3127 s390_alr (code, ins->dreg, ins->sreg2);
3130 if (ins->dreg != ins->sreg1) {
3131 s390_lr (code, ins->dreg, ins->sreg1);
3133 s390_ar (code, ins->dreg, ins->sreg2);
3136 if (ins->dreg != ins->sreg1) {
3137 s390_lr (code, ins->dreg, ins->sreg1);
3139 s390_alcr (code, ins->dreg, ins->sreg2);
3143 (ins->next->opcode == OP_ADC_IMM)) {
3144 s390_basr (code, s390_r13, 0);
3146 s390_word (code, ins->inst_imm);
3147 if (ins->dreg != ins->sreg1) {
3148 s390_lr (code, ins->dreg, ins->sreg1);
3150 s390_al (code, ins->dreg, 0, s390_r13, 4);
3152 if (s390_is_imm16 (ins->inst_imm)) {
3153 if (ins->dreg != ins->sreg1) {
3154 s390_lr (code, ins->dreg, ins->sreg1);
3156 s390_ahi (code, ins->dreg, ins->inst_imm);
3158 s390_basr (code, s390_r13, 0);
3160 s390_word (code, ins->inst_imm);
3161 if (ins->dreg != ins->sreg1) {
3162 s390_lr (code, ins->dreg, ins->sreg1);
3164 s390_a (code, ins->dreg, 0, s390_r13, 4);
3169 if (s390_is_imm16 (ins->inst_imm)) {
3170 if (ins->dreg != ins->sreg1) {
3171 s390_lr (code, ins->dreg, ins->sreg1);
3173 s390_lhi (code, s390_r0, ins->inst_imm);
3174 s390_alcr (code, ins->dreg, s390_r0);
3176 s390_basr (code, s390_r13, 0);
3178 s390_word (code, ins->inst_imm);
3179 s390_l (code, s390_r13, 0, s390_r13, 4);
3180 s390_alcr (code, ins->dreg, s390_r13);
3184 if (ins->dreg != ins->sreg1) {
3185 s390_lr (code, ins->dreg, ins->sreg1);
3187 s390_sr (code, ins->dreg, ins->sreg2);
3190 if (ins->dreg != ins->sreg1) {
3191 s390_lr (code, ins->dreg, ins->sreg1);
3193 s390_sr (code, ins->dreg, ins->sreg2);
3196 if (ins->dreg != ins->sreg1) {
3197 s390_lr (code, ins->dreg, ins->sreg1);
3199 s390_slbr (code, ins->dreg, ins->sreg2);
3202 if (s390_is_imm16 (-ins->inst_imm)) {
3203 if (ins->dreg != ins->sreg1) {
3204 s390_lr (code, ins->dreg, ins->sreg1);
3206 s390_ahi (code, ins->dreg, -ins->inst_imm);
3208 s390_basr (code, s390_r13, 0);
3210 s390_word (code, ins->inst_imm);
3211 if (ins->dreg != ins->sreg1) {
3212 s390_lr (code, ins->dreg, ins->sreg1);
3214 s390_s (code, ins->dreg, 0, s390_r13, 4);
3218 s390_basr (code, s390_r13, 0);
3220 s390_word (code, ins->inst_imm);
3221 s390_sl (code, ins->dreg, 0, s390_r13, 4);
3224 if (ins->sreg1 == ins->dreg) {
3225 s390_nr (code, ins->dreg, ins->sreg2);
3228 if (ins->sreg2 == ins->dreg) {
3229 s390_nr (code, ins->dreg, ins->sreg1);
3232 s390_lr (code, ins->dreg, ins->sreg1);
3233 s390_nr (code, ins->dreg, ins->sreg2);
3238 if (s390_is_imm16 (ins->inst_imm)) {
3239 s390_lhi (code, s390_r0, ins->inst_imm);
3240 if (ins->dreg != ins->sreg1) {
3241 s390_lr (code, ins->dreg, ins->sreg1);
3243 s390_nr (code, ins->dreg, s390_r0);
3245 s390_basr (code, s390_r13, 0);
3247 s390_word (code, ins->inst_imm);
3248 if (ins->dreg != ins->sreg1) {
3249 s390_lr (code, ins->dreg, ins->sreg1);
3251 s390_n (code, ins->dreg, 0, s390_r13, 4);
3255 s390_lr (code, s390_r0, ins->sreg1);
3256 s390_srda (code, s390_r0, 0, 32);
3257 s390_dr (code, s390_r0, ins->sreg2);
3258 s390_lr (code, ins->dreg, s390_r1);
3261 s390_lr (code, s390_r0, ins->sreg1);
3262 s390_srdl (code, s390_r0, 0, 32);
3263 s390_dlr (code, s390_r0, ins->sreg2);
3264 s390_lr (code, ins->dreg, s390_r1);
3267 if (s390_is_imm16 (ins->inst_imm)) {
3268 s390_lhi (code, s390_r13, ins->inst_imm);
3269 s390_lr (code, s390_r0, ins->sreg1);
3271 s390_basr (code, s390_r13, 0);
3273 s390_word (code, ins->inst_imm);
3274 s390_lr (code, s390_r0, ins->sreg1);
3275 s390_l (code, s390_r13, 0, s390_r13, 4);
3277 s390_srda (code, s390_r0, 0, 32);
3278 s390_dr (code, s390_r0, ins->sreg2);
3279 s390_lr (code, ins->dreg, s390_r1);
3282 s390_lr (code, s390_r0, ins->sreg1);
3283 s390_srda (code, s390_r0, 0, 32);
3284 s390_dr (code, s390_r0, ins->sreg2);
3285 s390_lr (code, ins->dreg, s390_r0);
3288 s390_lr (code, s390_r0, ins->sreg1);
3289 s390_srdl (code, s390_r0, 0, 32);
3290 s390_dlr (code, s390_r0, ins->sreg2);
3291 s390_lr (code, ins->dreg, s390_r0);
3294 if (s390_is_imm16 (ins->inst_imm)) {
3295 s390_lhi (code, s390_r13, ins->inst_imm);
3296 s390_lr (code, s390_r0, ins->sreg1);
3298 s390_basr (code, s390_r13, 0);
3300 s390_word (code, ins->inst_imm);
3301 s390_lr (code, s390_r0, ins->sreg1);
3302 s390_l (code, s390_r13, 0, s390_r13, 4);
3304 s390_srda (code, s390_r0, 0, 32);
3305 s390_dr (code, s390_r0, ins->sreg2);
3306 s390_lr (code, ins->dreg, s390_r0);
3309 if (ins->sreg1 == ins->dreg) {
3310 s390_or (code, ins->dreg, ins->sreg2);
3313 if (ins->sreg2 == ins->dreg) {
3314 s390_or (code, ins->dreg, ins->sreg1);
3317 s390_lr (code, ins->dreg, ins->sreg1);
3318 s390_or (code, ins->dreg, ins->sreg2);
3323 if (s390_is_imm16 (ins->inst_imm)) {
3324 s390_lhi (code, s390_r0, ins->inst_imm);
3325 if (ins->dreg != ins->sreg1) {
3326 s390_lr (code, ins->dreg, ins->sreg1);
3328 s390_or (code, ins->dreg, s390_r0);
3330 s390_bras (code, s390_r13, 4);
3331 s390_word (code, ins->inst_imm);
3332 if (ins->dreg != ins->sreg1) {
3333 s390_lr (code, ins->dreg, ins->sreg1);
3335 s390_o (code, ins->dreg, 0, s390_r13, 0);
3339 if (ins->sreg1 == ins->dreg) {
3340 s390_xr (code, ins->dreg, ins->sreg2);
3343 if (ins->sreg2 == ins->dreg) {
3344 s390_xr (code, ins->dreg, ins->sreg1);
3347 s390_lr (code, ins->dreg, ins->sreg1);
3348 s390_xr (code, ins->dreg, ins->sreg2);
3353 if (s390_is_imm16 (ins->inst_imm)) {
3354 s390_lhi (code, s390_r0, ins->inst_imm);
3355 if (ins->dreg != ins->sreg1) {
3356 s390_lr (code, ins->dreg, ins->sreg1);
3358 s390_xr (code, ins->dreg, s390_r0);
3360 s390_basr (code, s390_r13, 0);
3362 s390_word (code, ins->inst_imm);
3363 if (ins->dreg != ins->sreg1) {
3364 s390_lr (code, ins->dreg, ins->sreg1);
3366 s390_x (code, ins->dreg, 0, s390_r13, 4);
3370 if (ins->sreg1 != ins->dreg) {
3371 s390_lr (code, ins->dreg, ins->sreg1);
3373 s390_sll (code, ins->dreg, ins->sreg2, 0);
3376 if (ins->sreg1 != ins->dreg) {
3377 s390_lr (code, ins->dreg, ins->sreg1);
3379 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3382 if (ins->sreg1 != ins->dreg) {
3383 s390_lr (code, ins->dreg, ins->sreg1);
3385 s390_sra (code, ins->dreg, ins->sreg2, 0);
3388 if (ins->sreg1 != ins->dreg) {
3389 s390_lr (code, ins->dreg, ins->sreg1);
3391 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3394 if (ins->sreg1 != ins->dreg) {
3395 s390_lr (code, ins->dreg, ins->sreg1);
3397 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3400 if (ins->sreg1 != ins->dreg) {
3401 s390_lr (code, ins->dreg, ins->sreg1);
3403 s390_srl (code, ins->dreg, ins->sreg2, 0);
3406 if (ins->sreg1 != ins->dreg) {
3407 s390_lr (code, ins->dreg, ins->sreg1);
3409 s390_lhi (code, s390_r0, -1);
3410 s390_xr (code, ins->dreg, s390_r0);
3413 s390_lcr (code, ins->dreg, ins->sreg1);
3416 if (ins->sreg1 == ins->dreg) {
3417 s390_msr (code, ins->dreg, ins->sreg2);
3420 if (ins->sreg2 == ins->dreg) {
3421 s390_msr (code, ins->dreg, ins->sreg1);
3424 s390_lr (code, ins->dreg, ins->sreg1);
3425 s390_msr (code, ins->dreg, ins->sreg2);
3430 if (s390_is_imm16 (ins->inst_imm)) {
3431 s390_lhi (code, s390_r13, ins->inst_imm);
3433 s390_basr (code, s390_r13, 0);
3435 s390_word (code, ins->inst_imm);
3436 if (ins->dreg != ins->sreg1) {
3437 s390_lr (code, ins->dreg, ins->sreg1);
3439 s390_l (code, s390_r13, 0, s390_r13, 4);
3441 s390_msr (code, ins->dreg, s390_r13);
3444 s390_lhi (code, s390_r0, 0);
3445 s390_lr (code, s390_r1, ins->sreg1);
3446 s390_mr (code, s390_r0, ins->sreg2);
3447 s390_ltr (code, s390_r0, s390_r0);
3448 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3449 s390_lr (code, ins->dreg, s390_r1);
3451 case CEE_MUL_OVF_UN:
3452 s390_lhi (code, s390_r0, 0);
3453 s390_lr (code, s390_r1, ins->sreg1);
3454 s390_mlr (code, s390_r0, ins->sreg2);
3455 s390_ltr (code, s390_r0, s390_r0);
3456 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3457 s390_lr (code, ins->dreg, s390_r1);
3460 s390_l (code, s390_r0, 0, ins->sreg1, 4);
3461 s390_lr (code, s390_r14, s390_r0);
3462 s390_srda (code, s390_r0, 0, 32);
3463 s390_m (code, s390_r0, 0, ins->sreg2, 4);
3464 s390_srl (code, s390_r14, 0, 31);
3465 s390_a (code, s390_r14, 0, ins->sreg1, 0);
3466 s390_l (code, s390_r13, 0, ins->sreg2, 0);
3467 s390_srl (code, s390_r13, 0, 31);
3468 s390_ms (code, s390_r13, 0, ins->sreg1, 4);
3469 s390_ar (code, s390_r14, s390_r13);
3470 s390_st (code, s390_r14, 0, ins->dreg, 0);
3471 s390_st (code, s390_r1, 0, ins->dreg, 4);
3475 if (s390_is_imm16(ins->inst_c0)) {
3476 s390_lhi (code, ins->dreg, ins->inst_c0);
3478 s390_basr (code, s390_r13, 0);
3480 s390_word (code, ins->inst_c0);
3481 s390_l (code, ins->dreg, 0, s390_r13, 4);
3485 s390_basr (code, s390_r13, 0);
3487 mono_add_patch_info (cfg, code - cfg->native_code,
3488 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3489 s390_word (code, 0);
3490 s390_l (code,ins->dreg, 0, s390_r13, 4);
3496 if (ins->dreg != ins->sreg1) {
3497 s390_lr (code, ins->dreg, ins->sreg1);
3501 int saved = ins->sreg1;
3502 if (ins->sreg1 == s390_r2) {
3503 s390_lr (code, s390_r0, ins->sreg1);
3506 if (ins->sreg2 != s390_r2)
3507 s390_lr (code, s390_r2, ins->sreg2);
3508 if (saved != s390_r3)
3509 s390_lr (code, s390_r3, saved);
3514 if (ins->dreg != ins->sreg1) {
3515 s390_ldr (code, ins->dreg, ins->sreg1);
3518 case OP_FCONV_TO_R4:
3519 if (ins->dreg != ins->sreg1) {
3520 s390_ledbr (code, ins->dreg, ins->sreg1);
3524 g_assert_not_reached ();
3527 /* ensure ins->sreg1 is not NULL */
3528 s390_icm (code, s390_r0, 15, ins->sreg1, 0);
3535 call = (MonoCallInst*)ins;
3536 if (ins->flags & MONO_INST_HAS_METHOD)
3537 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method);
3539 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr);
3540 s390_brasl (code, s390_r14, 0);
3545 case OP_VOIDCALL_REG:
3547 s390_lr (code, s390_r1, ins->sreg1);
3548 s390_basr (code, s390_r14, s390_r1);
3550 case OP_FCALL_MEMBASE:
3551 case OP_LCALL_MEMBASE:
3552 case OP_VCALL_MEMBASE:
3553 case OP_VOIDCALL_MEMBASE:
3554 case OP_CALL_MEMBASE:
3555 s390_l (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3556 s390_basr (code, s390_r14, s390_r1);
3559 g_assert_not_reached ();
3562 s390_lr (code, s390_r1, ins->sreg1);
3563 s390_ahi (code, s390_r1, 14);
3564 s390_srl (code, s390_r1, 0, 3);
3565 s390_sll (code, s390_r1, 0, 3);
3566 s390_l (code, s390_r13, 0, STK_BASE, 0);
3567 s390_lcr (code, s390_r1, s390_r1);
3568 s390_la (code, STK_BASE, STK_BASE, s390_r1, 0);
3569 s390_st (code, s390_r13, 0, STK_BASE, 0);
3570 s390_la (code, ins->dreg, 0, STK_BASE, S390_MINIMAL_STACK_SIZE+7);
3571 s390_srl (code, ins->dreg, 0, 3);
3572 s390_sll (code, ins->dreg, 0, 3);
3575 s390_br (code, s390_r14);
3578 s390_lr (code, s390_r2, ins->sreg1);
3579 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3580 (gpointer)"mono_arch_throw_exception");
3581 s390_brasl (code, s390_r14, 0);
3584 case OP_START_HANDLER:
3585 s390_lr (code, s390_r0, s390_r14);
3586 s390_st (code, s390_r0, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3589 if (ins->sreg1 != s390_r2)
3590 s390_lr (code, s390_r2, ins->sreg1);
3591 s390_l (code, STK_BASE, 0, STK_BASE, 0);
3592 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
3593 s390_br (code, s390_r14);
3595 case CEE_ENDFINALLY:
3596 // s390_l (code, STK_BASE, 0, STK_BASE, 0);
3597 // s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
3598 s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3599 s390_br (code, s390_r14);
3601 case OP_CALL_HANDLER:
3602 mono_add_patch_info (cfg, code-cfg->native_code,
3603 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3604 s390_brasl (code, s390_r14, 0);
3607 ins->inst_c0 = code - cfg->native_code;
3610 EMIT_UNCOND_BRANCH(ins);
3613 s390_br (code, ins->sreg1);
3616 s390_lhi (code, ins->dreg, 1);
3618 s390_lhi (code, ins->dreg, 0);
3621 s390_lhi (code, ins->dreg, 1);
3623 s390_lhi (code, ins->dreg, 0);
3626 s390_lhi (code, ins->dreg, 1);
3628 s390_lhi (code, ins->dreg, 0);
3631 s390_lhi (code, ins->dreg, 1);
3633 s390_lhi (code, ins->dreg, 0);
3636 s390_lhi (code, ins->dreg, 1);
3638 s390_lhi (code, ins->dreg, 0);
3640 case OP_COND_EXC_EQ:
3641 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
3643 case OP_COND_EXC_NE_UN:
3644 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
3646 case OP_COND_EXC_LT:
3647 case OP_COND_EXC_LT_UN:
3648 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
3650 case OP_COND_EXC_GT:
3651 case OP_COND_EXC_GT_UN:
3652 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
3654 case OP_COND_EXC_GE:
3655 case OP_COND_EXC_GE_UN:
3656 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
3658 case OP_COND_EXC_LE:
3659 case OP_COND_EXC_LE_UN:
3660 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
3662 case OP_COND_EXC_OV:
3663 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
3665 case OP_COND_EXC_NO:
3666 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
3669 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
3671 case OP_COND_EXC_NC:
3672 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
3675 EMIT_COND_BRANCH (ins, S390_CC_EQ);
3678 EMIT_COND_BRANCH (ins, S390_CC_NE);
3682 EMIT_COND_BRANCH (ins, S390_CC_LT);
3686 EMIT_COND_BRANCH (ins, S390_CC_GT);
3690 EMIT_COND_BRANCH (ins, S390_CC_GE);
3694 EMIT_COND_BRANCH (ins, S390_CC_LE);
3697 /* floating point opcodes */
3699 if (*((float *) ins->inst_p0) == 0) {
3700 s390_lzdr (code, ins->dreg);
3702 s390_basr (code, s390_r13, 0);
3704 s390_word (code, ins->inst_p0);
3705 s390_l (code, s390_r13, 0, s390_r13, 4);
3706 s390_ld (code, ins->dreg, 0, s390_r13, 0);
3710 if (*((float *) ins->inst_p0) == 0) {
3711 s390_lzer (code, ins->dreg);
3713 s390_basr (code, s390_r13, 0);
3715 s390_word (code, ins->inst_p0);
3716 s390_l (code, s390_r13, 0, s390_r13, 4);
3717 s390_le (code, ins->dreg, 0, s390_r13, 0);
3718 s390_ldebr(code, ins->dreg, ins->dreg);
3721 case OP_STORER8_MEMBASE_REG:
3722 if (s390_is_uimm12(ins->inst_offset)) {
3723 s390_std (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3725 s390_basr (code, s390_r13, 0);
3727 s390_word (code, ins->inst_offset);
3728 s390_l (code, s390_r13, 0, s390_r13, 4);
3729 s390_std (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3732 case OP_LOADR8_MEMBASE:
3733 if (s390_is_uimm12(ins->inst_offset)) {
3734 s390_ld (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3736 s390_basr (code, s390_r13, 0);
3738 s390_word (code, ins->inst_offset);
3739 s390_l (code, s390_r13, 0, s390_r13, 4);
3740 s390_ld (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3743 case OP_STORER4_MEMBASE_REG:
3744 if (s390_is_uimm12(ins->inst_offset)) {
3745 s390_ledbr(code, s390_f0, ins->sreg1);
3746 s390_ste (code, s390_f0, 0, ins->inst_destbasereg, ins->inst_offset);
3748 s390_basr (code, s390_r13, 0);
3750 s390_word (code, ins->inst_offset);
3751 s390_l (code, s390_r13, 0, s390_r13, 4);
3752 s390_ledbr(code, s390_f0, ins->sreg1);
3753 s390_ste (code, s390_f0, s390_r13, ins->inst_destbasereg, 0);
3756 case OP_LOADR4_MEMBASE:
3757 if (s390_is_uimm12(ins->inst_offset)) {
3758 s390_le (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3760 s390_basr (code, s390_r13, 0);
3762 s390_word (code, ins->inst_offset);
3763 s390_l (code, s390_r13, 0, s390_r13, 4);
3764 s390_le (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3766 s390_ldebr (code, ins->dreg, ins->dreg);
3769 s390_cdfbr (code, ins->dreg, ins->sreg1);
3770 s390_ltr (code, ins->sreg1, ins->sreg1);
3771 s390_jnl (code, 12);
3772 s390_basr (code, s390_r13, 0);
3774 s390_word (code, 0x41f00000);
3775 s390_word (code, 0);
3776 s390_adb (code, ins->dreg, 0, s390_r13, 4);
3779 s390_cefbr (code, ins->dreg, ins->sreg1);
3782 s390_cdfbr (code, ins->dreg, ins->sreg1);
3784 case OP_FCONV_TO_I1:
3785 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
3787 case OP_FCONV_TO_U1:
3788 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
3790 case OP_FCONV_TO_I2:
3791 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
3793 case OP_FCONV_TO_U2:
3794 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
3796 case OP_FCONV_TO_I4:
3798 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
3800 case OP_FCONV_TO_U4:
3802 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
3804 case OP_FCONV_TO_I8:
3805 case OP_FCONV_TO_U8:
3806 g_assert_not_reached ();
3807 /* Implemented as helper calls */
3809 case OP_LCONV_TO_R_UN:
3810 g_assert_not_reached ();
3811 /* Implemented as helper calls */
3813 case OP_LCONV_TO_OVF_I: {
3814 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
3816 s390_ltr (code, ins->sreg1, ins->sreg1);
3817 s390_jnl (code, 0); CODEPTR(code, o[0]);
3818 s390_ltr (code, ins->sreg2, ins->sreg2);
3819 s390_jnl (code, 0); CODEPTR(code, o[1]);
3820 s390_lhi (code, s390_r13, -1);
3821 s390_cr (code, ins->sreg2, s390_r13);
3822 s390_jnz (code, 0); CODEPTR(code, o[2]);
3823 if (ins->dreg != ins->sreg1)
3824 s390_lr (code, ins->dreg, ins->sreg1);
3825 s390_j (code, 0); CODEPTR(code, o[3]);
3826 PTRSLOT(code, o[0]);
3827 s390_jz (code, 0); CODEPTR(code, o[4]);
3828 PTRSLOT(code, o[1]);
3829 PTRSLOT(code, o[2]);
3830 mono_add_patch_info (cfg, code - cfg->native_code,
3831 MONO_PATCH_INFO_EXC, "OverflowException");
3832 s390_brasl (code, s390_r14, 0);
3833 PTRSLOT(code, o[3]);
3834 PTRSLOT(code, o[4]);
3838 s390_sqdbr (code, ins->dreg, ins->sreg1);
3841 if (ins->dreg == ins->sreg1)
3842 s390_adbr (code, ins->dreg, ins->sreg2);
3844 if (ins->dreg == ins->sreg2)
3845 s390_adbr (code, ins->dreg, ins->sreg1);
3847 s390_ldr (code, ins->dreg, ins->sreg1);
3848 s390_adbr (code, ins->dreg, ins->sreg2);
3853 if (ins->dreg == ins->sreg1)
3854 s390_sdbr (code, ins->dreg, ins->sreg2);
3856 s390_ldr (code, ins->dreg, ins->sreg1);
3857 s390_sdbr (code, ins->dreg, ins->sreg2);
3861 if (ins->dreg == ins->sreg1)
3862 s390_mdbr (code, ins->dreg, ins->sreg2);
3864 if (ins->dreg == ins->sreg2)
3865 s390_mdbr (code, ins->dreg, ins->sreg1);
3867 s390_ldr (code, ins->dreg, ins->sreg1);
3868 s390_mdbr (code, ins->dreg, ins->sreg2);
3873 if (ins->dreg == ins->sreg1)
3874 s390_ddbr (code, ins->dreg, ins->sreg2);
3876 s390_ldr (code, ins->dreg, ins->sreg1);
3877 s390_ddbr (code, ins->dreg, ins->sreg2);
3881 s390_lcdbr (code, ins->dreg, ins->sreg1);
3884 if (ins->dreg != ins->sreg1) {
3885 s390_ldr (code, ins->dreg, ins->sreg1);
3887 s390_didbr (code, ins->dreg, ins->sreg2, 5, s390_f15);
3890 s390_cdbr (code, ins->sreg1, ins->sreg2);
3893 s390_cdbr (code, ins->sreg1, ins->sreg2);
3894 s390_lhi (code, ins->dreg, 1);
3896 s390_lhi (code, ins->dreg, 0);
3899 s390_cdbr (code, ins->sreg1, ins->sreg2);
3900 s390_lhi (code, ins->dreg, 1);
3902 s390_lhi (code, ins->dreg, 0);
3905 s390_cdbr (code, ins->sreg1, ins->sreg2);
3906 s390_lhi (code, ins->dreg, 1);
3908 s390_lhi (code, ins->dreg, 0);
3911 s390_cdbr (code, ins->sreg1, ins->sreg2);
3912 s390_lhi (code, ins->dreg, 1);
3914 s390_lhi (code, ins->dreg, 0);
3917 s390_cdbr (code, ins->sreg1, ins->sreg2);
3918 s390_lhi (code, ins->dreg, 1);
3920 s390_lhi (code, ins->dreg, 0);
3923 EMIT_COND_BRANCH (ins, S390_CC_EQ|S390_CC_OV);
3926 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
3929 EMIT_COND_BRANCH (ins, S390_CC_LT);
3932 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
3935 EMIT_COND_BRANCH (ins, S390_CC_GT);
3938 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
3941 EMIT_COND_BRANCH (ins, S390_CC_GE);
3944 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
3947 EMIT_COND_BRANCH (ins, S390_CC_LE);
3950 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
3952 case CEE_CKFINITE: {
3954 s390_lhi (code, s390_r13, 0xfc0);
3955 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
3956 s390_jz (code, 0); CODEPTR(code, o);
3957 mono_add_patch_info (cfg, code - cfg->native_code + 2,
3958 MONO_PATCH_INFO_EXC, "ArithmeticException");
3959 s390_brasl (code, s390_r14,0);
3964 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
3965 g_assert_not_reached ();
3968 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
3969 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
3970 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
3971 g_assert_not_reached ();
3977 last_offset = offset;
3982 cfg->code_len = code - cfg->native_code;
3985 /*========================= End of Function ========================*/
3987 /*------------------------------------------------------------------*/
3989 /* Name - mono_arch_register_lowlevel_calls */
3991 /* Function - Register routines to help with --trace operation. */
3993 /*------------------------------------------------------------------*/
3996 mono_arch_register_lowlevel_calls (void)
3998 mono_register_jit_icall (enter_method, "mono_enter_method", NULL, TRUE);
3999 mono_register_jit_icall (leave_method, "mono_leave_method", NULL, TRUE);
4002 /*========================= End of Function ========================*/
4004 /*------------------------------------------------------------------*/
4006 /* Name - mono_arch_patch_code */
4008 /* Function - Process the patch data created during the */
4009 /* instruction build process. This resolves jumps, */
4010 /* calls, variables etc. */
4012 /*------------------------------------------------------------------*/
4015 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4017 MonoJumpInfo *patch_info;
4019 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4020 unsigned char *ip = patch_info->ip.i + code;
4023 switch (patch_info->type) {
4024 case MONO_PATCH_INFO_BB:
4025 target = S390_RELATIVE((patch_info->data.bb->native_offset+code),
4027 ip += 2; /* Skip over op-code */
4029 case MONO_PATCH_INFO_ABS:
4030 target = S390_RELATIVE(patch_info->data.target, ip);
4031 ip += 2; /* Skip over op-code */
4033 case MONO_PATCH_INFO_LABEL:
4034 target = S390_RELATIVE((patch_info->data.inst->inst_c0+code),ip);
4035 ip += 2; /* Skip over op-code */
4037 case MONO_PATCH_INFO_IP:
4040 case MONO_PATCH_INFO_METHOD_REL:
4041 g_assert_not_reached ();
4042 *((gpointer *)(ip)) = code + patch_info->data.offset;
4044 case MONO_PATCH_INFO_INTERNAL_METHOD: {
4045 MonoJitICallInfo *mi = mono_find_jit_icall_by_name (patch_info->data.name);
4047 g_warning ("unknown MONO_PATCH_INFO_INTERNAL_METHOD %s", patch_info->data.name);
4048 g_assert_not_reached ();
4050 target = S390_RELATIVE(mono_icall_get_wrapper (mi), ip);
4051 ip += 2; /* Skip over op-code */
4054 case MONO_PATCH_INFO_METHOD_JUMP:
4055 g_assert_not_reached ();
4057 case MONO_PATCH_INFO_METHOD:
4058 if (patch_info->data.method == method) {
4059 target = S390_RELATIVE(code, ip);
4061 /* get the trampoline to the method from the domain */
4062 target = S390_RELATIVE(mono_arch_create_jit_trampoline (patch_info->data.method), ip);
4063 target = mono_arch_create_jit_trampoline(patch_info->data.method);
4064 target = S390_RELATIVE(target, ip);
4066 ip += 2; /* Skip over op-code */
4068 case MONO_PATCH_INFO_SWITCH: {
4069 gpointer *table = (gpointer *)patch_info->data.target;
4071 /*------------------------------------------------------*/
4072 /* ip is pointing at the basr r13,0/j +4 instruction */
4073 /* the vtable value follows this (i.e. ip+6) */
4074 /*------------------------------------------------------*/
4075 *((gconstpointer *)(ip+6)) = table;
4077 for (i = 0; i < patch_info->table_size; i++) {
4078 table [i] = (int)patch_info->data.table [i] + code;
4082 case MONO_PATCH_INFO_METHODCONST:
4083 case MONO_PATCH_INFO_CLASS:
4084 case MONO_PATCH_INFO_IMAGE:
4085 case MONO_PATCH_INFO_FIELD:
4086 target = S390_RELATIVE(patch_info->data.target, ip);
4088 case MONO_PATCH_INFO_R4:
4089 case MONO_PATCH_INFO_R8:
4090 g_assert_not_reached ();
4091 *((gconstpointer *)(ip + 2)) = patch_info->data.target;
4093 case MONO_PATCH_INFO_IID:
4094 mono_class_init (patch_info->data.klass);
4095 target = S390_RELATIVE(patch_info->data.klass->interface_id, ip);
4097 case MONO_PATCH_INFO_VTABLE:
4098 target = S390_RELATIVE(mono_class_vtable (domain, patch_info->data.klass),ip);
4101 case MONO_PATCH_INFO_CLASS_INIT:
4102 target = S390_RELATIVE(mono_create_class_init_trampoline (mono_class_vtable (domain, patch_info->data.klass)), ip);
4105 case MONO_PATCH_INFO_SFLDA: {
4106 MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
4107 if (!vtable->initialized && !(vtable->klass->flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT) && mono_class_needs_cctor_run (vtable->klass, method))
4108 /* Done by the generated code */
4112 mono_runtime_class_init (vtable);
4114 target = S390_RELATIVE((char*)vtable->data + patch_info->data.field->offset, ip);
4118 case MONO_PATCH_INFO_EXC_NAME:
4119 *((gconstpointer *)(ip)) = patch_info->data.name;
4121 case MONO_PATCH_INFO_LDSTR:
4122 target = mono_ldstr (domain, patch_info->data.token->image,
4123 mono_metadata_token_index (patch_info->data.token->token));
4125 case MONO_PATCH_INFO_TYPE_FROM_HANDLE: {
4127 MonoClass *handle_class;
4129 handle = mono_ldtoken (patch_info->data.token->image,
4130 patch_info->data.token->token,
4131 &handle_class, NULL);
4132 mono_class_init (handle_class);
4133 mono_class_init (mono_class_from_mono_type (handle));
4138 case MONO_PATCH_INFO_LDTOKEN: {
4140 MonoClass *handle_class;
4142 handle = mono_ldtoken (patch_info->data.token->image,
4143 patch_info->data.token->token,
4144 &handle_class, NULL);
4145 mono_class_init (handle_class);
4150 case MONO_PATCH_INFO_EXC:
4151 /* everything is dealt with at epilog output time */
4154 g_assert_not_reached ();
4156 s390_patch (ip, target);
4160 /*========================= End of Function ========================*/
4162 /*------------------------------------------------------------------*/
4164 /* Name - mono_arch_max_epilog_size */
4166 /* Function - Determine the maximum size of the epilog code. */
4168 /*------------------------------------------------------------------*/
4171 mono_arch_max_epilog_size (MonoCompile *cfg)
4173 int max_epilog_size = 96;
4174 MonoJumpInfo *patch_info;
4176 if (cfg->method->save_lmf)
4177 max_epilog_size += 128;
4179 if (mono_jit_trace_calls != NULL)
4180 max_epilog_size += 128;
4182 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4183 max_epilog_size += 128;
4185 /* count the number of exception infos */
4187 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4188 if (patch_info->type == MONO_PATCH_INFO_EXC)
4189 max_epilog_size += 26;
4192 return max_epilog_size;
4195 /*========================= End of Function ========================*/
4197 /*------------------------------------------------------------------*/
4199 /* Name - mono_arch_emit_prolog */
4201 /* Function - Create the instruction sequence for a function */
4204 /*------------------------------------------------------------------*/
4207 mono_arch_emit_prolog (MonoCompile *cfg)
4209 MonoMethod *method = cfg->method;
4211 MonoMethodSignature *sig;
4213 int alloc_size, pos, max_offset, i, lmfOffset;
4219 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
4222 cfg->code_size = 256;
4223 cfg->native_code = code = g_malloc (cfg->code_size);
4225 s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4227 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4228 cfg->used_int_regs |= 1 << 11;
4231 alloc_size = cfg->stack_offset;
4233 alloc_size += S390_TRACE_STACK_SIZE;
4235 /* reserve room to save return value */
4241 if (method->save_lmf)
4242 alloc_size += sizeof(MonoLMF);
4244 alloc_size = S390_ALIGN(alloc_size, S390_STACK_ALIGNMENT);
4246 cfg->stack_usage = alloc_size;
4247 g_assert (s390_is_imm16 (-alloc_size));
4249 s390_lr (code, s390_r11, STK_BASE);
4250 s390_ahi (code, STK_BASE, -alloc_size);
4251 s390_st (code, s390_r11, 0, STK_BASE, 0);
4254 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
4255 s390_lr (code, s390_r11, STK_BASE);
4257 /* compute max_offset in order to use short forward jumps
4258 * we always do it on s390 because the immediate displacement
4259 * for jumps is too small
4262 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4263 MonoInst *ins = bb->code;
4264 bb->max_offset = max_offset;
4266 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4270 max_offset += ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
4275 /* load arguments allocated to register from the stack */
4276 sig = method->signature;
4279 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
4281 if (cinfo->struct_ret) {
4282 ArgInfo *ainfo = &cinfo->ret;
4284 inst->unused = ainfo->vtsize;
4285 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4288 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4289 ArgInfo *ainfo = cinfo->args + i;
4290 inst = cfg->varinfo [pos];
4292 if (inst->opcode == OP_REGVAR) {
4293 if (ainfo->regtype == RegTypeGeneral)
4294 s390_lr (code, inst->dreg, ainfo->reg);
4295 else if (ainfo->regtype == RegTypeFP) {
4296 if (ainfo->size == 4) {
4297 s390_ledbr (code, inst->dreg, ainfo->reg);
4299 s390_ldr (code, inst->dreg, ainfo->reg);
4302 else if (ainfo->regtype == RegTypeBase) {
4303 s390_lr (code, s390_r13, STK_BASE);
4304 s390_ahi (code, s390_r13, alloc_size);
4305 s390_l (code, inst->dreg, 0, s390_r13, ainfo->offset);
4307 g_assert_not_reached ();
4309 if (cfg->verbose_level > 2)
4310 g_print ("Argument %d assigned to register %s\n",
4311 pos, mono_arch_regname (inst->dreg));
4313 if (ainfo->regtype == RegTypeGeneral) {
4314 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4315 g_assert_not_reached();
4316 switch (ainfo->size) {
4318 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4321 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4324 s390_stm (code, ainfo->reg, ainfo->reg + 1,
4325 inst->inst_basereg, inst->inst_offset);
4328 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4330 } else if (ainfo->regtype == RegTypeBase) {
4331 } else if (ainfo->regtype == RegTypeFP) {
4332 if (ainfo->size == 8)
4333 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4334 else if (ainfo->size == 4)
4335 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4337 g_assert_not_reached ();
4338 } else if (ainfo->regtype == RegTypeStructByVal) {
4339 int doffset = inst->inst_offset;
4341 if (ainfo->reg != STK_BASE)
4345 s390_lr (code, s390_r13, STK_BASE);
4346 s390_ahi (code, s390_r13, alloc_size);
4348 switch (ainfo->size) {
4350 if (ainfo->reg == STK_BASE)
4351 s390_ic (code, reg, 0, s390_r13, ainfo->offset+3);
4352 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4355 if (ainfo->reg == STK_BASE)
4356 s390_lh (code, reg, 0, s390_r13, ainfo->offset+2);
4357 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4360 if (ainfo->reg == STK_BASE)
4361 s390_l (code, reg, 0, s390_r13, ainfo->offset);
4362 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4365 if (ainfo->reg == STK_BASE)
4366 s390_lm (code, s390_r0, s390_r1, s390_r13, ainfo->offset);
4367 s390_stm (code, reg, reg+1, inst->inst_basereg, doffset);
4370 } else if (ainfo->regtype == RegTypeStructByAddr) {
4371 code = emit_memcpy (code, ainfo->vtsize,
4372 inst->inst_basereg, inst->inst_offset, ainfo->reg, 0);
4374 g_assert_not_reached ();
4379 if (method->save_lmf) {
4380 /*---------------------------------------------------------------*/
4381 /* Preserve the parameter registers while we fix up the lmf */
4382 /*---------------------------------------------------------------*/
4383 s390_lr (code, s390_r7, s390_r2);
4384 s390_lr (code, s390_r8, s390_r3);
4385 s390_lr (code, s390_r9, s390_r4);
4386 s390_lr (code, s390_r10, s390_r5);
4388 mono_add_patch_info (cfg, code - cfg->native_code,
4389 MONO_PATCH_INFO_INTERNAL_METHOD,
4390 (gpointer)"mono_get_lmf_addr");
4391 /*---------------------------------------------------------------*/
4392 /* On return from this call r2 have the address of the &lmf */
4393 /*---------------------------------------------------------------*/
4394 s390_brasl (code, s390_r14, 0);
4396 /*---------------------------------------------------------------*/
4397 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4398 /*---------------------------------------------------------------*/
4399 lmfOffset = S390_MINIMAL_STACK_SIZE + cfg->param_area;
4401 lmfOffset += S390_TRACE_STACK_SIZE;
4403 s390_lr (code, s390_r13, cfg->frame_reg);
4404 s390_ahi (code, s390_r13, lmfOffset);
4406 /*---------------------------------------------------------------*/
4407 /* Set lmf.lmf_addr = jit_tls->lmf */
4408 /*---------------------------------------------------------------*/
4409 s390_st (code, s390_r2, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4411 /*---------------------------------------------------------------*/
4412 /* Get current lmf */
4413 /*---------------------------------------------------------------*/
4414 s390_l (code, s390_r0, 0, s390_r2, 0);
4416 /*---------------------------------------------------------------*/
4417 /* Set our lmf as the current lmf */
4418 /*---------------------------------------------------------------*/
4419 s390_st (code, s390_r13, 0, s390_r2, 0);
4421 /*---------------------------------------------------------------*/
4422 /* Have our lmf.previous_lmf point to the last lmf */
4423 /*---------------------------------------------------------------*/
4424 s390_st (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4426 /*---------------------------------------------------------------*/
4427 /* save method info */
4428 /*---------------------------------------------------------------*/
4429 s390_basr (code, s390_r1, 0);
4431 s390_word (code, method);
4432 s390_l (code, s390_r1, 0, s390_r1, 4);
4433 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, method));
4434 s390_st (code, cfg->frame_reg, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4436 /*---------------------------------------------------------------*/
4437 /* save the current IP */
4438 /*---------------------------------------------------------------*/
4439 s390_larl (code, s390_r1, 0);
4440 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4442 /*---------------------------------------------------------------*/
4443 /* Restore the parameter registers now that we've set up the lmf */
4444 /*---------------------------------------------------------------*/
4445 s390_lr (code, s390_r2, s390_r7);
4446 s390_lr (code, s390_r3, s390_r8);
4447 s390_lr (code, s390_r4, s390_r9);
4448 s390_lr (code, s390_r5, s390_r10);
4452 code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
4454 cfg->code_len = code - cfg->native_code;
4460 /*========================= End of Function ========================*/
4462 /*------------------------------------------------------------------*/
4464 /* Name - mono_arch_emit_epilog */
4466 /* Function - Emit the instructions for a function epilog. */
4468 /*------------------------------------------------------------------*/
4471 mono_arch_emit_epilog (MonoCompile *cfg)
4473 MonoJumpInfo *patch_info;
4474 MonoMethod *method = cfg->method;
4475 MonoMethodSignature *sig = method->signature;
4477 int i, lmfOffset, tracing = 0;
4480 code = cfg->native_code + cfg->code_len;
4482 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
4485 if (method->save_lmf) {
4486 s390_lr (code, s390_r13, cfg->frame_reg);
4488 lmfOffset = S390_MINIMAL_STACK_SIZE + cfg->param_area;
4490 lmfOffset += S390_TRACE_STACK_SIZE;
4492 /*-------------------------------------------------*/
4494 /*-------------------------------------------------*/
4495 s390_ahi (code, s390_r13, lmfOffset);
4497 /*-------------------------------------------------*/
4498 /* r6 = &jit_tls->lmf */
4499 /*-------------------------------------------------*/
4500 s390_l (code, s390_r6, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4502 /*-------------------------------------------------*/
4503 /* r0 = lmf.previous_lmf */
4504 /*-------------------------------------------------*/
4505 s390_l (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4507 /*-------------------------------------------------*/
4508 /* jit_tls->lmf = previous_lmf */
4509 /*-------------------------------------------------*/
4510 s390_l (code, s390_r13, 0, s390_r6, 0);
4511 s390_st (code, s390_r0, 0, s390_r6, 0);
4514 if (cfg->frame_reg != STK_BASE)
4515 s390_lr (code, STK_BASE, cfg->frame_reg);
4517 s390_ahi (code, STK_BASE, cfg->stack_usage);
4518 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4519 s390_br (code, s390_r14);
4521 /* add code to raise exceptions */
4522 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4523 switch (patch_info->type) {
4524 case MONO_PATCH_INFO_EXC: {
4525 /*-----------------------------------------------------*/
4526 /* Patch the branch in epilog to come here */
4527 /*-----------------------------------------------------*/
4528 s390_patch (patch_info->ip.i+cfg->native_code+2,
4529 S390_RELATIVE(code,patch_info->ip.i+cfg->native_code));
4530 /*-----------------------------------------------------*/
4531 /* Patch the parameter passed to the handler */
4532 /*-----------------------------------------------------*/
4533 s390_basr (code, s390_r13, 0);
4535 mono_add_patch_info (cfg, code - cfg->native_code,
4536 MONO_PATCH_INFO_EXC_NAME,
4537 patch_info->data.target);
4538 s390_word (code, 0);
4539 /*-----------------------------------------------------*/
4540 /* Load the return address and the parameter register */
4541 /*-----------------------------------------------------*/
4542 s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
4543 cfg->native_code + 8), code));
4544 s390_l (code, s390_r2, 0, s390_r13, 4);
4545 /*-----------------------------------------------------*/
4546 /* Reuse the current patch to set the jump */
4547 /*-----------------------------------------------------*/
4548 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
4549 patch_info->data.name = "mono_arch_throw_exception_by_name";
4550 patch_info->ip.i = code - cfg->native_code;
4551 s390_jcl (code, S390_CC_UN, 0);
4560 cfg->code_len = code - cfg->native_code;
4562 g_assert (cfg->code_len < cfg->code_size);
4566 /*========================= End of Function ========================*/
4568 /*------------------------------------------------------------------*/
4570 /* Name - mono_arch_setup_jit_tls_data */
4572 /* Function - Setup the JIT's Thread Level Specific Data. */
4574 /*------------------------------------------------------------------*/
4577 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
4581 /*========================= End of Function ========================*/
4583 /*------------------------------------------------------------------*/
4585 /* Name - mono_arch_free_jit_tls_data */
4587 /* Function - Free tls data. */
4589 /*------------------------------------------------------------------*/
4592 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
4596 /*========================= End of Function ========================*/
4598 /*------------------------------------------------------------------*/
4600 /* Name - mono_arch_emit_this_vret_args */
4604 /*------------------------------------------------------------------*/
4607 mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
4609 int this_dreg = s390_r2;
4612 this_dreg = s390_r3;
4614 /* add the this argument */
4615 if (this_reg != -1) {
4617 MONO_INST_NEW (cfg, this, OP_SETREG);
4618 this->type = this_type;
4619 this->sreg1 = this_reg;
4620 this->dreg = this_dreg;
4621 mono_bblock_add_inst (cfg->cbb, this);
4626 MONO_INST_NEW (cfg, vtarg, OP_SETREG);
4627 vtarg->type = STACK_MP;
4628 vtarg->sreg1 = vt_reg;
4629 vtarg->dreg = s390_r2;
4630 mono_bblock_add_inst (cfg->cbb, vtarg);
4634 /*========================= End of Function ========================*/
4636 /*------------------------------------------------------------------*/
4638 /* Name - mono_arch_get_opcode_for_method */
4640 /* Function - Check for opcodes we can handle directly in */
4643 /*------------------------------------------------------------------*/
4646 mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
4648 if (cmethod->klass == mono_defaults.math_class) {
4649 if (strcmp (cmethod->name, "Sqrt") == 0)
4655 /*========================= End of Function ========================*/
4657 /*------------------------------------------------------------------*/
4659 /* Name - mono_arch_print_tree */
4661 /* Function - Print platform-specific opcode details. */
4663 /* Returns - 1 - opcode details have been printed */
4664 /* 0 - opcode details have not been printed */
4666 /*------------------------------------------------------------------*/
4669 mono_arch_print_tree (MonoInst *tree, int arity)
4673 switch (tree->opcode) {
4674 case OP_S390_LOADARG:
4675 case OP_S390_ARGPTR:
4676 case OP_S390_STKARG:
4677 printf ("[0x%x(%s)]", tree->inst_offset,
4678 mono_arch_regname (tree->inst_basereg));
4687 /*========================= End of Function ========================*/
4689 /*------------------------------------------------------------------*/
4691 /* Name - mono_arch_regalloc_cost */
4693 /* Function - Determine the cost, in the number of memory */
4694 /* references, of the action of allocating the var- */
4695 /* iable VMV into a register during global register */
4698 /* Returns - Cost */
4700 /*------------------------------------------------------------------*/
4703 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
4709 /*========================= End of Function ========================*/