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 */
194 gint32 gr[5]; /* R2-R6 */
195 gdouble fp[3]; /* F0-F2 */
196 } __attribute__ ((packed)) RegParm;
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 += 4;
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;
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 (cinfo->struct_ret) {
1275 m->ret->opcode = OP_REGVAR;
1276 m->ret->inst_c0 = s390_r2;
1278 /* FIXME: handle long and FP values */
1279 switch (sig->ret->type) {
1280 case MONO_TYPE_VOID:
1283 m->ret->opcode = OP_REGVAR;
1284 m->ret->dreg = s390_r2;
1289 /*--------------------------------------------------------------*/
1290 /* local vars are at a positive offset from the stack pointer */
1292 /* also note that if the function uses alloca, we use s390_r11 */
1293 /* to point at the local variables. */
1294 /* add parameter area size for called functions */
1295 /*--------------------------------------------------------------*/
1296 offset = (m->param_area + S390_MINIMAL_STACK_SIZE);
1298 if (cinfo->struct_ret) {
1300 offset = S390_ALIGN(offset, sizeof(gpointer));
1301 inst->inst_offset = offset;
1302 inst->opcode = OP_REGOFFSET;
1303 inst->inst_basereg = frame_reg;
1304 offset += sizeof(gpointer);
1307 curinst = m->locals_start;
1308 for (iVar = curinst; iVar < m->num_varinfo; ++iVar) {
1309 inst = m->varinfo [iVar];
1310 if (inst->opcode == OP_REGVAR)
1313 /* inst->unused indicates native sized value types, this is used by the
1314 * pinvoke wrappers when they call functions returning structure */
1315 if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1316 size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
1318 size = mono_type_size (inst->inst_vtype, &align);
1320 offset = S390_ALIGN(offset, align);
1321 inst->inst_offset = offset;
1322 inst->opcode = OP_REGOFFSET;
1323 inst->inst_basereg = frame_reg;
1325 //g_print ("allocating local %d to %d\n", i, inst->inst_offset);
1330 inst = m->varinfo [curinst];
1331 if (inst->opcode != OP_REGVAR) {
1332 inst->opcode = OP_REGOFFSET;
1333 inst->inst_basereg = frame_reg;
1334 offset = S390_ALIGN(offset, sizeof(gpointer));
1335 inst->inst_offset = offset;
1336 offset += sizeof (gpointer);
1343 eArg = sig->param_count + sArg;
1345 for (iParm = sArg; iParm < eArg; ++iParm) {
1346 inst = m->varinfo [curinst];
1347 if (inst->opcode != OP_REGVAR) {
1348 if (cinfo->args[iParm].regtype == RegTypeStructByVal) {
1349 if (cinfo->args[iParm].vtsize != 0) {
1350 inst->opcode = OP_S390_LOADARG;
1351 inst->inst_basereg = frame_reg;
1352 size = sizeof(long);
1353 offset = S390_ALIGN(offset, size);
1354 inst->inst_offset = offset;
1356 inst->opcode = OP_S390_ARGPTR;
1357 inst->inst_basereg = frame_reg;
1358 size = cinfo->args[iParm].size;
1359 offset = S390_ALIGN(offset, size);
1360 inst->inst_offset = offset;
1363 if (cinfo->args[iParm].reg != STK_BASE) {
1364 inst->opcode = OP_REGOFFSET;
1365 inst->inst_basereg = frame_reg;
1366 size = (cinfo->args[iParm].size < 8
1368 : sizeof(long long));
1369 offset = S390_ALIGN(offset, size);
1370 inst->inst_offset = offset;
1372 inst->opcode = OP_S390_STKARG;
1373 inst->inst_basereg = frame_reg;
1374 size = (cinfo->args[iParm].size < 4
1375 ? 4 - cinfo->args[iParm].size
1377 inst->inst_offset = cinfo->args[iParm].offset +
1379 // inst->unused = stackOffset;
1381 size = sizeof(long);
1389 /*------------------------------------------------------*/
1390 /* Allow space for the trace method stack area if needed*/
1391 /*------------------------------------------------------*/
1392 if (mono_jit_trace_calls != NULL && mono_trace_eval (m))
1393 offset += S390_TRACE_STACK_SIZE;
1395 /*------------------------------------------------------*/
1396 /* Reserve space to save LMF and caller saved registers */
1397 /*------------------------------------------------------*/
1398 if (m->method->save_lmf)
1399 offset += sizeof (MonoLMF);
1401 /*------------------------------------------------------*/
1402 /* align the offset */
1403 /*------------------------------------------------------*/
1404 m->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1408 /*========================= End of Function ========================*/
1410 /*------------------------------------------------------------------*/
1412 /* Name - mono_arch_call_opcode */
1414 /* Function - Take the arguments and generate the arch-specific */
1415 /* instructions to properly call the function. This */
1416 /* includes pushing, moving argments to the correct */
1419 /* Note - FIXME: We need an alignment solution for */
1420 /* enter_method and mono_arch_call_opcode, currently */
1421 /* alignment in mono_arch_call_opcode is computed */
1422 /* without arch_get_argument_info. */
1424 /*------------------------------------------------------------------*/
1427 mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
1429 MonoMethodSignature *sig;
1430 int i, n, lParamArea;
1435 sig = call->signature;
1436 n = sig->param_count + sig->hasthis;
1438 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1439 if (cinfo->struct_ret)
1440 call->used_iregs |= 1 << cinfo->struct_ret;
1442 for (i = 0; i < n; ++i) {
1443 ainfo = cinfo->args + i;
1444 if (is_virtual && i == 0) {
1445 /* the argument will be attached to the call instrucion */
1446 in = call->args [i];
1447 call->used_iregs |= 1 << ainfo->reg;
1449 MONO_INST_NEW (cfg, arg, OP_OUTARG);
1450 in = call->args [i];
1451 arg->cil_code = in->cil_code;
1452 arg->inst_left = in;
1453 arg->type = in->type;
1454 /* prepend, we'll need to reverse them later */
1455 arg->next = call->out_args;
1456 call->out_args = arg;
1457 if (ainfo->regtype == RegTypeGeneral) {
1458 arg->unused = ainfo->reg;
1459 call->used_iregs |= 1 << ainfo->reg;
1460 if (arg->type == STACK_I8)
1461 call->used_iregs |= 1 << (ainfo->reg + 1);
1462 } else if (ainfo->regtype == RegTypeStructByAddr) {
1463 arg->unused = ainfo->reg;
1464 call->used_iregs |= 1 << ainfo->reg;
1465 } else if (ainfo->regtype == RegTypeStructByVal) {
1466 if (ainfo->reg != STK_BASE) {
1467 switch (ainfo->size) {
1472 call->used_iregs |= 1 << ainfo->reg;
1475 call->used_iregs |= 1 << ainfo->reg;
1476 call->used_iregs |= 1 << (ainfo->reg+1);
1480 arg->sreg2 = ainfo->reg;
1481 arg->opcode = OP_OUTARG_VT;
1482 if (ainfo->vtsize != 0)
1483 arg->unused = -ainfo->vtsize;
1485 arg->unused = ainfo->size;
1486 arg->inst_imm = ainfo->offset;
1487 arg->sreg1 = ainfo->offparm;
1488 } else if (ainfo->regtype == RegTypeBase) {
1489 arg->opcode = OP_OUTARG;
1490 arg->unused = ainfo->reg | (ainfo->size << 8);
1491 arg->inst_imm = ainfo->offset;
1492 } else if (ainfo->regtype == RegTypeFP) {
1493 arg->opcode = OP_OUTARG_R8;
1494 arg->unused = ainfo->reg;
1495 call->used_fregs |= 1 << ainfo->reg;
1496 if (ainfo->size == 4) {
1497 /* we reduce the precision */
1499 MONO_INST_NEW (cfg, conv, OP_FCONV_TO_R4);
1500 conv->inst_left = arg->inst_left;
1501 arg->inst_left = conv;
1504 g_assert_not_reached ();
1509 * Reverse the call->out_args list.
1512 MonoInst *prev = NULL, *list = call->out_args, *next;
1519 call->out_args = prev;
1521 call->stack_usage = cinfo->stack_usage;
1523 lParamArea = cinfo->stack_usage - S390_MINIMAL_STACK_SIZE;
1524 cfg->param_area = MAX (cfg->param_area, lParamArea);
1525 cfg->flags |= MONO_CFG_HAS_CALLS;
1526 /*----------------------------------------------------------*/
1527 /* should set more info in call, such as the stack space */
1528 /* used by the args that needs to be added back to esp */
1529 /*----------------------------------------------------------*/
1535 /*========================= End of Function ========================*/
1537 /*------------------------------------------------------------------*/
1539 /* Name - mono_arch_instrument_mem_needs */
1541 /* Function - Allow tracing to work with this interface (with */
1542 /* an optional argument). */
1544 /*------------------------------------------------------------------*/
1547 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
1549 /* no stack room needed now (may be needed for FASTCALL-trace support) */
1551 /* split prolog-epilog requirements? */
1552 *code = 50; /* max bytes needed: check this number */
1555 /*========================= End of Function ========================*/
1557 /*------------------------------------------------------------------*/
1559 /* Name - mono_arch_instrument_prolog */
1561 /* Function - Create an "instrumented" prolog. */
1563 /*------------------------------------------------------------------*/
1566 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
1567 gboolean enable_arguments)
1573 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
1574 if (cfg->method->save_lmf)
1575 parmOffset -= sizeof(MonoLMF);
1576 fpOffset = parmOffset + (5*sizeof(gint32));
1578 s390_stm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1579 s390_std (code, s390_f0, 0, STK_BASE, fpOffset);
1580 s390_std (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1581 s390_std (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1582 s390_basr (code, s390_r13, 0);
1584 s390_word (code, cfg->method);
1585 s390_word (code, func);
1586 s390_l (code, s390_r2, 0, s390_r13, 4);
1587 s390_la (code, s390_r3, 0, STK_BASE, parmOffset);
1588 s390_lr (code, s390_r4, STK_BASE);
1589 s390_ahi (code, s390_r4, cfg->stack_usage);
1590 s390_l (code, s390_r1, 0, s390_r13, 8);
1591 s390_basr (code, s390_r14, s390_r1);
1592 s390_ld (code, s390_f2, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
1593 s390_ld (code, s390_f1, 0, STK_BASE, fpOffset+sizeof(gdouble));
1594 s390_ld (code, s390_f0, 0, STK_BASE, fpOffset);
1595 s390_lm (code, s390_r2, s390_r6, STK_BASE, parmOffset);
1600 /*========================= End of Function ========================*/
1602 /*------------------------------------------------------------------*/
1604 /* Name - mono_arch_instrument_epilog */
1606 /* Function - Create an epilog that will handle the returned */
1607 /* values used in instrumentation. */
1609 /*------------------------------------------------------------------*/
1612 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
1615 int save_mode = SAVE_NONE,
1617 MonoMethod *method = cfg->method;
1618 int rtype = method->signature->ret->type;
1620 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
1621 if (method->save_lmf)
1622 saveOffset -= sizeof(MonoLMF);
1626 case MONO_TYPE_VOID:
1627 /* special case string .ctor icall */
1628 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
1629 save_mode = SAVE_ONE;
1631 save_mode = SAVE_NONE;
1635 save_mode = SAVE_TWO;
1639 save_mode = SAVE_FP;
1641 case MONO_TYPE_VALUETYPE:
1642 if (method->signature->ret->data.klass->enumtype) {
1643 rtype = method->signature->ret->data.klass->enum_basetype->type;
1646 save_mode = SAVE_STRUCT;
1649 save_mode = SAVE_ONE;
1653 switch (save_mode) {
1655 s390_stm (code, s390_r2, s390_r3, cfg->frame_reg, saveOffset);
1656 if (enable_arguments) {
1657 s390_lr (code, s390_r4, s390_r3);
1658 s390_lr (code, s390_r3, s390_r2);
1662 s390_st (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1663 if (enable_arguments) {
1664 s390_lr (code, s390_r3, s390_r2);
1668 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
1669 if (enable_arguments) {
1670 /* FIXME: what reg? */
1671 s390_ldr (code, s390_f2, s390_f0);
1672 s390_lm (code, s390_r3, s390_r4, cfg->frame_reg, saveOffset);
1676 s390_st (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1677 if (enable_arguments) {
1678 s390_l (code, s390_r3, 0, cfg->frame_reg,
1679 S390_MINIMAL_STACK_SIZE+cfg->param_area);
1687 s390_basr (code, s390_r13, 0);
1689 s390_word (code, cfg->method);
1690 s390_word (code, func);
1691 s390_l (code, s390_r2, 0, s390_r13, 4);
1692 s390_l (code, s390_r1, 0, s390_r13, 8);
1693 s390_basr (code, s390_r14, s390_r1);
1695 switch (save_mode) {
1697 s390_lm (code, s390_r2, s390_r3, cfg->frame_reg, saveOffset);
1700 s390_l (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1703 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
1706 s390_l (code, s390_r2, 0, cfg->frame_reg, saveOffset);
1716 /*========================= End of Function ========================*/
1718 /*------------------------------------------------------------------*/
1720 /* Name - peephole_pass */
1722 /* Function - Form a peephole pass at the code looking for */
1723 /* simple optimizations. */
1725 /*------------------------------------------------------------------*/
1728 peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
1730 MonoInst *ins, *last_ins = NULL;
1735 switch (ins->opcode) {
1737 /* remove unnecessary multiplication with 1 */
1738 if (ins->inst_imm == 1) {
1739 if (ins->dreg != ins->sreg1) {
1740 ins->opcode = OP_MOVE;
1742 last_ins->next = ins->next;
1748 case OP_LOAD_MEMBASE:
1749 case OP_LOADI4_MEMBASE:
1751 * OP_STORE_MEMBASE_REG reg, offset(basereg)
1752 * OP_LOAD_MEMBASE offset(basereg), reg
1754 if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG
1755 || last_ins->opcode == OP_STORE_MEMBASE_REG) &&
1756 ins->inst_basereg == last_ins->inst_destbasereg &&
1757 ins->inst_offset == last_ins->inst_offset) {
1758 if (ins->dreg == last_ins->sreg1) {
1759 last_ins->next = ins->next;
1763 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1764 ins->opcode = OP_MOVE;
1765 ins->sreg1 = last_ins->sreg1;
1769 * Note: reg1 must be different from the basereg in the second load
1770 * OP_LOAD_MEMBASE offset(basereg), reg1
1771 * OP_LOAD_MEMBASE offset(basereg), reg2
1773 * OP_LOAD_MEMBASE offset(basereg), reg1
1774 * OP_MOVE reg1, reg2
1776 } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
1777 || last_ins->opcode == OP_LOAD_MEMBASE) &&
1778 ins->inst_basereg != last_ins->dreg &&
1779 ins->inst_basereg == last_ins->inst_basereg &&
1780 ins->inst_offset == last_ins->inst_offset) {
1782 if (ins->dreg == last_ins->dreg) {
1783 last_ins->next = ins->next;
1787 ins->opcode = OP_MOVE;
1788 ins->sreg1 = last_ins->dreg;
1791 //g_assert_not_reached ();
1795 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1796 * OP_LOAD_MEMBASE offset(basereg), reg
1798 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
1799 * OP_ICONST reg, imm
1801 } else if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_IMM
1802 || last_ins->opcode == OP_STORE_MEMBASE_IMM) &&
1803 ins->inst_basereg == last_ins->inst_destbasereg &&
1804 ins->inst_offset == last_ins->inst_offset) {
1805 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1806 ins->opcode = OP_ICONST;
1807 ins->inst_c0 = last_ins->inst_imm;
1808 g_assert_not_reached (); // check this rule
1812 case OP_LOADU1_MEMBASE:
1813 case OP_LOADI1_MEMBASE:
1814 if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
1815 ins->inst_basereg == last_ins->inst_destbasereg &&
1816 ins->inst_offset == last_ins->inst_offset) {
1817 if (ins->dreg == last_ins->sreg1) {
1818 last_ins->next = ins->next;
1822 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
1823 ins->opcode = OP_MOVE;
1824 ins->sreg1 = last_ins->sreg1;
1828 case OP_LOADU2_MEMBASE:
1829 case OP_LOADI2_MEMBASE:
1830 if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) &&
1831 ins->inst_basereg == last_ins->inst_destbasereg &&
1832 ins->inst_offset == last_ins->inst_offset) {
1833 if (ins->dreg == last_ins->sreg1) {
1834 last_ins->next = ins->next;
1838 ins->opcode = OP_MOVE;
1839 ins->sreg1 = last_ins->sreg1;
1849 if (ins->dreg == ins->sreg1) {
1851 last_ins->next = ins->next;
1856 * OP_MOVE sreg, dreg
1857 * OP_MOVE dreg, sreg
1859 if (last_ins && last_ins->opcode == OP_MOVE &&
1860 ins->sreg1 == last_ins->dreg &&
1861 ins->dreg == last_ins->sreg1) {
1862 last_ins->next = ins->next;
1871 bb->last_ins = last_ins;
1874 /*========================= End of Function ========================*/
1876 /*------------------------------------------------------------------*/
1878 /* Name - mono_spillvar_offset */
1880 /* Function - Returns the offset used by spillvar. It allocates */
1881 /* a new spill variable if necessary. */
1883 /*------------------------------------------------------------------*/
1886 mono_spillvar_offset (MonoCompile *cfg, int spillvar)
1888 MonoSpillInfo **si, *info;
1891 si = &cfg->spill_info;
1893 while (i <= spillvar) {
1896 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1898 info->offset = cfg->stack_offset;
1899 cfg->stack_offset += sizeof (gpointer);
1903 return (*si)->offset;
1909 g_assert_not_reached ();
1913 /*========================= End of Function ========================*/
1915 /*------------------------------------------------------------------*/
1917 /* Name - mono_spillvar_offset_float */
1921 /*------------------------------------------------------------------*/
1924 mono_spillvar_offset_float (MonoCompile *cfg, int spillvar)
1926 MonoSpillInfo **si, *info;
1929 si = &cfg->spill_info_float;
1931 while (i <= spillvar) {
1934 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1936 cfg->stack_offset = S390_ALIGN(cfg->stack_offset, S390_STACK_ALIGNMENT);
1937 info->offset = cfg->stack_offset;
1938 cfg->stack_offset += sizeof (double);
1942 return (*si)->offset;
1948 g_assert_not_reached ();
1952 /*========================= End of Function ========================*/
1954 /*------------------------------------------------------------------*/
1956 /* Name - print_ins */
1958 /* Function - Decode and print the instruction for tracing. */
1960 /*------------------------------------------------------------------*/
1963 print_ins (int i, MonoInst *ins)
1965 const char *spec = ins_spec [ins->opcode];
1966 g_print ("\t%-2d %s", i, mono_inst_name (ins->opcode));
1967 if (spec [MONO_INST_DEST]) {
1968 if (ins->dreg >= MONO_MAX_IREGS)
1969 g_print (" R%d <-", ins->dreg);
1971 g_print (" %s <-", mono_arch_regname (ins->dreg));
1973 if (spec [MONO_INST_SRC1]) {
1974 if (ins->sreg1 >= MONO_MAX_IREGS)
1975 g_print (" R%d", ins->sreg1);
1977 g_print (" %s", mono_arch_regname (ins->sreg1));
1979 if (spec [MONO_INST_SRC2]) {
1980 if (ins->sreg2 >= MONO_MAX_IREGS)
1981 g_print (" R%d", ins->sreg2);
1983 g_print (" %s", mono_arch_regname (ins->sreg2));
1985 if (spec [MONO_INST_CLOB])
1986 g_print (" clobbers: %c", spec [MONO_INST_CLOB]);
1990 /*========================= End of Function ========================*/
1992 /*------------------------------------------------------------------*/
1994 /* Name - print_regtrack. */
1998 /*------------------------------------------------------------------*/
2001 print_regtrack (RegTrack *t, int num)
2007 for (i = 0; i < num; ++i) {
2010 if (i >= MONO_MAX_IREGS) {
2011 g_snprintf (buf, sizeof(buf), "R%d", i);
2014 r = mono_arch_regname (i);
2015 g_print ("liveness: %s [%d - %d]\n", r, t [i].born_in, t[i].last_use);
2019 /*========================= End of Function ========================*/
2021 /*------------------------------------------------------------------*/
2023 /* Name - inst_list_prepend */
2025 /* Function - Prepend an instruction to the list. */
2027 /*------------------------------------------------------------------*/
2029 static inline InstList*
2030 inst_list_prepend (MonoMemPool *pool, InstList *list, MonoInst *data)
2032 InstList *item = mono_mempool_alloc (pool, sizeof (InstList));
2041 /*========================= End of Function ========================*/
2043 /*------------------------------------------------------------------*/
2045 /* Name - get_register_force_spilling */
2047 /* Function - Force the spilling of the variable in the */
2048 /* symbolic register 'reg'. */
2050 /*------------------------------------------------------------------*/
2053 get_register_force_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, int reg)
2058 sel = cfg->rs->iassign [reg];
2060 spill = ++cfg->spill_count;
2061 cfg->rs->iassign [i] = -spill - 1;
2062 mono_regstate_free_int (cfg->rs, sel);
2063 /*----------------------------------------------------------*/
2064 /* we need to create a spill var and insert a load to sel */
2065 /* after the current instruction */
2066 /*----------------------------------------------------------*/
2067 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2069 load->inst_basereg = cfg->frame_reg;
2070 load->inst_offset = mono_spillvar_offset (cfg, spill);
2072 while (ins->next != item->prev->data)
2075 load->next = ins->next;
2077 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n",
2078 spill, load->inst_offset, i, mono_arch_regname (sel)));
2079 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2080 g_assert (i == sel);
2085 /*========================= End of Function ========================*/
2087 /*------------------------------------------------------------------*/
2089 /* Name - get_register_spilling */
2093 /*------------------------------------------------------------------*/
2096 get_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2101 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));
2102 /* exclude the registers in the current instruction */
2103 if (reg != ins->sreg1 &&
2104 (reg_is_freeable (ins->sreg1) ||
2105 (ins->sreg1 >= MONO_MAX_IREGS &&
2106 cfg->rs->iassign [ins->sreg1] >= 0))) {
2107 if (ins->sreg1 >= MONO_MAX_IREGS)
2108 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg1]);
2110 regmask &= ~ (1 << ins->sreg1);
2111 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2113 if (reg != ins->sreg2 &&
2114 (reg_is_freeable (ins->sreg2) ||
2115 (ins->sreg2 >= MONO_MAX_IREGS &&
2116 cfg->rs->iassign [ins->sreg2] >= 0))) {
2117 if (ins->sreg2 >= MONO_MAX_IREGS)
2118 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg2]);
2120 regmask &= ~ (1 << ins->sreg2);
2121 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2123 if (reg != ins->dreg && reg_is_freeable (ins->dreg)) {
2124 regmask &= ~ (1 << ins->dreg);
2125 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2128 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2129 g_assert (regmask); /* need at least a register we can free */
2131 /* we should track prev_use and spill the register that's farther */
2132 for (i = 0; i < MONO_MAX_IREGS; ++i) {
2133 if (regmask & (1 << i)) {
2135 DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->iassign [sel]));
2139 i = cfg->rs->isymbolic [sel];
2140 spill = ++cfg->spill_count;
2141 cfg->rs->iassign [i] = -spill - 1;
2142 mono_regstate_free_int (cfg->rs, sel);
2143 /* we need to create a spill var and insert a load to sel after the current instruction */
2144 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
2146 load->inst_basereg = cfg->frame_reg;
2147 load->inst_offset = mono_spillvar_offset (cfg, spill);
2149 while (ins->next != item->prev->data)
2152 load->next = ins->next;
2154 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2155 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
2156 g_assert (i == sel);
2161 /*========================= End of Function ========================*/
2163 /*------------------------------------------------------------------*/
2165 /* Name - get_float_register_spilling */
2169 /*------------------------------------------------------------------*/
2172 get_float_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
2177 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));
2178 /* exclude the registers in the current instruction */
2179 if (reg != ins->sreg1 &&
2180 (freg_is_freeable (ins->sreg1) ||
2181 (ins->sreg1 >= MONO_MAX_FREGS &&
2182 cfg->rs->fassign [ins->sreg1] >= 0))) {
2183 if (ins->sreg1 >= MONO_MAX_FREGS)
2184 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg1]);
2186 regmask &= ~ (1 << ins->sreg1);
2187 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
2189 if (reg != ins->sreg2 &&
2190 (freg_is_freeable (ins->sreg2) ||
2191 (ins->sreg2 >= MONO_MAX_FREGS &&
2192 cfg->rs->fassign [ins->sreg2] >= 0))) {
2193 if (ins->sreg2 >= MONO_MAX_FREGS)
2194 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg2]);
2196 regmask &= ~ (1 << ins->sreg2);
2197 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
2199 if (reg != ins->dreg && freg_is_freeable (ins->dreg)) {
2200 regmask &= ~ (1 << ins->dreg);
2201 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
2204 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
2205 g_assert (regmask); /* need at least a register we can free */
2207 /* we should track prev_use and spill the register that's farther */
2208 for (i = 0; i < MONO_MAX_FREGS; ++i) {
2209 if (regmask & (1 << i)) {
2211 DEBUG (g_print ("selected register %s has assignment %d\n",
2212 mono_arch_regname (sel), cfg->rs->fassign [sel]));
2216 i = cfg->rs->fsymbolic [sel];
2217 spill = ++cfg->spill_count;
2218 cfg->rs->fassign [i] = -spill - 1;
2219 mono_regstate_free_float(cfg->rs, sel);
2220 /* we need to create a spill var and insert a load to sel after the current instruction */
2221 MONO_INST_NEW (cfg, load, OP_LOADR8_MEMBASE);
2223 load->inst_basereg = cfg->frame_reg;
2224 load->inst_offset = mono_spillvar_offset_float (cfg, spill);
2226 while (ins->next != item->prev->data)
2229 load->next = ins->next;
2231 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
2232 i = mono_regstate_alloc_float (cfg->rs, 1 << sel);
2233 g_assert (i == sel);
2238 /*========================= End of Function ========================*/
2240 /*------------------------------------------------------------------*/
2242 /* Name - create_copy_ins */
2244 /* Function - Create an instruction to copy from reg to reg. */
2246 /*------------------------------------------------------------------*/
2249 create_copy_ins (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2252 MONO_INST_NEW (cfg, copy, OP_MOVE);
2256 copy->next = ins->next;
2259 DEBUG (g_print ("\tforced copy from %s to %s\n",
2260 mono_arch_regname (src), mono_arch_regname (dest)));
2264 /*========================= End of Function ========================*/
2266 /*------------------------------------------------------------------*/
2268 /* Name - create_copy_ins_float */
2270 /* Function - Create an instruction to copy from float reg to */
2273 /*------------------------------------------------------------------*/
2276 create_copy_ins_float (MonoCompile *cfg, int dest, int src, MonoInst *ins)
2279 MONO_INST_NEW (cfg, copy, OP_FMOVE);
2283 copy->next = ins->next;
2286 DEBUG (g_print ("\tforced copy from %s to %s\n",
2287 mono_arch_regname (src), mono_arch_regname (dest)));
2291 /*========================= End of Function ========================*/
2293 /*------------------------------------------------------------------*/
2295 /* Name - create_spilled_store */
2297 /* Function - Spill register to storage. */
2299 /*------------------------------------------------------------------*/
2302 create_spilled_store (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2305 MONO_INST_NEW (cfg, store, OP_STORE_MEMBASE_REG);
2307 store->inst_destbasereg = cfg->frame_reg;
2308 store->inst_offset = mono_spillvar_offset (cfg, spill);
2310 store->next = ins->next;
2313 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2314 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2318 /*========================= End of Function ========================*/
2320 /*------------------------------------------------------------------*/
2322 /* Name - create_spilled_store_float */
2324 /* Function - Spill floating point register to storage. */
2326 /*------------------------------------------------------------------*/
2329 create_spilled_store_float (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
2332 MONO_INST_NEW (cfg, store, OP_STORER8_MEMBASE_REG);
2334 store->inst_destbasereg = cfg->frame_reg;
2335 store->inst_offset = mono_spillvar_offset_float (cfg, spill);
2337 store->next = ins->next;
2340 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n",
2341 spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
2345 /*========================= End of Function ========================*/
2347 /*------------------------------------------------------------------*/
2349 /* Name - insert_before_ins */
2351 /* Function - Insert an instruction before another. */
2353 /*------------------------------------------------------------------*/
2356 insert_before_ins (MonoInst *ins, InstList *item, MonoInst* to_insert)
2359 g_assert (item->next);
2360 prev = item->next->data;
2362 while (prev->next != ins)
2364 to_insert->next = ins;
2365 prev->next = to_insert;
2367 * needed otherwise in the next instruction we can add an ins to the
2368 * end and that would get past this instruction.
2370 item->data = to_insert;
2373 /*========================= End of Function ========================*/
2375 /*------------------------------------------------------------------*/
2377 /* Name - alloc_int_reg */
2379 /* Function - Allocate a general register. */
2381 /*------------------------------------------------------------------*/
2384 alloc_int_reg (MonoCompile *cfg, InstList *curinst, MonoInst *ins, int sym_reg, guint32 allow_mask)
2386 int val = cfg->rs->iassign [sym_reg];
2390 /* the register gets spilled after this inst */
2393 val = mono_regstate_alloc_int (cfg->rs, allow_mask);
2395 val = get_register_spilling (cfg, curinst, ins, allow_mask, sym_reg);
2396 cfg->rs->iassign [sym_reg] = val;
2397 /* add option to store before the instruction for src registers */
2399 create_spilled_store (cfg, spill, val, sym_reg, ins);
2401 cfg->rs->isymbolic [val] = sym_reg;
2405 /*========================= End of Function ========================*/
2407 /*------------------------------------------------------------------*/
2409 /* Name - mono_arch_local_regalloc. */
2411 /* Function - We first scan the list of instructions and we */
2412 /* save the liveness information of each register */
2413 /* (when the register is first used, when its value */
2414 /* is set etc.). We also reverse the list of instr- */
2415 /* uctions (in the InstList list) because assigning */
2416 /* registers backwards allows for more tricks to be */
2419 /*------------------------------------------------------------------*/
2422 mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
2425 MonoRegState *rs = cfg->rs;
2427 RegTrack *reginfo, *reginfof;
2428 RegTrack *reginfo1, *reginfo2, *reginfod;
2429 InstList *tmp, *reversed = NULL;
2431 guint32 src1_mask, src2_mask, dest_mask;
2432 guint32 cur_iregs, cur_fregs;
2436 rs->next_vireg = bb->max_ireg;
2437 rs->next_vfreg = bb->max_freg;
2438 mono_regstate_assign (rs);
2439 reginfo = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vireg);
2440 reginfof = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vfreg);
2441 rs->ifree_mask = S390_CALLER_REGS;
2442 rs->ffree_mask = S390_CALLER_FREGS;
2446 DEBUG (g_print ("LOCAL regalloc: basic block: %d\n", bb->block_num));
2447 /* forward pass on the instructions to collect register liveness info */
2449 spec = ins_spec [ins->opcode];
2450 DEBUG (print_ins (i, ins));
2451 if (spec [MONO_INST_CLOB] == 'c') {
2452 MonoCallInst * call = (MonoCallInst*)ins;
2455 if (spec [MONO_INST_SRC1]) {
2456 if (spec [MONO_INST_SRC1] == 'f')
2457 reginfo1 = reginfof;
2460 reginfo1 [ins->sreg1].prev_use = reginfo1 [ins->sreg1].last_use;
2461 reginfo1 [ins->sreg1].last_use = i;
2465 if (spec [MONO_INST_SRC2]) {
2466 if (spec [MONO_INST_SRC2] == 'f')
2467 reginfo2 = reginfof;
2470 reginfo2 [ins->sreg2].prev_use = reginfo2 [ins->sreg2].last_use;
2471 reginfo2 [ins->sreg2].last_use = i;
2475 if (spec [MONO_INST_DEST]) {
2476 if (spec [MONO_INST_DEST] == 'f')
2477 reginfod = reginfof;
2480 if (spec [MONO_INST_DEST] != 'b') /* it's not just a base register */
2481 reginfod [ins->dreg].killed_in = i;
2482 reginfod [ins->dreg].prev_use = reginfod [ins->dreg].last_use;
2483 reginfod [ins->dreg].last_use = i;
2484 if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
2485 reginfod [ins->dreg].born_in = i;
2486 if (spec [MONO_INST_DEST] == 'l') {
2487 /* result in eax:edx, the virtual register is allocated sequentially */
2488 reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
2489 reginfod [ins->dreg + 1].last_use = i;
2490 if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
2491 reginfod [ins->dreg + 1].born_in = i;
2496 reversed = inst_list_prepend (cfg->mempool, reversed, ins);
2501 cur_iregs = S390_CALLER_REGS;
2502 cur_fregs = S390_CALLER_FREGS;
2504 DEBUG (print_regtrack (reginfo, rs->next_vireg));
2505 DEBUG (print_regtrack (reginfof, rs->next_vfreg));
2508 int prev_dreg, prev_sreg1, prev_sreg2;
2511 spec = ins_spec [ins->opcode];
2512 DEBUG (g_print ("processing:"));
2513 DEBUG (print_ins (i, ins));
2514 /* make the register available for allocation: FIXME add fp reg */
2515 if (ins->opcode == OP_SETREG || ins->opcode == OP_SETREGIMM) {
2516 cur_iregs |= 1 << ins->dreg;
2517 DEBUG (g_print ("adding %d to cur_iregs\n", ins->dreg));
2518 } else if (ins->opcode == OP_SETFREG) {
2519 cur_fregs |= 1 << ins->dreg;
2520 DEBUG (g_print ("adding %d to cur_fregs\n", ins->dreg));
2521 } else if (spec [MONO_INST_CLOB] == 'c') {
2522 MonoCallInst *cinst = (MonoCallInst*)ins;
2523 DEBUG (g_print ("excluding regs 0x%x from cur_iregs (0x%x)\n", cinst->used_iregs, cur_iregs));
2524 DEBUG (g_print ("excluding fpregs 0x%x from cur_fregs (0x%x)\n", cinst->used_fregs, cur_fregs));
2525 cur_iregs &= ~cinst->used_iregs;
2526 cur_fregs &= ~cinst->used_fregs;
2527 DEBUG (g_print ("available cur_iregs: 0x%x\n", cur_iregs));
2528 DEBUG (g_print ("available cur_fregs: 0x%x\n", cur_fregs));
2529 /* registers used by the calling convention are excluded from
2530 * allocation: they will be selectively enabled when they are
2531 * assigned by the special SETREG opcodes.
2534 dest_mask = src1_mask = src2_mask = cur_iregs;
2535 /* update for use with FP regs... */
2536 if (spec [MONO_INST_DEST] == 'f') {
2537 dest_mask = cur_fregs;
2538 if (ins->dreg >= MONO_MAX_FREGS) {
2539 val = rs->fassign [ins->dreg];
2540 prev_dreg = ins->dreg;
2544 /* the register gets spilled after this inst */
2547 val = mono_regstate_alloc_float (rs, dest_mask);
2549 val = get_float_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2550 rs->fassign [ins->dreg] = val;
2552 create_spilled_store_float (cfg, spill, val, prev_dreg, ins);
2554 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
2555 rs->fsymbolic [val] = prev_dreg;
2557 if (spec [MONO_INST_CLOB] == 'c' && ins->dreg != s390_f0) {
2558 /* this instruction only outputs to s390_f0, need to copy */
2559 create_copy_ins_float (cfg, ins->dreg, s390_f0, ins);
2564 if (freg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i || !(cur_fregs & (1 << ins->dreg)))) {
2565 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2566 mono_regstate_free_float (rs, ins->dreg);
2568 } else if (ins->dreg >= MONO_MAX_IREGS) {
2569 val = rs->iassign [ins->dreg];
2570 prev_dreg = ins->dreg;
2574 /* the register gets spilled after this inst */
2577 val = mono_regstate_alloc_int (rs, dest_mask);
2579 val = get_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
2580 rs->iassign [ins->dreg] = val;
2582 create_spilled_store (cfg, spill, val, prev_dreg, ins);
2584 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
2585 rs->isymbolic [val] = prev_dreg;
2587 if (spec [MONO_INST_DEST] == 'l') {
2588 int hreg = prev_dreg + 1;
2589 val = rs->iassign [hreg];
2593 /* the register gets spilled after this inst */
2596 val = mono_regstate_alloc_int (rs, dest_mask);
2598 val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
2599 rs->iassign [hreg] = val;
2601 create_spilled_store (cfg, spill, val, hreg, ins);
2603 DEBUG (g_print ("\tassigned hreg %s to dest R%d\n", mono_arch_regname (val), hreg));
2604 rs->isymbolic [val] = hreg;
2605 /* FIXME:? ins->dreg = val; */
2606 if (ins->dreg == s390_r3) {
2608 create_copy_ins (cfg, val, s390_r2, ins);
2609 } else if (ins->dreg == s390_r2) {
2610 if (val == s390_r3) {
2612 create_copy_ins (cfg, s390_r3, s390_r0, ins);
2613 create_copy_ins (cfg, s390_r2, s390_r3, ins);
2614 create_copy_ins (cfg, s390_r0, s390_r2, ins);
2616 /* two forced copies */
2617 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2618 create_copy_ins (cfg, val, s390_r2, ins);
2621 if (val == s390_r2) {
2622 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2624 /* two forced copies */
2625 create_copy_ins (cfg, val, s390_r2, ins);
2626 create_copy_ins (cfg, ins->dreg, s390_r3, ins);
2629 if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
2630 DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
2631 mono_regstate_free_int (rs, val);
2633 } else if (spec [MONO_INST_DEST] == 'a' && ins->dreg != s390_r2 && spec [MONO_INST_CLOB] != 'd') {
2634 /* this instruction only outputs to s390_r2, need to copy */
2635 create_copy_ins (cfg, ins->dreg, s390_r2, ins);
2640 if (spec [MONO_INST_DEST] == 'f' &&
2641 freg_is_freeable (ins->dreg) &&
2642 prev_dreg >= 0 && (reginfof [prev_dreg].born_in >= i)) {
2643 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2644 mono_regstate_free_float (rs, ins->dreg);
2645 } else if (spec [MONO_INST_DEST] != 'f' &&
2646 reg_is_freeable (ins->dreg) &&
2647 prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i)) {
2648 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
2649 mono_regstate_free_int (rs, ins->dreg);
2651 if (spec [MONO_INST_SRC1] == 'f') {
2652 src1_mask = cur_fregs;
2653 if (ins->sreg1 >= MONO_MAX_FREGS) {
2654 val = rs->fassign [ins->sreg1];
2655 prev_sreg1 = ins->sreg1;
2659 /* the register gets spilled after this inst */
2662 //g_assert (val == -1); /* source cannot be spilled */
2663 val = mono_regstate_alloc_float (rs, src1_mask);
2665 val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
2666 rs->fassign [ins->sreg1] = val;
2667 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2669 MonoInst *store = create_spilled_store_float (cfg, spill, val, prev_sreg1, NULL);
2670 insert_before_ins (ins, tmp, store);
2673 rs->fsymbolic [val] = prev_sreg1;
2678 } else if (ins->sreg1 >= MONO_MAX_IREGS) {
2679 val = rs->iassign [ins->sreg1];
2680 prev_sreg1 = ins->sreg1;
2684 /* the register gets spilled after this inst */
2686 printf("val: %d spill: %d ins->sreg1: %d\n",val,spill,ins->sreg1);
2688 val = mono_regstate_alloc_int (rs, src1_mask);
2690 val = get_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
2691 rs->iassign [ins->sreg1] = val;
2692 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
2694 MonoInst *store = create_spilled_store (cfg, spill, val, prev_sreg1, NULL);
2695 insert_before_ins (ins, tmp, store);
2698 rs->isymbolic [val] = prev_sreg1;
2703 /*----------------------------------------------*/
2704 /* handle clobbering of sreg1 */
2705 /*----------------------------------------------*/
2706 if ((spec [MONO_INST_CLOB] == '1' ||
2707 spec [MONO_INST_CLOB] == 's') &&
2708 ins->dreg != ins->sreg1) {
2709 MonoInst *copy = create_copy_ins (cfg, ins->dreg, ins->sreg1, NULL);
2710 DEBUG (g_print ("\tneed to copy sreg1 %s to dreg %s\n",
2711 mono_arch_regname (ins->sreg1),
2712 mono_arch_regname (ins->dreg)));
2713 if (ins->sreg2 == -1 || spec [MONO_INST_CLOB] == 's') {
2714 /* note: the copy is inserted before the current instruction! */
2715 insert_before_ins (ins, tmp, copy);
2716 /* we set sreg1 to dest as well */
2717 prev_sreg1 = ins->sreg1 = ins->dreg;
2719 /* inserted after the operation */
2720 copy->next = ins->next;
2725 if (spec [MONO_INST_SRC2] == 'f') {
2726 src2_mask = cur_fregs;
2727 if (ins->sreg2 >= MONO_MAX_FREGS) {
2728 val = rs->fassign [ins->sreg2];
2729 prev_sreg2 = ins->sreg2;
2733 /* the register gets spilled after this inst */
2736 val = mono_regstate_alloc_float (rs, src2_mask);
2738 val = get_float_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2739 rs->fassign [ins->sreg2] = val;
2740 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2742 create_spilled_store_float (cfg, spill, val, prev_sreg2, ins);
2744 rs->fsymbolic [val] = prev_sreg2;
2749 } else if (ins->sreg2 >= MONO_MAX_IREGS) {
2750 val = rs->iassign [ins->sreg2];
2751 prev_sreg2 = ins->sreg2;
2755 /* the register gets spilled after this inst */
2758 val = mono_regstate_alloc_int (rs, src2_mask);
2760 val = get_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
2761 rs->iassign [ins->sreg2] = val;
2762 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
2764 create_spilled_store (cfg, spill, val, prev_sreg2, ins);
2766 rs->isymbolic [val] = prev_sreg2;
2772 if (spec [MONO_INST_CLOB] == 'c') {
2774 guint32 clob_mask = S390_CALLER_REGS;
2775 for (j = 0; j < MONO_MAX_IREGS; ++j) {
2777 if ((clob_mask & s) && !(rs->ifree_mask & s) && j != ins->sreg1) {
2778 //g_warning ("register %s busy at call site\n", mono_arch_regname (j));
2782 /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
2783 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
2784 mono_regstate_free_int (rs, ins->sreg1);
2786 if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
2787 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
2788 mono_regstate_free_int (rs, ins->sreg2);
2791 //DEBUG (print_ins (i, ins));
2796 /*========================= End of Function ========================*/
2798 /*------------------------------------------------------------------*/
2800 /* Name - emit_float_to_int */
2802 /* Function - Create instructions which will convert a floating */
2803 /* point value to integer. */
2805 /*------------------------------------------------------------------*/
2808 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2810 /* sreg is a float, dreg is an integer reg. */
2812 s390_cfdbr (code, dreg, 5, sreg);
2814 s390_basr (code, s390_r13, 0);
2816 s390_double (code, 0x41e0000000000000);
2817 s390_double (code, 0x41f0000000000000);
2818 s390_ldr (code, s390_f0, sreg);
2819 s390_cdb (code, s390_f0, 0, s390_r13, 0);
2821 s390_sdb (code, s390_f0, 0, s390_r13, 8);
2822 s390_cfdbr (code, dreg, 7, s390_f0);
2824 s390_cfdbr (code, dreg, 5, sreg);
2829 /*========================= End of Function ========================*/
2831 /*------------------------------------------------------------------*/
2833 /* Name - mono_emit_stack_alloc */
2837 /*------------------------------------------------------------------*/
2839 static unsigned char*
2840 mono_emit_stack_alloc (guchar *code, MonoInst* tree)
2845 /*========================= End of Function ========================*/
2847 /*------------------------------------------------------------------*/
2849 /* Name - mono_arch_output_basic_block */
2851 /* Function - Perform the "real" work of emitting instructions */
2852 /* that will do the work of in the basic block. */
2854 /*------------------------------------------------------------------*/
2857 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2862 guint8 *code = cfg->native_code + cfg->code_len;
2863 MonoInst *last_ins = NULL;
2864 guint last_offset = 0;
2867 if (cfg->opt & MONO_OPT_PEEPHOLE)
2868 peephole_pass (cfg, bb);
2870 /* we don't align basic blocks of loops on s390 */
2872 if (cfg->verbose_level > 2)
2873 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2875 cpos = bb->max_offset;
2877 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2878 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2879 //g_assert (!mono_compile_aot);
2882 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2883 /* this is not thread save, but good enough */
2884 /* fixme: howto handle overflows? */
2885 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2890 offset = code - cfg->native_code;
2892 max_len = ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
2894 if (offset > (cfg->code_size - max_len - 16)) {
2895 cfg->code_size *= 2;
2896 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2897 code = cfg->native_code + offset;
2900 switch (ins->opcode) {
2901 case OP_STOREI1_MEMBASE_IMM:
2902 s390_lhi (code, s390_r14, ins->inst_imm);
2903 if (s390_is_uimm12(ins->inst_offset))
2904 s390_stc (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2906 s390_basr (code, s390_r13, 0);
2908 s390_word (code, ins->inst_offset);
2909 s390_l (code, s390_r13, 0, s390_r13, 4);
2910 s390_stc (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2913 case OP_STOREI2_MEMBASE_IMM:
2914 s390_lhi (code, s390_r14, ins->inst_imm);
2915 if (s390_is_uimm12(ins->inst_offset)) {
2916 s390_sth (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
2918 s390_basr (code, s390_r14, 0);
2920 s390_word (code, ins->inst_offset);
2921 s390_l (code, s390_r13, 0, s390_r13, 4);
2922 s390_sth (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2925 case OP_STORE_MEMBASE_IMM:
2926 case OP_STOREI4_MEMBASE_IMM:
2927 if (s390_is_imm16(ins->inst_imm)) {
2928 s390_lhi (code, s390_r14, ins->inst_imm);
2930 s390_basr (code, s390_r13, 0);
2932 s390_word (code, ins->inst_imm);
2933 s390_l (code, s390_r14, 0, s390_r13, 4);
2935 if (s390_is_uimm12(ins->inst_offset)) {
2936 s390_st (code, s390_r14, 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_st (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
2945 case OP_STOREI1_MEMBASE_REG:
2946 if (s390_is_uimm12(ins->inst_offset)) {
2947 s390_stc (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_stc (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2956 case OP_STOREI2_MEMBASE_REG:
2957 if (s390_is_uimm12(ins->inst_offset)) {
2958 s390_sth (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
2960 s390_basr (code, s390_r13, 0);
2962 s390_word (code, ins->inst_offset);
2963 s390_l (code, s390_r13, 0, s390_r13, 4);
2964 s390_sth (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2967 case OP_STORE_MEMBASE_REG:
2968 case OP_STOREI4_MEMBASE_REG:
2969 if (s390_is_uimm12(ins->inst_offset)) {
2970 s390_st (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
2972 s390_basr (code, s390_r13, 0);
2974 s390_word (code, ins->inst_offset);
2975 s390_l (code, s390_r13, 0, s390_r13, 4);
2976 s390_st (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
2982 s390_basr (code, s390_r13, 0);
2984 s390_word (code, ins->inst_p0);
2985 s390_l (code, s390_r13, 0, s390_r13, 4);
2986 s390_l (code, ins->dreg, 0, s390_r13, 0);
2989 g_assert_not_reached ();
2991 case OP_LOAD_MEMBASE:
2992 case OP_LOADI4_MEMBASE:
2993 case OP_LOADU4_MEMBASE:
2994 if (s390_is_uimm12(ins->inst_offset))
2995 s390_l (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
2997 s390_basr (code, s390_r13, 0);
2999 s390_word (code, ins->inst_offset);
3000 s390_l (code, s390_r13, 0, s390_r13, 4);
3001 s390_l (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3004 case OP_LOADU1_MEMBASE:
3005 s390_lhi (code, s390_r0, 0);
3006 if (s390_is_uimm12(ins->inst_offset))
3007 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3009 s390_basr (code, s390_r13, 0);
3011 s390_word (code, ins->inst_offset);
3012 s390_l (code, s390_r13, 0, s390_r13, 4);
3013 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3015 s390_lr (code, ins->dreg, s390_r0);
3017 case OP_LOADI1_MEMBASE:
3018 s390_lhi (code, s390_r0, 0);
3019 if (s390_is_uimm12(ins->inst_offset))
3020 s390_ic (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3022 s390_basr (code, s390_r13, 0);
3024 s390_word (code, ins->inst_offset);
3025 s390_l (code, s390_r13, 0, s390_r13, 4);
3026 s390_ic (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3028 s390_lhi (code, s390_r13, 0x80);
3029 s390_nr (code, s390_r13, s390_r0);
3031 s390_lhi (code, s390_r13, 0xff00);
3032 s390_or (code, s390_r0, s390_r13);
3033 s390_lr (code, ins->dreg, s390_r0);
3035 case OP_LOADU2_MEMBASE:
3036 s390_lhi (code, s390_r0, 0);
3037 if (s390_is_uimm12(ins->inst_offset))
3038 s390_icm (code, s390_r0, 3, ins->inst_basereg, ins->inst_offset);
3040 s390_basr (code, s390_r13, 0);
3042 s390_word (code, ins->inst_offset);
3043 s390_l (code, s390_r13, 0, s390_r13, 4);
3044 s390_ar (code, s390_r13, ins->inst_basereg);
3045 s390_icm (code, s390_r0, 3, s390_r13, 0);
3047 s390_lr (code, ins->dreg, s390_r0);
3049 case OP_LOADI2_MEMBASE:
3050 s390_lhi (code, s390_r0, 0);
3051 if (s390_is_uimm12(ins->inst_offset))
3052 s390_lh (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
3054 s390_basr (code, s390_r13, 0);
3056 s390_word (code, ins->inst_offset);
3057 s390_l (code, s390_r13, 0, s390_r13, 4);
3058 s390_lh (code, s390_r0, s390_r13, ins->inst_basereg, 0);
3060 s390_lr (code, ins->dreg, s390_r0);
3063 s390_lhi (code, s390_r0, 0x80);
3064 if (ins->dreg != ins->sreg1) {
3065 s390_lr (code, ins->dreg, ins->sreg1);
3067 s390_nr (code, s390_r0, ins->sreg1);
3069 s390_lhi (code, s390_r13, -1);
3070 s390_sll (code, s390_r13, 0, 8);
3071 s390_or (code, ins->dreg, s390_r13);
3074 s390_lhi (code, s390_r0, 0x80);
3075 s390_lr (code, ins->dreg, ins->sreg1);
3076 s390_nr (code, s390_r0, ins->sreg1);
3078 s390_lhi (code, s390_r13, -1);
3079 s390_sll (code, s390_r13, 0, 16);
3080 s390_or (code, ins->dreg, s390_r13);
3083 s390_lhi (code, s390_r0, 0xff);
3084 if (ins->dreg != ins->sreg1) {
3085 s390_lr (code, ins->dreg, ins->sreg1);
3087 s390_nr (code, ins->dreg, s390_r0);
3090 s390_lhi (code, s390_r0, -1);
3091 s390_sll (code, s390_r0, 0, 16);
3092 s390_srl (code, s390_r0, 0, 16);
3093 if (ins->dreg != ins->sreg1) {
3094 s390_lr (code, ins->dreg, ins->sreg1);
3096 s390_nr (code, ins->dreg, s390_r0);
3100 ((ins->next->opcode >= CEE_BNE_UN) &&
3101 (ins->next->opcode <= CEE_BLT_UN)))
3102 s390_clr (code, ins->sreg1, ins->sreg2);
3104 s390_cr (code, ins->sreg1, ins->sreg2);
3106 case OP_COMPARE_IMM:
3107 if (s390_is_imm16 (ins->inst_imm)) {
3108 s390_lhi (code, s390_r0, ins->inst_imm);
3110 ((ins->next->opcode >= CEE_BNE_UN) &&
3111 (ins->next->opcode <= CEE_BLT_UN)))
3112 s390_clr (code, ins->sreg1, s390_r0);
3114 s390_cr (code, ins->sreg1, s390_r0);
3117 s390_basr (code, s390_r13, 0);
3119 s390_word (code, ins->inst_imm);
3121 ((ins->next->opcode >= CEE_BNE_UN) &&
3122 (ins->next->opcode <= CEE_BLT_UN)))
3123 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3125 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3128 case OP_X86_TEST_NULL:
3129 s390_ltr (code, ins->sreg1, ins->sreg1);
3135 if (ins->dreg != ins->sreg1) {
3136 s390_lr (code, ins->dreg, ins->sreg1);
3138 s390_alr (code, ins->dreg, ins->sreg2);
3141 if (ins->dreg != ins->sreg1) {
3142 s390_lr (code, ins->dreg, ins->sreg1);
3144 s390_ar (code, ins->dreg, ins->sreg2);
3147 if (ins->dreg != ins->sreg1) {
3148 s390_lr (code, ins->dreg, ins->sreg1);
3150 s390_alcr (code, ins->dreg, ins->sreg2);
3154 (ins->next->opcode == OP_ADC_IMM)) {
3155 s390_basr (code, s390_r13, 0);
3157 s390_word (code, ins->inst_imm);
3158 if (ins->dreg != ins->sreg1) {
3159 s390_lr (code, ins->dreg, ins->sreg1);
3161 s390_al (code, ins->dreg, 0, s390_r13, 4);
3163 if (s390_is_imm16 (ins->inst_imm)) {
3164 if (ins->dreg != ins->sreg1) {
3165 s390_lr (code, ins->dreg, ins->sreg1);
3167 s390_ahi (code, ins->dreg, ins->inst_imm);
3169 s390_basr (code, s390_r13, 0);
3171 s390_word (code, ins->inst_imm);
3172 if (ins->dreg != ins->sreg1) {
3173 s390_lr (code, ins->dreg, ins->sreg1);
3175 s390_a (code, ins->dreg, 0, s390_r13, 4);
3180 if (s390_is_imm16 (ins->inst_imm)) {
3181 if (ins->dreg != ins->sreg1) {
3182 s390_lr (code, ins->dreg, ins->sreg1);
3184 s390_lhi (code, s390_r0, ins->inst_imm);
3185 s390_alcr (code, ins->dreg, s390_r0);
3187 s390_basr (code, s390_r13, 0);
3189 s390_word (code, ins->inst_imm);
3190 s390_l (code, s390_r13, 0, s390_r13, 4);
3191 s390_alcr (code, ins->dreg, s390_r13);
3195 if (ins->dreg != ins->sreg1) {
3196 s390_lr (code, ins->dreg, ins->sreg1);
3198 s390_sr (code, ins->dreg, ins->sreg2);
3201 if (ins->dreg != ins->sreg1) {
3202 s390_lr (code, ins->dreg, ins->sreg1);
3204 s390_sr (code, ins->dreg, ins->sreg2);
3207 if (ins->dreg != ins->sreg1) {
3208 s390_lr (code, ins->dreg, ins->sreg1);
3210 s390_slbr (code, ins->dreg, ins->sreg2);
3213 if (s390_is_imm16 (-ins->inst_imm)) {
3214 if (ins->dreg != ins->sreg1) {
3215 s390_lr (code, ins->dreg, ins->sreg1);
3217 s390_ahi (code, ins->dreg, -ins->inst_imm);
3219 s390_basr (code, s390_r13, 0);
3221 s390_word (code, ins->inst_imm);
3222 if (ins->dreg != ins->sreg1) {
3223 s390_lr (code, ins->dreg, ins->sreg1);
3225 s390_s (code, ins->dreg, 0, s390_r13, 4);
3229 s390_basr (code, s390_r13, 0);
3231 s390_word (code, ins->inst_imm);
3232 s390_sl (code, ins->dreg, 0, s390_r13, 4);
3235 if (ins->sreg1 == ins->dreg) {
3236 s390_nr (code, ins->dreg, ins->sreg2);
3239 if (ins->sreg2 == ins->dreg) {
3240 s390_nr (code, ins->dreg, ins->sreg1);
3243 s390_lr (code, ins->dreg, ins->sreg1);
3244 s390_nr (code, ins->dreg, ins->sreg2);
3249 if (s390_is_imm16 (ins->inst_imm)) {
3250 s390_lhi (code, s390_r0, ins->inst_imm);
3251 if (ins->dreg != ins->sreg1) {
3252 s390_lr (code, ins->dreg, ins->sreg1);
3254 s390_nr (code, ins->dreg, s390_r0);
3256 s390_basr (code, s390_r13, 0);
3258 s390_word (code, ins->inst_imm);
3259 if (ins->dreg != ins->sreg1) {
3260 s390_lr (code, ins->dreg, ins->sreg1);
3262 s390_n (code, ins->dreg, 0, s390_r13, 4);
3266 s390_lr (code, s390_r0, ins->sreg1);
3267 s390_srda (code, s390_r0, 0, 32);
3268 s390_dr (code, s390_r0, ins->sreg2);
3269 s390_lr (code, ins->dreg, s390_r1);
3272 s390_lr (code, s390_r0, ins->sreg1);
3273 s390_srdl (code, s390_r0, 0, 32);
3274 s390_dlr (code, s390_r0, ins->sreg2);
3275 s390_lr (code, ins->dreg, s390_r1);
3278 if (s390_is_imm16 (ins->inst_imm)) {
3279 s390_lhi (code, s390_r13, ins->inst_imm);
3280 s390_lr (code, s390_r0, ins->sreg1);
3282 s390_basr (code, s390_r13, 0);
3284 s390_word (code, ins->inst_imm);
3285 s390_lr (code, s390_r0, ins->sreg1);
3286 s390_l (code, s390_r13, 0, s390_r13, 4);
3288 s390_srda (code, s390_r0, 0, 32);
3289 s390_dr (code, s390_r0, ins->sreg2);
3290 s390_lr (code, ins->dreg, s390_r1);
3293 s390_lr (code, s390_r0, ins->sreg1);
3294 s390_srda (code, s390_r0, 0, 32);
3295 s390_dr (code, s390_r0, ins->sreg2);
3296 s390_lr (code, ins->dreg, s390_r0);
3299 s390_lr (code, s390_r0, ins->sreg1);
3300 s390_srdl (code, s390_r0, 0, 32);
3301 s390_dlr (code, s390_r0, ins->sreg2);
3302 s390_lr (code, ins->dreg, s390_r0);
3305 if (s390_is_imm16 (ins->inst_imm)) {
3306 s390_lhi (code, s390_r13, ins->inst_imm);
3307 s390_lr (code, s390_r0, ins->sreg1);
3309 s390_basr (code, s390_r13, 0);
3311 s390_word (code, ins->inst_imm);
3312 s390_lr (code, s390_r0, ins->sreg1);
3313 s390_l (code, s390_r13, 0, s390_r13, 4);
3315 s390_srda (code, s390_r0, 0, 32);
3316 s390_dr (code, s390_r0, ins->sreg2);
3317 s390_lr (code, ins->dreg, s390_r0);
3320 if (ins->sreg1 == ins->dreg) {
3321 s390_or (code, ins->dreg, ins->sreg2);
3324 if (ins->sreg2 == ins->dreg) {
3325 s390_or (code, ins->dreg, ins->sreg1);
3328 s390_lr (code, ins->dreg, ins->sreg1);
3329 s390_or (code, ins->dreg, ins->sreg2);
3334 if (s390_is_imm16 (ins->inst_imm)) {
3335 s390_lhi (code, s390_r0, ins->inst_imm);
3336 if (ins->dreg != ins->sreg1) {
3337 s390_lr (code, ins->dreg, ins->sreg1);
3339 s390_or (code, ins->dreg, s390_r0);
3341 s390_bras (code, s390_r13, 4);
3342 s390_word (code, ins->inst_imm);
3343 if (ins->dreg != ins->sreg1) {
3344 s390_lr (code, ins->dreg, ins->sreg1);
3346 s390_o (code, ins->dreg, 0, s390_r13, 0);
3350 if (ins->sreg1 == ins->dreg) {
3351 s390_xr (code, ins->dreg, ins->sreg2);
3354 if (ins->sreg2 == ins->dreg) {
3355 s390_xr (code, ins->dreg, ins->sreg1);
3358 s390_lr (code, ins->dreg, ins->sreg1);
3359 s390_xr (code, ins->dreg, ins->sreg2);
3364 if (s390_is_imm16 (ins->inst_imm)) {
3365 s390_lhi (code, s390_r0, ins->inst_imm);
3366 if (ins->dreg != ins->sreg1) {
3367 s390_lr (code, ins->dreg, ins->sreg1);
3369 s390_xr (code, ins->dreg, s390_r0);
3371 s390_basr (code, s390_r13, 0);
3373 s390_word (code, ins->inst_imm);
3374 if (ins->dreg != ins->sreg1) {
3375 s390_lr (code, ins->dreg, ins->sreg1);
3377 s390_x (code, ins->dreg, 0, s390_r13, 4);
3381 if (ins->sreg1 != ins->dreg) {
3382 s390_lr (code, ins->dreg, ins->sreg1);
3384 s390_sll (code, ins->dreg, ins->sreg2, 0);
3387 if (ins->sreg1 != ins->dreg) {
3388 s390_lr (code, ins->dreg, ins->sreg1);
3390 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3393 if (ins->sreg1 != ins->dreg) {
3394 s390_lr (code, ins->dreg, ins->sreg1);
3396 s390_sra (code, ins->dreg, ins->sreg2, 0);
3399 if (ins->sreg1 != ins->dreg) {
3400 s390_lr (code, ins->dreg, ins->sreg1);
3402 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3405 if (ins->sreg1 != ins->dreg) {
3406 s390_lr (code, ins->dreg, ins->sreg1);
3408 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3411 if (ins->sreg1 != ins->dreg) {
3412 s390_lr (code, ins->dreg, ins->sreg1);
3414 s390_srl (code, ins->dreg, ins->sreg2, 0);
3417 if (ins->sreg1 != ins->dreg) {
3418 s390_lr (code, ins->dreg, ins->sreg1);
3420 s390_lhi (code, s390_r0, -1);
3421 s390_xr (code, ins->dreg, s390_r0);
3424 s390_lcr (code, ins->dreg, ins->sreg1);
3427 if (ins->sreg1 == ins->dreg) {
3428 s390_msr (code, ins->dreg, ins->sreg2);
3431 if (ins->sreg2 == ins->dreg) {
3432 s390_msr (code, ins->dreg, ins->sreg1);
3435 s390_lr (code, ins->dreg, ins->sreg1);
3436 s390_msr (code, ins->dreg, ins->sreg2);
3441 if (s390_is_imm16 (ins->inst_imm)) {
3442 s390_lhi (code, s390_r13, ins->inst_imm);
3444 s390_basr (code, s390_r13, 0);
3446 s390_word (code, ins->inst_imm);
3447 if (ins->dreg != ins->sreg1) {
3448 s390_lr (code, ins->dreg, ins->sreg1);
3450 s390_l (code, s390_r13, 0, s390_r13, 4);
3452 s390_msr (code, ins->dreg, s390_r13);
3455 s390_lhi (code, s390_r0, 0);
3456 s390_lr (code, s390_r1, ins->sreg1);
3457 s390_mr (code, s390_r0, ins->sreg2);
3458 s390_ltr (code, s390_r0, s390_r0);
3459 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3460 s390_lr (code, ins->dreg, s390_r1);
3462 case CEE_MUL_OVF_UN:
3463 s390_lhi (code, s390_r0, 0);
3464 s390_lr (code, s390_r1, ins->sreg1);
3465 s390_mlr (code, s390_r0, ins->sreg2);
3466 s390_ltr (code, s390_r0, s390_r0);
3467 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3468 s390_lr (code, ins->dreg, s390_r1);
3471 s390_l (code, s390_r0, 0, ins->sreg1, 4);
3472 s390_lr (code, s390_r14, s390_r0);
3473 s390_srda (code, s390_r0, 0, 32);
3474 s390_m (code, s390_r0, 0, ins->sreg2, 4);
3475 s390_srl (code, s390_r14, 0, 31);
3476 s390_a (code, s390_r14, 0, ins->sreg1, 0);
3477 s390_l (code, s390_r13, 0, ins->sreg2, 0);
3478 s390_srl (code, s390_r13, 0, 31);
3479 s390_ms (code, s390_r13, 0, ins->sreg1, 4);
3480 s390_ar (code, s390_r14, s390_r13);
3481 s390_st (code, s390_r14, 0, ins->dreg, 0);
3482 s390_st (code, s390_r1, 0, ins->dreg, 4);
3486 if (s390_is_imm16(ins->inst_c0)) {
3487 s390_lhi (code, ins->dreg, ins->inst_c0);
3489 s390_basr (code, s390_r13, 0);
3491 s390_word (code, ins->inst_c0);
3492 s390_l (code, ins->dreg, 0, s390_r13, 4);
3496 s390_basr (code, s390_r13, 0);
3498 mono_add_patch_info (cfg, code - cfg->native_code,
3499 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3500 s390_word (code, 0);
3501 s390_l (code,ins->dreg, 0, s390_r13, 4);
3507 if (ins->dreg != ins->sreg1) {
3508 s390_lr (code, ins->dreg, ins->sreg1);
3512 int saved = ins->sreg1;
3513 if (ins->sreg1 == s390_r2) {
3514 s390_lr (code, s390_r0, ins->sreg1);
3517 if (ins->sreg2 != s390_r2)
3518 s390_lr (code, s390_r2, ins->sreg2);
3519 if (saved != s390_r3)
3520 s390_lr (code, s390_r3, saved);
3525 if (ins->dreg != ins->sreg1) {
3526 s390_ldr (code, ins->dreg, ins->sreg1);
3529 case OP_FCONV_TO_R4:
3530 s390_ledbr (code, ins->dreg, ins->sreg1);
3533 g_assert_not_reached ();
3536 /* ensure ins->sreg1 is not NULL */
3537 s390_icm (code, s390_r0, 15, ins->sreg1, 0);
3544 call = (MonoCallInst*)ins;
3545 if (ins->flags & MONO_INST_HAS_METHOD)
3546 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method);
3548 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr);
3549 s390_brasl (code, s390_r14, 0);
3554 case OP_VOIDCALL_REG:
3556 s390_lr (code, s390_r1, ins->sreg1);
3557 s390_basr (code, s390_r14, s390_r1);
3559 case OP_FCALL_MEMBASE:
3560 case OP_LCALL_MEMBASE:
3561 case OP_VCALL_MEMBASE:
3562 case OP_VOIDCALL_MEMBASE:
3563 case OP_CALL_MEMBASE:
3564 s390_l (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3565 s390_basr (code, s390_r14, s390_r1);
3568 g_assert_not_reached ();
3571 s390_lr (code, s390_r1, ins->sreg1);
3572 s390_ahi (code, s390_r1, 14);
3573 s390_srl (code, s390_r1, 0, 3);
3574 s390_sll (code, s390_r1, 0, 3);
3575 s390_l (code, s390_r13, 0, STK_BASE, 0);
3576 s390_lcr (code, s390_r1, s390_r1);
3577 s390_la (code, STK_BASE, STK_BASE, s390_r1, 0);
3578 s390_st (code, s390_r13, 0, STK_BASE, 0);
3579 s390_la (code, ins->dreg, 0, STK_BASE, S390_MINIMAL_STACK_SIZE+7);
3580 s390_srl (code, ins->dreg, 0, 3);
3581 s390_sll (code, ins->dreg, 0, 3);
3584 s390_br (code, s390_r14);
3587 s390_lr (code, s390_r2, ins->sreg1);
3588 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3589 (gpointer)"mono_arch_throw_exception");
3590 s390_brasl (code, s390_r14, 0);
3593 case OP_START_HANDLER:
3594 s390_lr (code, s390_r0, s390_r14);
3595 s390_st (code, s390_r0, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3598 if (ins->sreg1 != s390_r2)
3599 s390_lr (code, s390_r2, ins->sreg1);
3600 s390_l (code, STK_BASE, 0, STK_BASE, 0);
3601 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
3602 s390_br (code, s390_r14);
3604 case CEE_ENDFINALLY:
3605 s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
3606 s390_br (code, s390_r14);
3608 case OP_CALL_HANDLER:
3609 mono_add_patch_info (cfg, code-cfg->native_code,
3610 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3611 s390_brasl (code, s390_r14, 0);
3614 ins->inst_c0 = code - cfg->native_code;
3617 EMIT_UNCOND_BRANCH(ins);
3620 s390_br (code, ins->sreg1);
3623 s390_lhi (code, ins->dreg, 1);
3625 s390_lhi (code, ins->dreg, 0);
3628 s390_lhi (code, ins->dreg, 1);
3630 s390_lhi (code, ins->dreg, 0);
3633 s390_lhi (code, ins->dreg, 1);
3635 s390_lhi (code, ins->dreg, 0);
3638 s390_lhi (code, ins->dreg, 1);
3640 s390_lhi (code, ins->dreg, 0);
3643 s390_lhi (code, ins->dreg, 1);
3645 s390_lhi (code, ins->dreg, 0);
3647 case OP_COND_EXC_EQ:
3648 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
3650 case OP_COND_EXC_NE_UN:
3651 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
3653 case OP_COND_EXC_LT:
3654 case OP_COND_EXC_LT_UN:
3655 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
3657 case OP_COND_EXC_GT:
3658 case OP_COND_EXC_GT_UN:
3659 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
3661 case OP_COND_EXC_GE:
3662 case OP_COND_EXC_GE_UN:
3663 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
3665 case OP_COND_EXC_LE:
3666 case OP_COND_EXC_LE_UN:
3667 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
3669 case OP_COND_EXC_OV:
3670 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
3672 case OP_COND_EXC_NO:
3673 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
3676 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
3678 case OP_COND_EXC_NC:
3679 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
3682 EMIT_COND_BRANCH (ins, S390_CC_EQ);
3685 EMIT_COND_BRANCH (ins, S390_CC_NE);
3689 EMIT_COND_BRANCH (ins, S390_CC_LT);
3693 EMIT_COND_BRANCH (ins, S390_CC_GT);
3697 EMIT_COND_BRANCH (ins, S390_CC_GE);
3701 EMIT_COND_BRANCH (ins, S390_CC_LE);
3704 /* floating point opcodes */
3706 if (*((float *) ins->inst_p0) == 0) {
3707 s390_lzdr (code, ins->dreg);
3709 s390_basr (code, s390_r13, 0);
3711 s390_word (code, ins->inst_p0);
3712 s390_l (code, s390_r13, 0, s390_r13, 4);
3713 s390_ld (code, ins->dreg, 0, s390_r13, 0);
3717 if (*((float *) ins->inst_p0) == 0) {
3718 s390_lzer (code, ins->dreg);
3720 s390_basr (code, s390_r13, 0);
3722 s390_word (code, ins->inst_p0);
3723 s390_l (code, s390_r13, 0, s390_r13, 4);
3724 s390_le (code, ins->dreg, 0, s390_r13, 0);
3725 s390_ldebr(code, ins->dreg, ins->dreg);
3728 case OP_STORER8_MEMBASE_REG:
3729 if (s390_is_uimm12(ins->inst_offset)) {
3730 s390_std (code, ins->sreg1, 0, ins->inst_destbasereg, ins->inst_offset);
3732 s390_basr (code, s390_r13, 0);
3734 s390_word (code, ins->inst_offset);
3735 s390_l (code, s390_r13, 0, s390_r13, 4);
3736 s390_std (code, ins->sreg1, s390_r13, ins->inst_destbasereg, 0);
3739 case OP_LOADR8_MEMBASE:
3740 if (s390_is_uimm12(ins->inst_offset)) {
3741 s390_ld (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3743 s390_basr (code, s390_r13, 0);
3745 s390_word (code, ins->inst_offset);
3746 s390_l (code, s390_r13, 0, s390_r13, 4);
3747 s390_ld (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3750 case OP_STORER4_MEMBASE_REG:
3751 if (s390_is_uimm12(ins->inst_offset)) {
3752 s390_ledbr(code, s390_f0, ins->sreg1);
3753 s390_ste (code, s390_f0, 0, ins->inst_destbasereg, ins->inst_offset);
3755 s390_basr (code, s390_r13, 0);
3757 s390_word (code, ins->inst_offset);
3758 s390_l (code, s390_r13, 0, s390_r13, 4);
3759 s390_ledbr(code, s390_f0, ins->sreg1);
3760 s390_ste (code, s390_f0, s390_r13, ins->inst_destbasereg, 0);
3763 case OP_LOADR4_MEMBASE:
3764 if (s390_is_uimm12(ins->inst_offset)) {
3765 s390_le (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
3767 s390_basr (code, s390_r13, 0);
3769 s390_word (code, ins->inst_offset);
3770 s390_l (code, s390_r13, 0, s390_r13, 4);
3771 s390_le (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
3773 s390_ldebr (code, ins->dreg, ins->dreg);
3776 s390_cdfbr (code, ins->dreg, ins->sreg1);
3777 s390_ltr (code, ins->sreg1, ins->sreg1);
3778 s390_jnl (code, 12);
3779 s390_basr (code, s390_r13, 0);
3781 s390_word (code, 0x41f00000);
3782 s390_word (code, 0);
3783 s390_adb (code, ins->dreg, 0, s390_r13, 4);
3786 s390_cefbr (code, ins->dreg, ins->sreg1);
3789 s390_cdfbr (code, ins->dreg, ins->sreg1);
3791 case OP_FCONV_TO_I1:
3792 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
3794 case OP_FCONV_TO_U1:
3795 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
3797 case OP_FCONV_TO_I2:
3798 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
3800 case OP_FCONV_TO_U2:
3801 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
3803 case OP_FCONV_TO_I4:
3805 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
3807 case OP_FCONV_TO_U4:
3809 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
3811 case OP_FCONV_TO_I8:
3812 case OP_FCONV_TO_U8:
3813 g_assert_not_reached ();
3814 /* Implemented as helper calls */
3816 case OP_LCONV_TO_R_UN:
3817 g_assert_not_reached ();
3818 /* Implemented as helper calls */
3820 case OP_LCONV_TO_OVF_I: {
3821 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
3823 s390_ltr (code, ins->sreg2, ins->sreg2);
3824 s390_jnl (code, 0); CODEPTR(code, o[0]);
3825 s390_ltr (code, ins->sreg1, ins->sreg1);
3826 s390_jnl (code, 0); CODEPTR(code, o[1]);
3827 s390_lhi (code, s390_r13, -1);
3828 s390_cr (code, ins->sreg1, s390_r13);
3829 s390_jnz (code, 0); CODEPTR(code, o[2]);
3830 if (ins->dreg != ins->sreg2)
3831 s390_lr (code, ins->dreg, ins->sreg2);
3832 s390_j (code, 0); CODEPTR(code, o[3]);
3833 PTRSLOT(code, o[0]);
3834 s390_jz (code, 0); CODEPTR(code, o[4]);
3835 PTRSLOT(code, o[1]);
3836 PTRSLOT(code, o[2]);
3837 mono_add_patch_info (cfg, code - cfg->native_code,
3838 MONO_PATCH_INFO_EXC, "OverflowException");
3839 s390_brasl (code, s390_r14, 0);
3840 PTRSLOT(code, o[3]);
3841 PTRSLOT(code, o[4]);
3845 s390_sqdbr (code, ins->dreg, ins->sreg1);
3848 if (ins->dreg == ins->sreg1)
3849 s390_adbr (code, ins->dreg, ins->sreg2);
3851 if (ins->dreg == ins->sreg2)
3852 s390_adbr (code, ins->dreg, ins->sreg1);
3854 s390_ldr (code, ins->dreg, ins->sreg1);
3855 s390_adbr (code, ins->dreg, ins->sreg2);
3860 if (ins->dreg == ins->sreg1)
3861 s390_sdbr (code, ins->dreg, ins->sreg2);
3863 s390_ldr (code, ins->dreg, ins->sreg1);
3864 s390_sdbr (code, ins->dreg, ins->sreg2);
3868 if (ins->dreg == ins->sreg1)
3869 s390_mdbr (code, ins->dreg, ins->sreg2);
3871 if (ins->dreg == ins->sreg2)
3872 s390_mdbr (code, ins->dreg, ins->sreg1);
3874 s390_ldr (code, ins->dreg, ins->sreg1);
3875 s390_mdbr (code, ins->dreg, ins->sreg2);
3880 if (ins->dreg == ins->sreg1)
3881 s390_ddbr (code, ins->dreg, ins->sreg2);
3883 s390_ldr (code, ins->dreg, ins->sreg1);
3884 s390_ddbr (code, ins->dreg, ins->sreg2);
3888 s390_lcdbr (code, ins->dreg, ins->sreg1);
3891 if (ins->dreg != ins->sreg1) {
3892 s390_ldr (code, ins->dreg, ins->sreg1);
3894 s390_didbr (code, ins->dreg, ins->sreg2, 5, s390_f15);
3897 s390_cdbr (code, ins->sreg1, ins->sreg2);
3900 s390_cdbr (code, ins->sreg1, ins->sreg2);
3901 s390_lhi (code, ins->dreg, 1);
3903 s390_lhi (code, ins->dreg, 0);
3906 s390_cdbr (code, ins->sreg1, ins->sreg2);
3907 s390_lhi (code, ins->dreg, 1);
3909 s390_lhi (code, ins->dreg, 0);
3912 s390_cdbr (code, ins->sreg1, ins->sreg2);
3913 s390_lhi (code, ins->dreg, 1);
3915 s390_lhi (code, ins->dreg, 0);
3918 s390_cdbr (code, ins->sreg1, ins->sreg2);
3919 s390_lhi (code, ins->dreg, 1);
3921 s390_lhi (code, ins->dreg, 0);
3924 s390_cdbr (code, ins->sreg1, ins->sreg2);
3925 s390_lhi (code, ins->dreg, 1);
3927 s390_lhi (code, ins->dreg, 0);
3930 EMIT_COND_BRANCH (ins, S390_CC_EQ|S390_CC_OV);
3933 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
3936 EMIT_COND_BRANCH (ins, S390_CC_LT);
3939 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
3942 EMIT_COND_BRANCH (ins, S390_CC_GT);
3945 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
3948 EMIT_COND_BRANCH (ins, S390_CC_GE);
3951 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
3954 EMIT_COND_BRANCH (ins, S390_CC_LE);
3957 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
3959 case CEE_CKFINITE: {
3961 s390_lhi (code, s390_r13, 0xfc0);
3962 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
3963 s390_jz (code, 0); CODEPTR(code, o);
3964 mono_add_patch_info (cfg, code - cfg->native_code + 2,
3965 MONO_PATCH_INFO_EXC, "ArithmeticException");
3966 s390_brasl (code, s390_r14,0);
3971 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
3972 g_assert_not_reached ();
3975 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
3976 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
3977 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
3978 g_assert_not_reached ();
3984 last_offset = offset;
3989 cfg->code_len = code - cfg->native_code;
3992 /*========================= End of Function ========================*/
3994 /*------------------------------------------------------------------*/
3996 /* Name - mono_arch_register_lowlevel_calls */
3998 /* Function - Register routines to help with --trace operation. */
4000 /*------------------------------------------------------------------*/
4003 mono_arch_register_lowlevel_calls (void)
4005 mono_register_jit_icall (enter_method, "mono_enter_method", NULL, TRUE);
4006 mono_register_jit_icall (leave_method, "mono_leave_method", NULL, TRUE);
4009 /*========================= End of Function ========================*/
4011 /*------------------------------------------------------------------*/
4013 /* Name - mono_arch_patch_code */
4015 /* Function - Process the patch data created during the */
4016 /* instruction build process. This resolves jumps, */
4017 /* calls, variables etc. */
4019 /*------------------------------------------------------------------*/
4022 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4024 MonoJumpInfo *patch_info;
4026 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4027 unsigned char *ip = patch_info->ip.i + code;
4030 switch (patch_info->type) {
4031 case MONO_PATCH_INFO_BB:
4032 target = S390_RELATIVE((patch_info->data.bb->native_offset+code),
4034 ip += 2; /* Skip over op-code */
4036 case MONO_PATCH_INFO_ABS:
4037 target = S390_RELATIVE(patch_info->data.target, ip);
4038 ip += 2; /* Skip over op-code */
4040 case MONO_PATCH_INFO_LABEL:
4041 target = S390_RELATIVE((patch_info->data.inst->inst_c0+code),ip);
4042 ip += 2; /* Skip over op-code */
4044 case MONO_PATCH_INFO_IP:
4047 case MONO_PATCH_INFO_METHOD_REL:
4048 g_assert_not_reached ();
4049 *((gpointer *)(ip)) = code + patch_info->data.offset;
4051 case MONO_PATCH_INFO_INTERNAL_METHOD: {
4052 MonoJitICallInfo *mi = mono_find_jit_icall_by_name (patch_info->data.name);
4054 g_warning ("unknown MONO_PATCH_INFO_INTERNAL_METHOD %s", patch_info->data.name);
4055 g_assert_not_reached ();
4057 target = S390_RELATIVE(mono_icall_get_wrapper (mi), ip);
4058 ip += 2; /* Skip over op-code */
4061 case MONO_PATCH_INFO_METHOD_JUMP:
4062 g_assert_not_reached ();
4064 case MONO_PATCH_INFO_METHOD:
4065 if (patch_info->data.method == method) {
4066 target = S390_RELATIVE(code, ip);
4068 /* get the trampoline to the method from the domain */
4069 target = S390_RELATIVE(mono_arch_create_jit_trampoline (patch_info->data.method), ip);
4070 target = mono_arch_create_jit_trampoline(patch_info->data.method);
4071 target = S390_RELATIVE(target, ip);
4073 ip += 2; /* Skip over op-code */
4075 case MONO_PATCH_INFO_SWITCH: {
4076 gpointer *table = (gpointer *)patch_info->data.target;
4078 /*------------------------------------------------------*/
4079 /* ip is pointing at the basr r13,0/j +4 instruction */
4080 /* the vtable value follows this (i.e. ip+6) */
4081 /*------------------------------------------------------*/
4082 *((gconstpointer *)(ip+6)) = table;
4084 for (i = 0; i < patch_info->table_size; i++) {
4085 table [i] = (int)patch_info->data.table [i] + code;
4089 case MONO_PATCH_INFO_METHODCONST:
4090 case MONO_PATCH_INFO_CLASS:
4091 case MONO_PATCH_INFO_IMAGE:
4092 case MONO_PATCH_INFO_FIELD:
4093 target = S390_RELATIVE(patch_info->data.target, ip);
4095 case MONO_PATCH_INFO_R4:
4096 case MONO_PATCH_INFO_R8:
4097 g_assert_not_reached ();
4098 *((gconstpointer *)(ip + 2)) = patch_info->data.target;
4100 case MONO_PATCH_INFO_IID:
4101 mono_class_init (patch_info->data.klass);
4102 target = S390_RELATIVE(patch_info->data.klass->interface_id, ip);
4104 case MONO_PATCH_INFO_VTABLE:
4105 target = S390_RELATIVE(mono_class_vtable (domain, patch_info->data.klass),ip);
4108 case MONO_PATCH_INFO_CLASS_INIT:
4109 target = S390_RELATIVE(mono_create_class_init_trampoline (mono_class_vtable (domain, patch_info->data.klass)), ip);
4112 case MONO_PATCH_INFO_SFLDA: {
4113 MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
4114 if (!vtable->initialized && !(vtable->klass->flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT) && mono_class_needs_cctor_run (vtable->klass, method))
4115 /* Done by the generated code */
4119 mono_runtime_class_init (vtable);
4121 target = S390_RELATIVE((char*)vtable->data + patch_info->data.field->offset, ip);
4125 case MONO_PATCH_INFO_EXC_NAME:
4126 *((gconstpointer *)(ip)) = patch_info->data.name;
4128 case MONO_PATCH_INFO_LDSTR:
4129 target = mono_ldstr (domain, patch_info->data.token->image,
4130 mono_metadata_token_index (patch_info->data.token->token));
4132 case MONO_PATCH_INFO_TYPE_FROM_HANDLE: {
4134 MonoClass *handle_class;
4136 handle = mono_ldtoken (patch_info->data.token->image,
4137 patch_info->data.token->token,
4138 &handle_class, NULL);
4139 mono_class_init (handle_class);
4140 mono_class_init (mono_class_from_mono_type (handle));
4145 case MONO_PATCH_INFO_LDTOKEN: {
4147 MonoClass *handle_class;
4149 handle = mono_ldtoken (patch_info->data.token->image,
4150 patch_info->data.token->token,
4151 &handle_class, NULL);
4152 mono_class_init (handle_class);
4157 case MONO_PATCH_INFO_EXC:
4158 /* everything is dealt with at epilog output time */
4161 g_assert_not_reached ();
4163 s390_patch (ip, target);
4167 /*========================= End of Function ========================*/
4169 /*------------------------------------------------------------------*/
4171 /* Name - mono_arch_max_epilog_size */
4173 /* Function - Determine the maximum size of the epilog code. */
4175 /*------------------------------------------------------------------*/
4178 mono_arch_max_epilog_size (MonoCompile *cfg)
4180 int max_epilog_size = 96;
4181 MonoJumpInfo *patch_info;
4183 if (cfg->method->save_lmf)
4184 max_epilog_size += 128;
4186 if (mono_jit_trace_calls != NULL)
4187 max_epilog_size += 128;
4189 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4190 max_epilog_size += 128;
4192 /* count the number of exception infos */
4194 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4195 if (patch_info->type == MONO_PATCH_INFO_EXC)
4196 max_epilog_size += 26;
4199 return max_epilog_size;
4202 /*========================= End of Function ========================*/
4204 /*------------------------------------------------------------------*/
4206 /* Name - mono_arch_emit_prolog */
4208 /* Function - Create the instruction sequence for a function */
4211 /*------------------------------------------------------------------*/
4214 mono_arch_emit_prolog (MonoCompile *cfg)
4216 MonoMethod *method = cfg->method;
4218 MonoMethodSignature *sig;
4220 int alloc_size, pos, max_offset, i, lmfOffset;
4226 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
4229 cfg->code_size = 256;
4230 cfg->native_code = code = g_malloc (cfg->code_size);
4232 s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4234 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4235 cfg->used_int_regs |= 1 << 11;
4238 alloc_size = cfg->stack_offset;
4240 // alloc_size += S390_TRACE_STACK_SIZE;
4242 /* reserve room to save return value */
4246 // alloc_size += pos;
4248 // if (method->save_lmf)
4249 // alloc_size += sizeof(MonoLMF);
4251 // alloc_size = S390_ALIGN(alloc_size, S390_STACK_ALIGNMENT);
4253 cfg->stack_usage = alloc_size;
4254 s390_lr (code, s390_r11, STK_BASE);
4255 if (s390_is_imm16 (-alloc_size)) {
4256 s390_ahi (code, STK_BASE, -alloc_size);
4258 int stackSize = alloc_size;
4259 while (stackSize > 32767) {
4260 s390_ahi (code, STK_BASE, -32767);
4263 s390_ahi (code, STK_BASE, -stackSize);
4265 s390_st (code, s390_r11, 0, STK_BASE, 0);
4267 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
4268 s390_lr (code, s390_r11, STK_BASE);
4270 /* compute max_offset in order to use short forward jumps
4271 * we always do it on s390 because the immediate displacement
4272 * for jumps is too small
4275 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4276 MonoInst *ins = bb->code;
4277 bb->max_offset = max_offset;
4279 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4283 max_offset += ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
4288 /* load arguments allocated to register from the stack */
4289 sig = method->signature;
4292 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
4294 if (cinfo->struct_ret) {
4295 ArgInfo *ainfo = &cinfo->ret;
4297 inst->unused = ainfo->vtsize;
4298 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4301 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4302 ArgInfo *ainfo = cinfo->args + i;
4303 inst = cfg->varinfo [pos];
4305 if (inst->opcode == OP_REGVAR) {
4306 if (ainfo->regtype == RegTypeGeneral)
4307 s390_lr (code, inst->dreg, ainfo->reg);
4308 else if (ainfo->regtype == RegTypeFP) {
4309 if (ainfo->size == 4) {
4310 s390_ledbr (code, inst->dreg, ainfo->reg);
4312 s390_ldr (code, inst->dreg, ainfo->reg);
4315 else if (ainfo->regtype == RegTypeBase) {
4316 s390_lr (code, s390_r13, STK_BASE);
4317 s390_ahi (code, s390_r13, alloc_size);
4318 s390_l (code, inst->dreg, 0, s390_r13, ainfo->offset);
4320 g_assert_not_reached ();
4322 if (cfg->verbose_level > 2)
4323 g_print ("Argument %d assigned to register %s\n",
4324 pos, mono_arch_regname (inst->dreg));
4326 if (ainfo->regtype == RegTypeGeneral) {
4327 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4328 g_assert_not_reached();
4329 switch (ainfo->size) {
4331 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4334 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4337 s390_stm (code, ainfo->reg, ainfo->reg + 1,
4338 inst->inst_basereg, inst->inst_offset);
4341 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4343 } else if (ainfo->regtype == RegTypeBase) {
4344 } else if (ainfo->regtype == RegTypeFP) {
4345 if (ainfo->size == 8)
4346 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4347 else if (ainfo->size == 4)
4348 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4350 g_assert_not_reached ();
4351 } else if (ainfo->regtype == RegTypeStructByVal) {
4352 int doffset = inst->inst_offset;
4354 if (ainfo->reg != STK_BASE)
4358 s390_lr (code, s390_r13, STK_BASE);
4359 s390_ahi (code, s390_r13, alloc_size);
4361 switch (ainfo->size) {
4363 if (ainfo->reg == STK_BASE)
4364 s390_ic (code, reg, 0, s390_r13, ainfo->offset+3);
4365 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4368 if (ainfo->reg == STK_BASE)
4369 s390_lh (code, reg, 0, s390_r13, ainfo->offset+2);
4370 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4373 if (ainfo->reg == STK_BASE)
4374 s390_l (code, reg, 0, s390_r13, ainfo->offset);
4375 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4378 if (ainfo->reg == STK_BASE)
4379 s390_lm (code, s390_r0, s390_r1, s390_r13, ainfo->offset);
4380 s390_stm (code, reg, reg+1, inst->inst_basereg, doffset);
4383 } else if (ainfo->regtype == RegTypeStructByAddr) {
4384 code = emit_memcpy (code, ainfo->vtsize,
4385 inst->inst_basereg, inst->inst_offset, ainfo->reg, 0);
4387 g_assert_not_reached ();
4392 if (method->save_lmf) {
4393 /*---------------------------------------------------------------*/
4394 /* Preserve the parameter registers while we fix up the lmf */
4395 /*---------------------------------------------------------------*/
4396 s390_lr (code, s390_r7, s390_r2);
4397 s390_lr (code, s390_r8, s390_r3);
4398 s390_lr (code, s390_r9, s390_r4);
4399 s390_lr (code, s390_r10, s390_r5);
4401 mono_add_patch_info (cfg, code - cfg->native_code,
4402 MONO_PATCH_INFO_INTERNAL_METHOD,
4403 (gpointer)"mono_get_lmf_addr");
4404 /*---------------------------------------------------------------*/
4405 /* On return from this call r2 have the address of the &lmf */
4406 /*---------------------------------------------------------------*/
4407 s390_brasl (code, s390_r14, 0);
4409 /*---------------------------------------------------------------*/
4410 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4411 /*---------------------------------------------------------------*/
4412 lmfOffset = alloc_size - sizeof(MonoLMF);
4414 s390_lr (code, s390_r13, cfg->frame_reg);
4415 s390_ahi (code, s390_r13, lmfOffset);
4417 /*---------------------------------------------------------------*/
4418 /* Set lmf.lmf_addr = jit_tls->lmf */
4419 /*---------------------------------------------------------------*/
4420 s390_st (code, s390_r2, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4422 /*---------------------------------------------------------------*/
4423 /* Get current lmf */
4424 /*---------------------------------------------------------------*/
4425 s390_l (code, s390_r0, 0, s390_r2, 0);
4427 /*---------------------------------------------------------------*/
4428 /* Set our lmf as the current lmf */
4429 /*---------------------------------------------------------------*/
4430 s390_st (code, s390_r13, 0, s390_r2, 0);
4432 /*---------------------------------------------------------------*/
4433 /* Have our lmf.previous_lmf point to the last lmf */
4434 /*---------------------------------------------------------------*/
4435 s390_st (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4437 /*---------------------------------------------------------------*/
4438 /* save method info */
4439 /*---------------------------------------------------------------*/
4440 s390_basr (code, s390_r1, 0);
4442 s390_word (code, method);
4443 s390_l (code, s390_r1, 0, s390_r1, 4);
4444 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, method));
4446 /*---------------------------------------------------------------*/
4447 /* save the current IP */
4448 /*---------------------------------------------------------------*/
4449 s390_lr (code, s390_r1, cfg->frame_reg);
4450 s390_ahi (code, s390_r1, alloc_size);
4451 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4452 s390_l (code, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
4453 s390_la (code, s390_r1, 0, s390_r1, 0);
4454 s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4456 /*---------------------------------------------------------------*/
4457 /* Restore the parameter registers now that we've set up the lmf */
4458 /*---------------------------------------------------------------*/
4459 s390_lr (code, s390_r2, s390_r7);
4460 s390_lr (code, s390_r3, s390_r8);
4461 s390_lr (code, s390_r4, s390_r9);
4462 s390_lr (code, s390_r5, s390_r10);
4466 code = mono_arch_instrument_prolog (cfg, enter_method, code, TRUE);
4468 cfg->code_len = code - cfg->native_code;
4474 /*========================= End of Function ========================*/
4476 /*------------------------------------------------------------------*/
4478 /* Name - mono_arch_emit_epilog */
4480 /* Function - Emit the instructions for a function epilog. */
4482 /*------------------------------------------------------------------*/
4485 mono_arch_emit_epilog (MonoCompile *cfg)
4487 MonoJumpInfo *patch_info;
4488 MonoMethod *method = cfg->method;
4489 MonoMethodSignature *sig = method->signature;
4491 int i, lmfOffset, tracing = 0;
4494 code = cfg->native_code + cfg->code_len;
4496 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4497 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
4501 if (method->save_lmf) {
4502 s390_lr (code, s390_r13, cfg->frame_reg);
4504 lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4506 /*-------------------------------------------------*/
4508 /*-------------------------------------------------*/
4509 s390_ahi (code, s390_r13, lmfOffset);
4511 /*-------------------------------------------------*/
4512 /* r6 = &jit_tls->lmf */
4513 /*-------------------------------------------------*/
4514 s390_l (code, s390_r6, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4516 /*-------------------------------------------------*/
4517 /* r0 = lmf.previous_lmf */
4518 /*-------------------------------------------------*/
4519 s390_l (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4521 /*-------------------------------------------------*/
4522 /* jit_tls->lmf = previous_lmf */
4523 /*-------------------------------------------------*/
4524 s390_l (code, s390_r13, 0, s390_r6, 0);
4525 s390_st (code, s390_r0, 0, s390_r6, 0);
4528 if (cfg->frame_reg != STK_BASE)
4529 s390_lr (code, STK_BASE, cfg->frame_reg);
4531 s390_ahi (code, STK_BASE, cfg->stack_usage);
4532 s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4533 s390_br (code, s390_r14);
4535 /* add code to raise exceptions */
4536 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4537 switch (patch_info->type) {
4538 case MONO_PATCH_INFO_EXC: {
4539 /*-----------------------------------------------------*/
4540 /* Patch the branch in epilog to come here */
4541 /*-----------------------------------------------------*/
4542 s390_patch (patch_info->ip.i+cfg->native_code+2,
4543 S390_RELATIVE(code,patch_info->ip.i+cfg->native_code));
4544 /*-----------------------------------------------------*/
4545 /* Patch the parameter passed to the handler */
4546 /*-----------------------------------------------------*/
4547 s390_basr (code, s390_r13, 0);
4549 mono_add_patch_info (cfg, code - cfg->native_code,
4550 MONO_PATCH_INFO_EXC_NAME,
4551 patch_info->data.target);
4552 s390_word (code, 0);
4553 /*-----------------------------------------------------*/
4554 /* Load the return address and the parameter register */
4555 /*-----------------------------------------------------*/
4556 s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
4557 cfg->native_code + 8), code));
4558 s390_l (code, s390_r2, 0, s390_r13, 4);
4559 /*-----------------------------------------------------*/
4560 /* Reuse the current patch to set the jump */
4561 /*-----------------------------------------------------*/
4562 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
4563 patch_info->data.name = "mono_arch_throw_exception_by_name";
4564 patch_info->ip.i = code - cfg->native_code;
4565 s390_jcl (code, S390_CC_UN, 0);
4574 cfg->code_len = code - cfg->native_code;
4576 g_assert (cfg->code_len < cfg->code_size);
4580 /*========================= End of Function ========================*/
4582 /*------------------------------------------------------------------*/
4584 /* Name - mono_arch_setup_jit_tls_data */
4586 /* Function - Setup the JIT's Thread Level Specific Data. */
4588 /*------------------------------------------------------------------*/
4591 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
4595 /*========================= End of Function ========================*/
4597 /*------------------------------------------------------------------*/
4599 /* Name - mono_arch_free_jit_tls_data */
4601 /* Function - Free tls data. */
4603 /*------------------------------------------------------------------*/
4606 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
4610 /*========================= End of Function ========================*/
4612 /*------------------------------------------------------------------*/
4614 /* Name - mono_arch_emit_this_vret_args */
4618 /*------------------------------------------------------------------*/
4621 mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
4623 int this_dreg = s390_r2;
4626 this_dreg = s390_r3;
4628 /* add the this argument */
4629 if (this_reg != -1) {
4631 MONO_INST_NEW (cfg, this, OP_SETREG);
4632 this->type = this_type;
4633 this->sreg1 = this_reg;
4634 this->dreg = this_dreg;
4635 mono_bblock_add_inst (cfg->cbb, this);
4640 MONO_INST_NEW (cfg, vtarg, OP_SETREG);
4641 vtarg->type = STACK_MP;
4642 vtarg->sreg1 = vt_reg;
4643 vtarg->dreg = s390_r2;
4644 mono_bblock_add_inst (cfg->cbb, vtarg);
4648 /*========================= End of Function ========================*/
4650 /*------------------------------------------------------------------*/
4652 /* Name - mono_arch_get_opcode_for_method */
4654 /* Function - Check for opcodes we can handle directly in */
4657 /*------------------------------------------------------------------*/
4660 mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
4662 if (cmethod->klass == mono_defaults.math_class) {
4663 if (strcmp (cmethod->name, "Sqrt") == 0)
4669 /*========================= End of Function ========================*/
4671 /*------------------------------------------------------------------*/
4673 /* Name - mono_arch_print_tree */
4675 /* Function - Print platform-specific opcode details. */
4677 /* Returns - 1 - opcode details have been printed */
4678 /* 0 - opcode details have not been printed */
4680 /*------------------------------------------------------------------*/
4683 mono_arch_print_tree (MonoInst *tree, int arity)
4687 switch (tree->opcode) {
4688 case OP_S390_LOADARG:
4689 case OP_S390_ARGPTR:
4690 case OP_S390_STKARG:
4691 printf ("[0x%x(%s)]", tree->inst_offset,
4692 mono_arch_regname (tree->inst_basereg));
4701 /*========================= End of Function ========================*/
4703 /*------------------------------------------------------------------*/
4705 /* Name - mono_arch_regalloc_cost */
4707 /* Function - Determine the cost, in the number of memory */
4708 /* references, of the action of allocating the var- */
4709 /* iable VMV into a register during global register */
4712 /* Returns - Cost */
4714 /*------------------------------------------------------------------*/
4717 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
4723 /*========================= End of Function ========================*/