2 * mini-sparc.c: Sparc backend for the Mono code generator
5 * Paolo Molaro (lupus@ximian.com)
6 * Dietmar Maurer (dietmar@ximian.com)
9 * Christopher Taylor (ct@gentoo.org)
10 * Mark Crichton (crichton@gimp.org)
11 * Zoltan Varga (vargaz@freemail.hu)
13 * (C) 2003 Ximian, Inc.
18 #include <mono/metadata/appdomain.h>
19 #include <mono/metadata/debug-helpers.h>
20 #include <mono/utils/mono-math.h>
22 #include "mini-sparc.h"
25 #include "cpu-sparc.h"
28 * Sparc V9 means two things:
29 * - the instruction set
32 * V9 instructions are only usable if the underlying processor is 64 bit. Most Sparc
33 * processors in use are 64 bit processors. The V9 ABI is only usable if the
34 * mono executable is a 64 bit executable. So it would make sense to use the 64 bit
35 * instructions without using the 64 bit ABI.
40 * - %i0..%i7 hold the incoming arguments, these are never written by JITted code
41 * - %l0..%l7 is used for local register allocation
42 * - %o0..%o6 is used for outgoing arguments
43 * - %o7 and %g1 is used as scratch registers in opcodes
44 * - all floating point registers are used for local register allocation except %f0.
45 * Only double precision registers are used.
50 * - doubles and longs must be stored in dword aligned locations
54 #error "Sparc V9 support not yet implemented."
57 int mono_exc_esp_offset = 0;
59 #define NOT_IMPLEMENTED g_assert_not_reached ();
61 #define ALIGN_TO(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
64 mono_arch_regname (int reg) {
65 static const char * rnames[] = {
66 "sparc_g0", "sparc_g1", "sparc_g2", "sparc_g3", "sparc_g4",
67 "sparc_g5", "sparc_g6", "sparc_g7", "sparc_o0", "sparc_o1",
68 "sparc_o2", "sparc_o3", "sparc_o4", "sparc_o5", "sparc_sp",
69 "sparc_call", "sparc_l0", "sparc_l1", "sparc_l2", "sparc_l3",
70 "sparc_l4", "sparc_l5", "sparc_l6", "sparc_l7", "sparc_i0",
71 "sparc_i1", "sparc_i2", "sparc_i3", "sparc_i4", "sparc_i5",
72 "sparc_fp", "sparc_retadr"
74 if (reg >= 0 && reg < 32)
80 * Initialize the cpu to execute managed code.
83 mono_arch_cpu_init (void)
88 * This function returns the optimizations supported on this cpu.
91 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
99 is_regsize_var (MonoType *t) {
108 case MONO_TYPE_OBJECT:
109 case MONO_TYPE_STRING:
110 case MONO_TYPE_CLASS:
111 case MONO_TYPE_SZARRAY:
112 case MONO_TYPE_ARRAY:
114 case MONO_TYPE_VALUETYPE:
115 if (t->data.klass->enumtype)
116 return is_regsize_var (t->data.klass->enum_basetype);
123 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
132 * FIXME: If an argument is allocated to a register, then load it from the
133 * stack in the prolog.
136 for (i = 0; i < cfg->num_varinfo; i++) {
137 MonoInst *ins = cfg->varinfo [i];
138 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
141 if (vmv->range.first_use.abs_pos > vmv->range.last_use.abs_pos)
144 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) || (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
148 /* we can only allocate 32 bit values */
149 if (is_regsize_var (ins->inst_vtype)) {
150 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
151 g_assert (i == vmv->idx);
152 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
160 mono_arch_get_global_int_regs (MonoCompile *cfg)
165 /* FIXME: Use unused input registers for global allocation */
167 /* Use %l0..%l3 as global registers */
169 for (i = 16; i < 20; ++i)
170 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
176 #define flushi(addr) __asm__ __volatile__ ("flush %0"::"r"(addr):"memory")
177 #else /* assume Sun's compiler */
178 static void flushi(void *addr)
185 mono_arch_flush_icache (guint8 *code, gint size)
188 * FIXME: This might not work on older machines, but flushing code in dword
195 for (i = 0; i < (size/8); i++)
196 flushi(code + (i*8));
212 /* This needs to be offset by %i0 or %o0 depending on caller/callee */
215 guint32 vt_offset; /* for valuetypes */
231 add_general (guint32 *gr, guint32 *stack_size, ArgInfo *ainfo, gboolean pair)
233 ainfo->offset = *stack_size;
236 if (*gr >= PARAM_REGS) {
237 ainfo->storage = ArgOnStack;
240 ainfo->storage = ArgInIReg;
245 /* Allways reserve stack space for parameters passed in registers */
249 if (*gr < PARAM_REGS - 1) {
250 /* A pair of registers */
251 ainfo->storage = ArgInIRegPair;
255 else if (*gr >= PARAM_REGS) {
256 /* A pair of stack locations */
257 ainfo->storage = ArgOnStackPair;
258 ainfo->offset = *stack_size;
261 ainfo->storage = ArgInSplitRegStack;
263 ainfo->offset = *stack_size;
274 * Obtain information about a call according to the calling convention.
275 * See the "System V ABI, Sparc Processor Supplement" Sparc V8 version document for
279 get_call_info (MonoMethodSignature *sig, gboolean is_pinvoke)
281 guint32 i, gr, simpletype;
282 int n = sig->hasthis + sig->param_count;
283 guint32 stack_size = 0;
286 cinfo = g_malloc0 (sizeof (CallInfo) + (sizeof (ArgInfo) * n));
292 add_general (&gr, &stack_size, cinfo->args + 0, FALSE);
294 for (i = 0; i < sig->param_count; ++i) {
295 ArgInfo *ainfo = &cinfo->args [sig->hasthis + i];
297 DEBUG(printf("param %d: ", i));
298 if (sig->params [i]->byref) {
299 DEBUG(printf("byref\n"));
301 add_general (&gr, &stack_size, ainfo, FALSE);
304 simpletype = sig->params [i]->type;
306 switch (simpletype) {
307 case MONO_TYPE_BOOLEAN:
311 add_general (&gr, &stack_size, ainfo, FALSE);
312 /* the value is in the ls byte */
317 add_general (&gr, &stack_size, ainfo, FALSE);
318 /* the value is in the ls word */
326 case MONO_TYPE_CLASS:
327 case MONO_TYPE_OBJECT:
328 case MONO_TYPE_STRING:
329 case MONO_TYPE_SZARRAY:
330 case MONO_TYPE_ARRAY:
331 add_general (&gr, &stack_size, ainfo, FALSE);
333 case MONO_TYPE_VALUETYPE: {
334 if (sig->params [i]->data.klass->enumtype) {
335 simpletype = sig->params [i]->data.klass->enum_basetype->type;
339 add_general (&gr, &stack_size, ainfo, FALSE);
344 add_general (&gr, &stack_size, ainfo, TRUE);
347 /* single precision values are passed in integer registers */
348 add_general (&gr, &stack_size, ainfo, FALSE);
351 /* double precision values are passed in a pair of registers */
352 add_general (&gr, &stack_size, ainfo, TRUE);
355 g_assert_not_reached ();
361 simpletype = sig->ret->type;
363 switch (simpletype) {
364 case MONO_TYPE_BOOLEAN:
374 case MONO_TYPE_CLASS:
375 case MONO_TYPE_OBJECT:
376 case MONO_TYPE_SZARRAY:
377 case MONO_TYPE_ARRAY:
378 case MONO_TYPE_STRING:
379 cinfo->ret.storage = ArgInIReg;
380 cinfo->ret.reg = sparc_i0;
384 cinfo->ret.storage = ArgInIRegPair;
385 cinfo->ret.reg = sparc_i0;
389 cinfo->ret.storage = ArgInFReg;
390 cinfo->ret.reg = sparc_f0;
392 case MONO_TYPE_VALUETYPE:
393 if (sig->ret->data.klass->enumtype) {
394 simpletype = sig->ret->data.klass->enum_basetype->type;
397 cinfo->ret.storage = ArgOnStack;
402 g_error ("Can't handle as return value 0x%x", sig->ret->type);
406 cinfo->stack_usage = stack_size;
411 * Set var information according to the calling convention. sparc version.
412 * The locals var stuff should most likely be split in another method.
415 mono_arch_allocate_vars (MonoCompile *m)
417 MonoMethodSignature *sig;
418 MonoMethodHeader *header;
420 int i, offset, size, align, curinst;
421 int frame_reg = sparc_sp;
424 m->frame_reg = frame_reg;
426 header = ((MonoMethodNormal *)m->method)->header;
428 sig = m->method->signature;
430 cinfo = get_call_info (sig, FALSE);
432 if (sig->ret->type != MONO_TYPE_VOID) {
433 switch (cinfo->ret.storage) {
437 m->ret->opcode = OP_REGVAR;
438 m->ret->inst_c0 = cinfo->ret.reg;
442 m->ret->opcode = OP_REGOFFSET;
443 m->ret->inst_basereg = sparc_fp;
444 m->ret->inst_offset = 64;
452 * We use the Sparc V8 calling conventions for managed code as well.
453 * FIXME: Use something more optimized.
456 offset = 64; /* register save area */
457 offset += 4; /* struct/union return pointer */
459 /* add parameter area size for called functions */
460 if (m->param_area < 24)
461 /* Reserve space for the first 6 arguments even if it is unused */
464 offset += m->param_area;
466 curinst = m->locals_start;
467 for (i = curinst; i < m->num_varinfo; ++i) {
468 inst = m->varinfo [i];
470 if (inst->opcode == OP_REGVAR)
473 /* inst->unused indicates native sized value types, this is used by the
474 * pinvoke wrappers when they call functions returning structure */
475 if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
476 size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
478 size = mono_type_stack_size (inst->inst_vtype, &align);
481 * This is needed since structures containing doubles must be doubleword
483 * FIXME: Do this only if needed.
485 if (MONO_TYPE_ISSTRUCT (inst->inst_vtype))
489 offset &= ~(align - 1);
490 inst->inst_offset = offset;
491 inst->opcode = OP_REGOFFSET;
492 inst->inst_basereg = frame_reg;
494 //g_print ("allocating local %d to %d\n", i, inst->inst_offset);
497 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
498 inst = m->varinfo [i];
499 if (inst->opcode != OP_REGVAR) {
500 ArgInfo *ainfo = &cinfo->args [i];
501 gboolean inreg = TRUE;
504 if (sig->hasthis && (i == 0))
505 arg_type = mono_defaults.object_class;
507 arg_type = sig->params [i - sig->hasthis];
509 if ((arg_type->type == MONO_TYPE_R4)
510 || (arg_type->type == MONO_TYPE_R8))
512 * Since float arguments are passed in integer registers, we need to
513 * save them to the stack in the prolog.
517 if (inst->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT))
520 if (MONO_TYPE_ISSTRUCT (arg_type))
521 /* FIXME: this isn't needed */
524 switch (ainfo->storage) {
528 inst->opcode = OP_REGVAR;
529 inst->dreg = sparc_i0 + ainfo->reg;
537 case ArgInSplitRegStack:
538 /* Split arguments are saved to the stack in the prolog */
539 inst->opcode = OP_REGOFFSET;
540 /* in parent frame */
541 inst->inst_basereg = sparc_fp;
542 inst->inst_offset = ainfo->offset + 68;
544 if (arg_type->type == MONO_TYPE_R8) {
546 * It is very hard to load doubles from non-doubleword aligned
547 * memory locations. So if the offset is misaligned, we copy the
548 * argument to a stack location in the prolog.
550 if (inst->inst_offset % 8) {
551 inst->inst_basereg = sparc_sp;
554 offset &= ~(align - 1);
555 inst->inst_offset = offset;
564 if (MONO_TYPE_ISSTRUCT (arg_type)) {
565 /* Add a level of indirection */
567 * It would be easier to add OP_LDIND_I here, but ldind_i instructions
568 * are destructively modified in a lot of places in inssel.brg.
571 MONO_INST_NEW (m, indir, 0);
573 inst->opcode = OP_SPARC_INARG_VT;
574 inst->inst_left = indir;
578 g_assert_not_reached ();
581 /* align the stack size to 8 bytes */
585 /* Add a properly aligned dword for use by int<->float conversion opcodes */
588 m->stack_offset = offset;
594 * take the arguments and generate the arch-specific
595 * instructions to properly call the function in call.
596 * This includes pushing, moving arguments to the right register
600 mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
602 MonoMethodSignature *sig;
606 guint32 extra_space = 0;
608 sig = call->signature;
609 n = sig->param_count + sig->hasthis;
611 cinfo = get_call_info (sig, sig->pinvoke);
613 for (i = 0; i < n; ++i) {
614 ainfo = cinfo->args + i;
615 if (is_virtual && i == 0) {
616 /* the argument will be attached to the call instruction */
619 MONO_INST_NEW (cfg, arg, OP_OUTARG);
621 arg->cil_code = in->cil_code;
623 arg->type = in->type;
624 /* prepend, we'll need to reverse them later */
625 arg->next = call->out_args;
626 call->out_args = arg;
628 if ((i >= sig->hasthis) && (MONO_TYPE_ISSTRUCT(sig->params [i - sig->hasthis]))) {
632 guint32 size = mono_type_stack_size (&in->klass->byval_arg, &align);
635 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
636 * use the normal OUTARG opcodes to pass the address of the location to
639 MONO_INST_NEW (cfg, inst, OP_OUTARG_VT);
640 inst->inst_left = in;
642 /* The first 6 argument locations are reserved */
643 if (cinfo->stack_usage < 24)
644 cinfo->stack_usage = 24;
646 offset = ALIGN_TO (68 + cinfo->stack_usage, align);
647 pad = offset - (68 + cinfo->stack_usage);
649 inst->inst_c1 = offset;
651 arg->inst_left = inst;
653 cinfo->stack_usage += size;
654 cinfo->stack_usage += pad;
657 switch (ainfo->storage) {
661 if (ainfo->storage == ArgInIRegPair)
662 arg->opcode = OP_SPARC_OUTARG_REGPAIR;
663 arg->unused = sparc_o0 + ainfo->reg;
664 /* outgoing arguments begin at sp+68 */
665 arg->inst_basereg = sparc_sp;
666 arg->inst_imm = 68 + ainfo->offset;
667 call->used_iregs |= 1 << ainfo->reg;
669 if ((i >= sig->hasthis) && (sig->params [i - sig->hasthis]->type == MONO_TYPE_R8)) {
671 * The OUTARG (freg) implementation needs an extra dword to store
672 * the temporary value.
678 arg->opcode = OP_SPARC_OUTARG_MEM;
679 arg->inst_basereg = sparc_sp;
680 arg->inst_imm = 68 + ainfo->offset;
683 arg->opcode = OP_SPARC_OUTARG_MEMPAIR;
684 arg->inst_basereg = sparc_sp;
685 arg->inst_imm = 68 + ainfo->offset;
687 case ArgInSplitRegStack:
688 arg->opcode = OP_SPARC_OUTARG_SPLIT_REG_STACK;
689 arg->unused = sparc_o0 + ainfo->reg;
690 arg->inst_basereg = sparc_sp;
691 arg->inst_imm = 68 + ainfo->offset;
692 call->used_iregs |= 1 << ainfo->reg;
701 * Reverse the call->out_args list.
704 MonoInst *prev = NULL, *list = call->out_args, *next;
711 call->out_args = prev;
713 call->stack_usage = cinfo->stack_usage + extra_space;
714 cfg->param_area = MAX (cfg->param_area, call->stack_usage);
715 cfg->flags |= MONO_CFG_HAS_CALLS;
721 /* Map opcode to the sparc condition codes */
722 static inline SparcCond
723 opcode_to_sparc_cond (int opcode)
768 g_assert_not_reached ();
773 #define EMIT_COND_BRANCH_GENERAL(ins,bop,cond) \
774 if (ins->flags & MONO_INST_BRLABEL) { \
775 if (ins->inst_i0->inst_c0) { \
776 gint32 disp = (ins->inst_i0->inst_c0 - ((guint8*)code - cfg->native_code)) >> 2; \
777 g_assert (sparc_is_imm22 (disp)); \
778 sparc_ ## bop (code, 1, cond, disp); \
780 mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_LABEL, ins->inst_i0); \
781 sparc_ ## bop (code, 1, cond, 0); \
785 if (ins->inst_true_bb->native_offset) { \
786 gint32 disp = (ins->inst_true_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2; \
787 g_assert (sparc_is_imm22 (disp)); \
788 sparc_ ## bop (code, 1, cond, disp); \
790 mono_add_patch_info (cfg, (guint8*)code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
791 sparc_ ## bop (code, 1, cond, 0); \
796 #define EMIT_COND_BRANCH(ins,cond) EMIT_COND_BRANCH_GENERAL((ins),branch,(cond))
798 #define EMIT_FLOAT_COND_BRANCH(ins,cond) EMIT_COND_BRANCH_GENERAL((ins),fbranch,(cond))
800 #define EMIT_ALU_IMM(ins,op,setcc) do { \
801 if (sparc_is_imm13 ((ins)->inst_imm)) \
802 sparc_ ## op ## _imm (code, (setcc), (ins)->sreg1, ins->inst_imm, (ins)->dreg); \
804 sparc_set (code, ins->inst_imm, sparc_o7); \
805 sparc_ ## op (code, (setcc), (ins)->sreg1, sparc_o7, (ins)->dreg); \
809 #define EMIT_LOAD_MEMBASE(ins,op) do { \
810 if (sparc_is_imm13 (ins->inst_offset)) \
811 sparc_ ## op ## _imm (code, ins->inst_basereg, ins->inst_offset, ins->dreg); \
813 sparc_set (code, ins->inst_offset, sparc_o7); \
814 sparc_ ## op (code, ins->inst_basereg, sparc_o7, ins->dreg); \
819 #define EMIT_STORE_MEMBASE_IMM(ins,op) do { \
821 if (ins->inst_imm == 0) \
824 sparc_set (code, ins->inst_imm, sparc_o7); \
827 if (!sparc_is_imm13 (ins->inst_offset)) { \
828 sparc_set (code, ins->inst_offset, sparc_g1); \
829 sparc_ ## op (code, sreg, ins->inst_destbasereg, sparc_g1); \
832 sparc_ ## op ## _imm (code, sreg, ins->inst_destbasereg, ins->inst_offset); \
835 #define EMIT_STORE_MEMBASE_REG(ins,op) do { \
836 if (!sparc_is_imm13 (ins->inst_offset)) { \
837 sparc_set (code, ins->inst_offset, sparc_o7); \
838 sparc_ ## op (code, ins->sreg1, ins->inst_destbasereg, sparc_o7); \
841 sparc_ ## op ## _imm (code, ins->sreg1, ins->inst_destbasereg, ins->inst_offset); \
845 /* emit an exception if condition is fail */
846 #define EMIT_COND_SYSTEM_EXCEPTION(cond,signed,exc_name) \
848 mono_add_patch_info (cfg, code - cfg->native_code, \
849 MONO_PATCH_INFO_EXC, exc_name); \
850 x86_branch32 (code, cond, 0, signed); \
853 #define EMIT_FPCOMPARE(code) do { \
856 x86_alu_reg_imm (code, X86_AND, X86_EAX, 0x4500); \
860 peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
862 MonoInst *ins, *last_ins = NULL;
865 /* short circuit this for now */
870 switch (ins->opcode) {
872 /* remove unnecessary multiplication with 1 */
873 if (ins->inst_imm == 1) {
874 if (ins->dreg != ins->sreg1) {
875 ins->opcode = OP_MOVE;
877 last_ins->next = ins->next;
883 case OP_LOAD_MEMBASE:
884 case OP_LOADI4_MEMBASE:
886 * OP_STORE_MEMBASE_REG reg, offset(basereg)
887 * OP_LOAD_MEMBASE offset(basereg), reg
889 if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG
890 || last_ins->opcode == OP_STORE_MEMBASE_REG) &&
891 ins->inst_basereg == last_ins->inst_destbasereg &&
892 ins->inst_offset == last_ins->inst_offset) {
893 if (ins->dreg == last_ins->sreg1) {
894 last_ins->next = ins->next;
898 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
899 ins->opcode = OP_MOVE;
900 ins->sreg1 = last_ins->sreg1;
904 * Note: reg1 must be different from the basereg in the second load
905 * OP_LOAD_MEMBASE offset(basereg), reg1
906 * OP_LOAD_MEMBASE offset(basereg), reg2
908 * OP_LOAD_MEMBASE offset(basereg), reg1
911 } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
912 || last_ins->opcode == OP_LOAD_MEMBASE) &&
913 ins->inst_basereg != last_ins->dreg &&
914 ins->inst_basereg == last_ins->inst_basereg &&
915 ins->inst_offset == last_ins->inst_offset) {
917 if (ins->dreg == last_ins->dreg) {
918 last_ins->next = ins->next;
922 ins->opcode = OP_MOVE;
923 ins->sreg1 = last_ins->dreg;
926 //g_assert_not_reached ();
930 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
931 * OP_LOAD_MEMBASE offset(basereg), reg
933 * OP_STORE_MEMBASE_IMM imm, offset(basereg)
936 } else if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_IMM
937 || last_ins->opcode == OP_STORE_MEMBASE_IMM) &&
938 ins->inst_basereg == last_ins->inst_destbasereg &&
939 ins->inst_offset == last_ins->inst_offset) {
940 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
941 ins->opcode = OP_ICONST;
942 ins->inst_c0 = last_ins->inst_imm;
943 g_assert_not_reached (); // check this rule
947 case OP_LOADU1_MEMBASE:
948 case OP_LOADI1_MEMBASE:
949 if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
950 ins->inst_basereg == last_ins->inst_destbasereg &&
951 ins->inst_offset == last_ins->inst_offset) {
952 if (ins->dreg == last_ins->sreg1) {
953 last_ins->next = ins->next;
957 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
958 ins->opcode = OP_MOVE;
959 ins->sreg1 = last_ins->sreg1;
963 case OP_LOADU2_MEMBASE:
964 case OP_LOADI2_MEMBASE:
965 if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) &&
966 ins->inst_basereg == last_ins->inst_destbasereg &&
967 ins->inst_offset == last_ins->inst_offset) {
968 if (ins->dreg == last_ins->sreg1) {
969 last_ins->next = ins->next;
973 //static int c = 0; printf ("MATCHX %s %d\n", cfg->method->name,c++);
974 ins->opcode = OP_MOVE;
975 ins->sreg1 = last_ins->sreg1;
985 if (ins->dreg == ins->sreg1) {
987 last_ins->next = ins->next;
995 if (last_ins && last_ins->opcode == OP_MOVE &&
996 ins->sreg1 == last_ins->dreg &&
997 ins->dreg == last_ins->sreg1) {
998 last_ins->next = ins->next;
1007 bb->last_ins = last_ins;
1011 #define DEBUG(a) if (cfg->verbose_level > 1) a
1013 #define reg_is_freeable(r) (TRUE)
1014 #define freg_is_freeable(r) (TRUE)
1023 static const char*const * ins_spec = sparc_desc;
1026 print_ins (int i, MonoInst *ins)
1028 const char *spec = ins_spec [ins->opcode];
1029 g_print ("\t%-2d %s", i, mono_inst_name (ins->opcode));
1030 if (spec [MONO_INST_DEST]) {
1031 if (ins->dreg >= MONO_MAX_IREGS)
1032 g_print (" R%d <-", ins->dreg);
1034 if (spec [MONO_INST_DEST] == 'b')
1035 g_print (" [%s + 0x%x] <-", mono_arch_regname (ins->dreg), ins->inst_offset);
1037 g_print (" %s <-", mono_arch_regname (ins->dreg));
1039 if (spec [MONO_INST_SRC1]) {
1040 if (ins->sreg1 >= MONO_MAX_IREGS)
1041 g_print (" R%d", ins->sreg1);
1043 if (spec [MONO_INST_SRC1] == 'b')
1044 g_print (" [%s + 0x%x]", mono_arch_regname (ins->sreg1), ins->inst_offset);
1046 g_print (" %s", mono_arch_regname (ins->sreg1));
1048 if (spec [MONO_INST_SRC2]) {
1049 if (ins->sreg2 >= MONO_MAX_IREGS)
1050 g_print (" R%d", ins->sreg2);
1052 g_print (" %s", mono_arch_regname (ins->sreg2));
1054 if (spec [MONO_INST_CLOB])
1055 g_print (" clobbers: %c", spec [MONO_INST_CLOB]);
1060 print_regtrack (RegTrack *t, int num)
1066 for (i = 0; i < num; ++i) {
1069 if (i >= MONO_MAX_IREGS) {
1070 g_snprintf (buf, sizeof(buf), "R%d", i);
1073 r = mono_arch_regname (i);
1074 g_print ("liveness: %s [%d - %d]\n", r, t [i].born_in, t[i].last_use);
1078 typedef struct InstList InstList;
1086 static inline InstList*
1087 inst_list_prepend (MonoMemPool *pool, InstList *list, MonoInst *data)
1089 InstList *item = mono_mempool_alloc (pool, sizeof (InstList));
1098 #define STACK_OFFSETS_POSITIVE
1101 * returns the offset used by spillvar. It allocates a new
1102 * spill variable if necessary. Likely incorrect for sparc.
1105 mono_spillvar_offset (MonoCompile *cfg, int spillvar)
1107 MonoSpillInfo **si, *info;
1110 si = &cfg->spill_info;
1112 while (i <= spillvar) {
1115 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1117 #ifdef STACK_OFFSETS_POSITIVE
1118 cfg->stack_offset += sizeof (gpointer);
1120 cfg->stack_offset -= sizeof (gpointer);
1122 info->offset = cfg->stack_offset;
1126 return (*si)->offset;
1132 g_assert_not_reached ();
1137 mono_spillvar_offset_float (MonoCompile *cfg, int spillvar)
1139 MonoSpillInfo **si, *info;
1142 si = &cfg->spill_info_float;
1144 while (i <= spillvar) {
1147 *si = info = mono_mempool_alloc (cfg->mempool, sizeof (MonoSpillInfo));
1149 cfg->stack_offset += 7;
1150 cfg->stack_offset &= ~7;
1151 info->offset = cfg->stack_offset;
1152 cfg->stack_offset += sizeof (double);
1156 return (*si)->offset;
1162 g_assert_not_reached ();
1167 * Force the spilling of the variable in the symbolic register 'reg'.
1170 get_register_force_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, int reg)
1175 sel = cfg->rs->iassign [reg];
1176 /*i = cfg->rs->isymbolic [sel];
1177 g_assert (i == reg);*/
1179 spill = ++cfg->spill_count;
1180 cfg->rs->iassign [i] = -spill - 1;
1181 mono_regstate_free_int (cfg->rs, sel);
1182 /* we need to create a spill var and insert a load to sel after the current instruction */
1183 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
1185 load->inst_basereg = cfg->frame_reg;
1186 load->inst_offset = mono_spillvar_offset (cfg, spill);
1188 while (ins->next != item->prev->data)
1191 load->next = ins->next;
1193 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
1194 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
1195 g_assert (i == sel);
1201 get_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
1206 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));
1207 /* exclude the registers in the current instruction */
1208 if (reg != ins->sreg1 && (reg_is_freeable (ins->sreg1) || (ins->sreg1 >= MONO_MAX_IREGS && cfg->rs->iassign [ins->sreg1] >= 0))) {
1209 if (ins->sreg1 >= MONO_MAX_IREGS)
1210 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg1]);
1212 regmask &= ~ (1 << ins->sreg1);
1213 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
1215 if (reg != ins->sreg2 && (reg_is_freeable (ins->sreg2) || (ins->sreg2 >= MONO_MAX_IREGS && cfg->rs->iassign [ins->sreg2] >= 0))) {
1216 if (ins->sreg2 >= MONO_MAX_IREGS)
1217 regmask &= ~ (1 << cfg->rs->iassign [ins->sreg2]);
1219 regmask &= ~ (1 << ins->sreg2);
1220 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
1222 if (reg != ins->dreg && reg_is_freeable (ins->dreg)) {
1223 regmask &= ~ (1 << ins->dreg);
1224 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
1227 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
1228 g_assert (regmask); /* need at least a register we can free */
1230 /* we should track prev_use and spill the register that's farther */
1231 for (i = 0; i < MONO_MAX_IREGS; ++i) {
1232 if (regmask & (1 << i)) {
1234 DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->iassign [sel]));
1238 i = cfg->rs->isymbolic [sel];
1239 spill = ++cfg->spill_count;
1240 cfg->rs->iassign [i] = -spill - 1;
1241 mono_regstate_free_int (cfg->rs, sel);
1242 /* we need to create a spill var and insert a load to sel after the current instruction */
1243 MONO_INST_NEW (cfg, load, OP_LOAD_MEMBASE);
1245 load->inst_basereg = cfg->frame_reg;
1246 load->inst_offset = mono_spillvar_offset (cfg, spill);
1248 while (ins->next != item->prev->data)
1251 load->next = ins->next;
1253 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
1254 i = mono_regstate_alloc_int (cfg->rs, 1 << sel);
1255 g_assert (i == sel);
1261 get_float_register_spilling (MonoCompile *cfg, InstList *item, MonoInst *ins, guint32 regmask, int reg)
1266 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));
1267 /* exclude the registers in the current instruction */
1268 if (reg != ins->sreg1 && (freg_is_freeable (ins->sreg1) || (ins->sreg1 >= MONO_MAX_FREGS && cfg->rs->fassign [ins->sreg1] >= 0))) {
1269 if (ins->sreg1 >= MONO_MAX_FREGS)
1270 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg1]);
1272 regmask &= ~ (1 << ins->sreg1);
1273 DEBUG (g_print ("excluding sreg1 %s\n", mono_arch_regname (ins->sreg1)));
1275 if (reg != ins->sreg2 && (freg_is_freeable (ins->sreg2) || (ins->sreg2 >= MONO_MAX_FREGS && cfg->rs->fassign [ins->sreg2] >= 0))) {
1276 if (ins->sreg2 >= MONO_MAX_FREGS)
1277 regmask &= ~ (1 << cfg->rs->fassign [ins->sreg2]);
1279 regmask &= ~ (1 << ins->sreg2);
1280 DEBUG (g_print ("excluding sreg2 %s %d\n", mono_arch_regname (ins->sreg2), ins->sreg2));
1282 if (reg != ins->dreg && freg_is_freeable (ins->dreg)) {
1283 regmask &= ~ (1 << ins->dreg);
1284 DEBUG (g_print ("excluding dreg %s\n", mono_arch_regname (ins->dreg)));
1287 DEBUG (g_print ("available regmask: 0x%08x\n", regmask));
1288 g_assert (regmask); /* need at least a register we can free */
1290 /* we should track prev_use and spill the register that's farther */
1291 for (i = 0; i < MONO_MAX_FREGS; ++i) {
1292 if (regmask & (1 << i)) {
1294 DEBUG (g_print ("selected register %s has assignment %d\n", mono_arch_regname (sel), cfg->rs->fassign [sel]));
1298 i = cfg->rs->fsymbolic [sel];
1299 spill = ++cfg->spill_count;
1300 cfg->rs->fassign [i] = -spill - 1;
1301 mono_regstate_free_float(cfg->rs, sel);
1302 /* we need to create a spill var and insert a load to sel after the current instruction */
1303 MONO_INST_NEW (cfg, load, OP_LOADR8_MEMBASE);
1305 load->inst_basereg = cfg->frame_reg;
1306 load->inst_offset = mono_spillvar_offset_float (cfg, spill);
1308 while (ins->next != item->prev->data)
1311 load->next = ins->next;
1313 DEBUG (g_print ("SPILLED LOAD (%d at 0x%08x(%%sp)) R%d (freed %s)\n", spill, load->inst_offset, i, mono_arch_regname (sel)));
1314 i = mono_regstate_alloc_float (cfg->rs, 1 << sel);
1315 g_assert (i == sel);
1321 create_copy_ins (MonoCompile *cfg, int dest, int src, MonoInst *ins)
1324 MONO_INST_NEW (cfg, copy, OP_MOVE);
1328 copy->next = ins->next;
1331 DEBUG (g_print ("\tforced copy from %s to %s\n", mono_arch_regname (src), mono_arch_regname (dest)));
1336 create_copy_ins_float (MonoCompile *cfg, int dest, int src, MonoInst *ins)
1339 MONO_INST_NEW (cfg, copy, OP_FMOVE);
1343 copy->next = ins->next;
1346 DEBUG (g_print ("\tforced copy from %s to %s\n", mono_arch_regname (src), mono_arch_regname (dest)));
1351 create_spilled_store (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
1354 MONO_INST_NEW (cfg, store, OP_STORE_MEMBASE_REG);
1356 store->inst_destbasereg = cfg->frame_reg;
1357 store->inst_offset = mono_spillvar_offset (cfg, spill);
1359 store->next = ins->next;
1362 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n", spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
1367 create_spilled_store_float (MonoCompile *cfg, int spill, int reg, int prev_reg, MonoInst *ins)
1370 MONO_INST_NEW (cfg, store, OP_STORER8_MEMBASE_REG);
1372 store->inst_destbasereg = cfg->frame_reg;
1373 store->inst_offset = mono_spillvar_offset_float (cfg, spill);
1375 store->next = ins->next;
1378 DEBUG (g_print ("SPILLED STORE (%d at 0x%08x(%%sp)) R%d (from %s)\n", spill, store->inst_offset, prev_reg, mono_arch_regname (reg)));
1383 insert_before_ins (MonoInst *ins, InstList *item, MonoInst* to_insert)
1386 g_assert (item->next);
1387 prev = item->next->data;
1389 while (prev->next != ins)
1391 to_insert->next = ins;
1392 prev->next = to_insert;
1394 * needed otherwise in the next instruction we can add an ins to the
1395 * end and that would get past this instruction.
1397 item->data = to_insert;
1401 alloc_int_reg (MonoCompile *cfg, InstList *curinst, MonoInst *ins, int sym_reg, guint32 allow_mask)
1403 int val = cfg->rs->iassign [sym_reg];
1407 /* the register gets spilled after this inst */
1410 val = mono_regstate_alloc_int (cfg->rs, allow_mask);
1412 val = get_register_spilling (cfg, curinst, ins, allow_mask, sym_reg);
1413 cfg->rs->iassign [sym_reg] = val;
1414 /* add option to store before the instruction for src registers */
1416 create_spilled_store (cfg, spill, val, sym_reg, ins);
1418 cfg->rs->isymbolic [val] = sym_reg;
1422 /* Parameters used by the register allocator */
1424 /* Use %l4..%l7 as local registers */
1425 #define ARCH_CALLER_REGS (0xf0<<16)
1426 /* Use %f2..%f30 as the double precision floating point local registers */
1427 #define ARCH_CALLER_FREGS (0x55555554)
1429 /* FIXME: Strange loads from the stack in basic-float.cs:test_2_rem */
1432 * Local register allocation.
1433 * We first scan the list of instructions and we save the liveness info of
1434 * each register (when the register is first used, when it's value is set etc.).
1435 * We also reverse the list of instructions (in the InstList list) because assigning
1436 * registers backwards allows for more tricks to be used.
1439 mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
1442 MonoRegState *rs = cfg->rs;
1444 RegTrack *reginfo, *reginfof;
1445 RegTrack *reginfo1, *reginfo2, *reginfod;
1446 InstList *tmp, *reversed = NULL;
1448 guint32 src1_mask, src2_mask, dest_mask;
1449 guint32 cur_iregs, cur_fregs;
1451 /* FIXME: clobbering */
1455 rs->next_vireg = bb->max_ireg;
1456 rs->next_vfreg = bb->max_freg;
1457 mono_regstate_assign (rs);
1458 reginfo = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vireg);
1459 reginfof = mono_mempool_alloc0 (cfg->mempool, sizeof (RegTrack) * rs->next_vfreg);
1460 rs->ifree_mask = ARCH_CALLER_REGS;
1461 rs->ffree_mask = ARCH_CALLER_FREGS;
1465 DEBUG (g_print ("LOCAL regalloc: basic block: %d\n", bb->block_num));
1466 /* forward pass on the instructions to collect register liveness info */
1468 spec = ins_spec [ins->opcode];
1470 DEBUG (print_ins (i, ins));
1472 if (spec [MONO_INST_SRC1]) {
1473 if (spec [MONO_INST_SRC1] == 'f')
1474 reginfo1 = reginfof;
1477 reginfo1 [ins->sreg1].prev_use = reginfo1 [ins->sreg1].last_use;
1478 reginfo1 [ins->sreg1].last_use = i;
1482 if (spec [MONO_INST_SRC2]) {
1483 if (spec [MONO_INST_SRC2] == 'f')
1484 reginfo2 = reginfof;
1487 reginfo2 [ins->sreg2].prev_use = reginfo2 [ins->sreg2].last_use;
1488 reginfo2 [ins->sreg2].last_use = i;
1492 if (spec [MONO_INST_DEST]) {
1493 if (spec [MONO_INST_DEST] == 'f')
1494 reginfod = reginfof;
1497 if (spec [MONO_INST_DEST] != 'b') /* it's not just a base register */
1498 reginfod [ins->dreg].killed_in = i;
1499 reginfod [ins->dreg].prev_use = reginfod [ins->dreg].last_use;
1500 reginfod [ins->dreg].last_use = i;
1501 if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
1502 reginfod [ins->dreg].born_in = i;
1503 if (spec [MONO_INST_DEST] == 'l') {
1504 /* result in eax:edx, the virtual register is allocated sequentially */
1505 reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
1506 reginfod [ins->dreg + 1].last_use = i;
1507 if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
1508 reginfod [ins->dreg + 1].born_in = i;
1513 reversed = inst_list_prepend (cfg->mempool, reversed, ins);
1518 cur_iregs = ARCH_CALLER_REGS;
1519 cur_fregs = ARCH_CALLER_FREGS;
1521 DEBUG (print_regtrack (reginfo, rs->next_vireg));
1522 DEBUG (print_regtrack (reginfof, rs->next_vfreg));
1525 int prev_dreg, prev_sreg1, prev_sreg2;
1528 spec = ins_spec [ins->opcode];
1529 DEBUG (g_print ("processing:"));
1530 DEBUG (print_ins (i, ins));
1532 /* make the register available for allocation: FIXME add fp reg */
1533 if (ins->opcode == OP_SETREG || ins->opcode == OP_SETREGIMM) {
1534 /* Dont free register which can't be allocated */
1535 if ((ins->dreg << 1) | ARCH_CALLER_REGS) {
1536 cur_iregs |= 1 << ins->dreg;
1537 DEBUG (g_print ("adding %d to cur_iregs\n", ins->dreg));
1539 } else if (ins->opcode == OP_SETFREG) {
1540 if ((ins->dreg << 1) | ARCH_CALLER_FREGS) {
1541 cur_fregs |= 1 << ins->dreg;
1542 DEBUG (g_print ("adding %d to cur_fregs\n", ins->dreg));
1544 } else if (spec [MONO_INST_CLOB] == 'c') {
1545 MonoCallInst *cinst = (MonoCallInst*)ins;
1546 DEBUG (g_print ("excluding regs 0x%x from cur_iregs (0x%x)\n", cinst->used_iregs, cur_iregs));
1547 cur_iregs &= ~cinst->used_iregs;
1548 cur_fregs &= ~cinst->used_fregs;
1549 DEBUG (g_print ("available cur_iregs: 0x%x\n", cur_iregs));
1550 /* registers used by the calling convention are excluded from
1551 * allocation: they will be selectively enabled when they are
1552 * assigned by the special SETREG opcodes.
1555 dest_mask = src1_mask = src2_mask = cur_iregs;
1560 /* update for use with FP regs... */
1561 if (spec [MONO_INST_DEST] == 'f') {
1562 if (ins->dreg >= MONO_MAX_FREGS) {
1563 val = rs->fassign [ins->dreg];
1564 prev_dreg = ins->dreg;
1568 /* the register gets spilled after this inst */
1571 dest_mask = cur_fregs;
1572 val = mono_regstate_alloc_float (rs, dest_mask);
1574 val = get_float_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
1575 rs->fassign [ins->dreg] = val;
1577 create_spilled_store_float (cfg, spill, val, prev_dreg, ins);
1579 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
1580 rs->fsymbolic [val] = prev_dreg;
1585 if (freg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i || !(cur_fregs & (1 << ins->dreg)))) {
1586 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
1587 mono_regstate_free_float (rs, ins->dreg);
1589 } else if (ins->dreg >= MONO_MAX_IREGS) {
1590 val = rs->iassign [ins->dreg];
1591 prev_dreg = ins->dreg;
1595 /* the register gets spilled after this inst */
1598 val = mono_regstate_alloc_int (rs, dest_mask);
1600 val = get_register_spilling (cfg, tmp, ins, dest_mask, ins->dreg);
1601 rs->iassign [ins->dreg] = val;
1603 create_spilled_store (cfg, spill, val, prev_dreg, ins);
1605 DEBUG (g_print ("\tassigned dreg %s to dest R%d\n", mono_arch_regname (val), ins->dreg));
1606 rs->isymbolic [val] = prev_dreg;
1608 if (spec [MONO_INST_DEST] == 'l') {
1609 int hreg = prev_dreg + 1;
1610 val = rs->iassign [hreg];
1614 /* the register gets spilled after this inst */
1617 /* The second register must be a pair of the first */
1618 dest_mask = 1 << (rs->iassign [prev_dreg] + 1);
1619 val = mono_regstate_alloc_int (rs, dest_mask);
1621 val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
1622 rs->iassign [hreg] = val;
1624 create_spilled_store (cfg, spill, val, hreg, ins);
1627 /* The second register must be a pair of the first */
1628 if (val != rs->iassign [prev_dreg] + 1) {
1629 dest_mask = 1 << (rs->iassign [prev_dreg] + 1);
1631 val = mono_regstate_alloc_int (rs, dest_mask);
1633 val = get_register_spilling (cfg, tmp, ins, dest_mask, hreg);
1635 create_copy_ins (cfg, rs->iassign [hreg], val, ins);
1637 rs->iassign [hreg] = val;
1641 DEBUG (g_print ("\tassigned hreg %s to dest R%d\n", mono_arch_regname (val), hreg));
1642 rs->isymbolic [val] = hreg;
1644 if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
1645 DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
1646 mono_regstate_free_int (rs, val);
1652 if (spec [MONO_INST_DEST] != 'f' && reg_is_freeable (ins->dreg) && prev_dreg >= 0 && (reginfo [prev_dreg].born_in >= i)) {
1653 DEBUG (g_print ("\tfreeable %s (R%d) (born in %d)\n", mono_arch_regname (ins->dreg), prev_dreg, reginfo [prev_dreg].born_in));
1654 mono_regstate_free_int (rs, ins->dreg);
1660 if (spec [MONO_INST_SRC1] == 'f') {
1661 if (ins->sreg1 >= MONO_MAX_FREGS) {
1662 val = rs->fassign [ins->sreg1];
1663 prev_sreg1 = ins->sreg1;
1667 /* the register gets spilled after this inst */
1670 //g_assert (val == -1); /* source cannot be spilled */
1671 src1_mask = cur_fregs;
1672 val = mono_regstate_alloc_float (rs, src1_mask);
1674 val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
1675 rs->fassign [ins->sreg1] = val;
1676 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
1678 MonoInst *store = create_spilled_store_float (cfg, spill, val, prev_sreg1, NULL);
1679 insert_before_ins (ins, tmp, store);
1682 rs->fsymbolic [val] = prev_sreg1;
1687 } else if (ins->sreg1 >= MONO_MAX_IREGS) {
1688 val = rs->iassign [ins->sreg1];
1689 prev_sreg1 = ins->sreg1;
1693 /* the register gets spilled after this inst */
1696 if (0 && ins->opcode == OP_MOVE) {
1698 * small optimization: the dest register is already allocated
1699 * but the src one is not: we can simply assign the same register
1700 * here and peephole will get rid of the instruction later.
1701 * This optimization may interfere with the clobbering handling:
1702 * it removes a mov operation that will be added again to handle clobbering.
1703 * There are also some other issues that should with make testjit.
1705 mono_regstate_alloc_int (rs, 1 << ins->dreg);
1706 val = rs->iassign [ins->sreg1] = ins->dreg;
1707 //g_assert (val >= 0);
1708 DEBUG (g_print ("\tfast assigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
1710 //g_assert (val == -1); /* source cannot be spilled */
1711 val = mono_regstate_alloc_int (rs, src1_mask);
1713 val = get_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
1714 rs->iassign [ins->sreg1] = val;
1715 DEBUG (g_print ("\tassigned sreg1 %s to R%d\n", mono_arch_regname (val), ins->sreg1));
1718 MonoInst *store = create_spilled_store (cfg, spill, val, prev_sreg1, NULL);
1719 insert_before_ins (ins, tmp, store);
1722 rs->isymbolic [val] = prev_sreg1;
1731 if (spec [MONO_INST_SRC2] == 'f') {
1732 if (ins->sreg2 >= MONO_MAX_FREGS) {
1733 val = rs->fassign [ins->sreg2];
1734 prev_sreg2 = ins->sreg2;
1738 /* the register gets spilled after this inst */
1741 src2_mask = cur_fregs;
1742 val = mono_regstate_alloc_float (rs, src2_mask);
1744 val = get_float_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
1745 rs->fassign [ins->sreg2] = val;
1746 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
1748 create_spilled_store_float (cfg, spill, val, prev_sreg2, ins);
1750 rs->fsymbolic [val] = prev_sreg2;
1755 } else if (ins->sreg2 >= MONO_MAX_IREGS) {
1756 val = rs->iassign [ins->sreg2];
1757 prev_sreg2 = ins->sreg2;
1761 /* the register gets spilled after this inst */
1764 val = mono_regstate_alloc_int (rs, src2_mask);
1766 val = get_register_spilling (cfg, tmp, ins, src2_mask, ins->sreg2);
1767 rs->iassign [ins->sreg2] = val;
1768 DEBUG (g_print ("\tassigned sreg2 %s to R%d\n", mono_arch_regname (val), ins->sreg2));
1770 create_spilled_store (cfg, spill, val, prev_sreg2, ins);
1772 rs->isymbolic [val] = prev_sreg2;
1778 if (spec [MONO_INST_CLOB] == 'c') {
1780 guint32 clob_mask = ARCH_CALLER_REGS;
1781 for (j = 0; j < MONO_MAX_IREGS; ++j) {
1783 if ((clob_mask & s) && !(rs->ifree_mask & s) && j != ins->sreg1) {
1784 //g_warning ("register %s busy at call site\n", mono_arch_regname (j));
1788 /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
1789 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
1790 mono_regstate_free_int (rs, ins->sreg1);
1792 if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
1793 DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
1794 mono_regstate_free_int (rs, ins->sreg2);
1797 //DEBUG (print_ins (i, ins));
1804 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int size, gboolean is_signed)
1809 static unsigned char*
1810 mono_emit_stack_alloc (guchar *code, MonoInst* tree)
1817 sparc_patch (guint8 *code, guint8 *target)
1819 guint32 ins = *(guint32*)code;
1820 guint32 op = ins >> 30;
1821 guint32 op2 = (ins >> 22) & 0x7;
1822 guint32 rd = (ins >> 25) & 0x1f;
1823 gint32 disp = (target - code) >> 2;
1825 // g_print ("patching 0x%08x (0x%08x) to point to 0x%08x\n", code, ins, target);
1827 if ((op == 0) && (op2 == 2)) {
1828 if (!sparc_is_imm22 (disp))
1831 *(guint32*)code = ((ins >> 22) << 22) | disp;
1833 else if ((op == 0) && (op2 == 6)) {
1834 if (!sparc_is_imm22 (disp))
1837 *(guint32*)code = ((ins >> 22) << 22) | disp;
1839 else if ((op == 0) && (op2 == 4)) {
1840 guint32 ins2 = *(guint32*)(code + 4);
1842 if (((ins2 >> 30) == 2) && (((ins2 >> 19) & 0x3f) == 2)) {
1843 /* sethi followed by or */
1844 guint32 *p = (guint32*)code;
1845 sparc_set (p, target, rd);
1846 while (p < (code + 4))
1849 else if ((sparc_inst_op (ins2) == 3) && (sparc_inst_imm (ins2))) {
1850 /* sethi followed by load/store */
1851 guint32 t = (guint32)target;
1852 *(guint32*)code = ins | (t >> 10);
1853 *(guint32*)(code + 4) = ins2 | (t & 0x3ff);
1855 else if ((sparc_inst_op (ins2) == 2) && (sparc_inst_op3 (ins2) == 0x38) &&
1856 (sparc_inst_imm (ins2))) {
1857 /* sethi followed by jmpl */
1858 guint32 t = (guint32)target;
1859 *(guint32*)code = ins | (t >> 10);
1860 *(guint32*)(code + 4) = ins2 | (t & 0x3ff);
1865 else if (op == 01) {
1866 sparc_call_simple (code, target - code);
1871 // g_print ("patched with 0x%08x\n", ins);
1875 emit_move_return_value (MonoInst *ins, guint32 *code)
1877 /* Move return value to the target register */
1878 /* FIXME: do this in the local reg allocator */
1879 switch (ins->opcode) {
1881 case OP_VOIDCALL_REG:
1882 case OP_VOIDCALL_MEMBASE:
1886 case OP_CALL_MEMBASE:
1887 sparc_mov_reg_reg (code, sparc_o0, ins->dreg);
1891 case OP_LCALL_MEMBASE:
1893 * ins->dreg is the least significant reg due to the lreg: LCALL rule
1896 sparc_mov_reg_reg (code, sparc_o0, ins->dreg + 1);
1897 sparc_mov_reg_reg (code, sparc_o1, ins->dreg);
1901 case OP_FCALL_MEMBASE:
1902 sparc_fmovs (code, sparc_f0, ins->dreg);
1903 sparc_fmovs (code, sparc_f1, ins->dreg + 1);
1907 case OP_VCALL_MEMBASE:
1917 * Some conventions used in the following code.
1918 * 2) The only scratch registers we have are o7 and g1. We try to
1919 * stick to o7 when we can, and use g1 when necessary.
1923 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
1928 guint32 *code = (guint32*)(cfg->native_code + cfg->code_len);
1929 MonoInst *last_ins = NULL;
1930 guint last_offset = 0;
1935 if (cfg->opt & MONO_OPT_PEEPHOLE)
1936 peephole_pass (cfg, bb);
1938 if (cfg->verbose_level > 2)
1939 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
1941 cpos = bb->max_offset;
1943 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
1949 offset = (guint8*)code - cfg->native_code;
1951 max_len = ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
1953 if (offset > (cfg->code_size - max_len - 16)) {
1954 cfg->code_size *= 2;
1955 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
1956 code = (guint32*)(cfg->native_code + offset);
1958 // if (ins->cil_code)
1959 // g_print ("cil code\n");
1961 switch (ins->opcode) {
1962 case OP_STOREI1_MEMBASE_IMM:
1963 EMIT_STORE_MEMBASE_IMM (ins, stb);
1965 case OP_STOREI2_MEMBASE_IMM:
1966 EMIT_STORE_MEMBASE_IMM (ins, sth);
1968 case OP_STORE_MEMBASE_IMM:
1969 case OP_STOREI4_MEMBASE_IMM:
1970 EMIT_STORE_MEMBASE_IMM (ins, st);
1972 case OP_STOREI1_MEMBASE_REG:
1973 EMIT_STORE_MEMBASE_REG (ins, stb);
1975 case OP_STOREI2_MEMBASE_REG:
1976 EMIT_STORE_MEMBASE_REG (ins, sth);
1978 case OP_STORE_MEMBASE_REG:
1979 case OP_STOREI4_MEMBASE_REG:
1980 EMIT_STORE_MEMBASE_REG (ins, st);
1982 case OP_STOREI8_MEMBASE_REG:
1983 /* Only used by OP_MEMSET */
1984 EMIT_STORE_MEMBASE_REG (ins, std);
1989 sparc_ld (code, ins->inst_p0, sparc_g0, ins->dreg);
1991 /* The cast IS BAD (maybe). But it needs to be done... */
1993 sparc_set (code, (guint)ins->inst_p0, ins->dreg);
1994 sparc_ld (code, ins->dreg, sparc_g0, ins->dreg);
1996 case OP_LOAD_MEMBASE:
1997 case OP_LOADI4_MEMBASE:
1998 case OP_LOADU4_MEMBASE:
1999 EMIT_LOAD_MEMBASE (ins, ld);
2001 case OP_LOADU1_MEMBASE:
2002 EMIT_LOAD_MEMBASE (ins, ldub);
2004 case OP_LOADI1_MEMBASE:
2005 EMIT_LOAD_MEMBASE (ins, ldsb);
2007 case OP_LOADU2_MEMBASE:
2008 EMIT_LOAD_MEMBASE (ins, lduh);
2010 case OP_LOADI2_MEMBASE:
2011 EMIT_LOAD_MEMBASE (ins, ldsh);
2014 sparc_sll_imm (code, ins->sreg1, 24, sparc_o7);
2015 sparc_sra_imm (code, sparc_o7, 24, ins->dreg);
2018 sparc_sll_imm (code, ins->sreg1, 16, sparc_o7);
2019 sparc_sra_imm (code, sparc_o7, 16, ins->dreg);
2021 /* GCC does this one differently. Don't ask me WHY. */
2023 sparc_and_imm (code, FALSE, ins->sreg1, 0xff, ins->dreg);
2026 sparc_sll_imm (code, ins->sreg1, 16, sparc_o7);
2027 sparc_srl_imm (code, sparc_o7, 16, ins->dreg);
2030 sparc_cmp (code, ins->sreg1, ins->sreg2);
2032 case OP_COMPARE_IMM:
2033 if (sparc_is_imm13 (ins->inst_imm))
2034 sparc_cmp_imm (code, ins->sreg1, ins->inst_imm);
2036 sparc_set (code, ins->inst_imm, sparc_o7);
2037 sparc_cmp (code, ins->sreg1, sparc_o7);
2040 case OP_X86_TEST_NULL:
2041 sparc_cmp_imm (code, ins->sreg1, 0);
2047 sparc_add (code, TRUE, ins->sreg1, ins->sreg2, ins->dreg);
2050 sparc_add (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2053 sparc_addx (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2056 EMIT_ALU_IMM (ins, add, FALSE);
2059 EMIT_ALU_IMM (ins, addx, FALSE);
2062 sparc_sub (code, TRUE, ins->sreg1, ins->sreg2, ins->dreg);
2065 sparc_sub (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2068 sparc_subx (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2071 // we add the negated value
2072 if (sparc_is_imm13 (- ins->inst_imm))
2073 sparc_add_imm (code, FALSE, ins->sreg1, -ins->inst_imm, ins->dreg);
2075 sparc_set (code, - ins->inst_imm, sparc_o7);
2076 sparc_add (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
2080 EMIT_ALU_IMM (ins, subx, FALSE);
2083 sparc_and (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2086 EMIT_ALU_IMM (ins, and, FALSE);
2089 /* Sign extend sreg1 into %y */
2090 sparc_sra_imm (code, ins->sreg1, 31, sparc_o7);
2091 sparc_wry (code, sparc_o7, sparc_g0);
2092 sparc_sdiv (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2095 sparc_wry (code, sparc_g0, sparc_g0);
2096 sparc_udiv (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2099 /* Sign extend sreg1 into %y */
2100 sparc_sra_imm (code, ins->sreg1, 31, sparc_o7);
2101 sparc_wry (code, sparc_o7, sparc_g0);
2102 EMIT_ALU_IMM (ins, sdiv, FALSE);
2105 /* Sign extend sreg1 into %y */
2106 sparc_sra_imm (code, ins->sreg1, 31, sparc_o7);
2107 sparc_wry (code, sparc_o7, sparc_g0);
2108 sparc_sdiv (code, FALSE, ins->sreg1, ins->sreg2, sparc_o7);
2109 sparc_smul (code, FALSE, ins->sreg2, sparc_o7, sparc_o7);
2110 sparc_sub (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
2113 sparc_wry (code, sparc_g0, sparc_g0);
2114 sparc_udiv (code, FALSE, ins->sreg1, ins->sreg2, sparc_o7);
2115 sparc_umul (code, FALSE, ins->sreg2, sparc_o7, sparc_o7);
2116 sparc_sub (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
2119 /* Sign extend sreg1 into %y */
2120 sparc_sra_imm (code, ins->sreg1, 31, sparc_o7);
2121 sparc_wry (code, sparc_o7, sparc_g0);
2122 if (!sparc_is_imm13 (ins->inst_imm)) {
2123 sparc_set (code, ins->inst_imm, sparc_g1);
2124 sparc_sdiv (code, FALSE, ins->sreg1, sparc_g1, sparc_o7);
2125 sparc_smul (code, FALSE, sparc_o7, sparc_g1, sparc_o7);
2128 sparc_sdiv_imm (code, FALSE, ins->sreg1, ins->inst_imm, sparc_o7);
2129 sparc_smul_imm (code, FALSE, sparc_o7, ins->inst_imm, sparc_o7);
2131 sparc_sub (code, FALSE, ins->sreg1, sparc_o7, ins->dreg);
2134 sparc_or (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2137 EMIT_ALU_IMM (ins, or, FALSE);
2140 sparc_xor (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2143 EMIT_ALU_IMM (ins, xor, FALSE);
2146 sparc_sll (code, ins->sreg1, ins->sreg2, ins->dreg);
2149 if (sparc_is_imm13 (ins->inst_imm))
2150 sparc_sll_imm (code, ins->sreg1, ins->inst_imm, ins->dreg);
2152 sparc_set (code, ins->inst_imm, sparc_o7);
2153 sparc_sll (code, ins->sreg1, sparc_o7, ins->dreg);
2157 sparc_sra (code, ins->sreg1, ins->sreg2, ins->dreg);
2160 if (sparc_is_imm13 (ins->inst_imm))
2161 sparc_sra_imm (code, ins->sreg1, ins->inst_imm, ins->dreg);
2163 sparc_set (code, ins->inst_imm, sparc_o7);
2164 sparc_sra (code, ins->sreg1, sparc_o7, ins->dreg);
2168 if (sparc_is_imm13 (ins->inst_imm))
2169 sparc_srl_imm (code, ins->sreg1, ins->inst_imm, ins->dreg);
2171 sparc_set (code, ins->inst_imm, sparc_o7);
2172 sparc_srl (code, ins->sreg1, sparc_o7, ins->dreg);
2176 sparc_srl (code, ins->sreg1, ins->sreg2, ins->dreg);
2179 /* can't use sparc_not */
2180 sparc_xnor (code, FALSE, ins->sreg1, sparc_g0, ins->dreg);
2183 /* can't use sparc_neg */
2184 sparc_sub (code, FALSE, sparc_g0, ins->sreg1, ins->dreg);
2187 sparc_smul (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2190 EMIT_ALU_IMM (ins, smul, FALSE);
2194 sparc_smul (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2196 case CEE_MUL_OVF_UN:
2198 sparc_umul (code, FALSE, ins->sreg1, ins->sreg2, ins->dreg);
2202 sparc_set (code, ins->inst_c0, ins->dreg);
2208 if (ins->sreg1 != ins->dreg)
2209 sparc_mov_reg_reg (code, ins->sreg1, ins->dreg);
2212 g_assert_not_reached ();
2215 /* ensure ins->sreg1 is not NULL */
2216 sparc_ld_imm (code, ins->sreg1, 0, sparc_g0);
2223 call = (MonoCallInst*)ins;
2224 if (ins->flags & MONO_INST_HAS_METHOD)
2225 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method);
2227 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr);
2228 sparc_call_simple (code, 0);
2231 code = emit_move_return_value (ins, code);
2236 case OP_VOIDCALL_REG:
2238 call = (MonoCallInst*)ins;
2239 sparc_jmpl (code, ins->sreg1, sparc_g0, sparc_callsite);
2242 code = emit_move_return_value (ins, code);
2244 case OP_FCALL_MEMBASE:
2245 case OP_LCALL_MEMBASE:
2246 case OP_VCALL_MEMBASE:
2247 case OP_VOIDCALL_MEMBASE:
2248 case OP_CALL_MEMBASE:
2249 call = (MonoCallInst*)ins;
2250 g_assert (sparc_is_imm13 (ins->inst_offset));
2252 sparc_ld_imm (code, ins->inst_basereg, ins->inst_offset, sparc_o7);
2253 sparc_jmpl (code, sparc_o7, sparc_g0, sparc_callsite);
2256 code = emit_move_return_value (ins, code);
2259 g_assert_not_reached ();
2265 /* The return is done in the epilog */
2266 g_assert_not_reached ();
2269 sparc_unimp (code, 0);
2276 case CEE_ENDFINALLY:
2279 case OP_CALL_HANDLER:
2283 ins->inst_c0 = (guint8*)code - cfg->native_code;
2286 //g_print ("target: %p, next: %p, curr: %p, last: %p\n", ins->inst_target_bb, bb->next_bb, ins, bb->last_ins);
2287 if ((ins->inst_target_bb == bb->next_bb) && ins == bb->last_ins)
2289 if (ins->flags & MONO_INST_BRLABEL) {
2290 if (ins->inst_i0->inst_c0) {
2291 gint32 disp = (ins->inst_i0->inst_c0 - ((guint8*)code - cfg->native_code)) >> 2;
2292 g_assert (sparc_is_imm22 (disp));
2293 sparc_branch (code, 1, sparc_ba, disp);
2295 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_LABEL, ins->inst_i0);
2296 sparc_branch (code, 1, sparc_ba, 0);
2299 if (ins->inst_target_bb->native_offset) {
2300 gint32 disp = (ins->inst_target_bb->native_offset - ((guint8*)code - cfg->native_code)) >> 2;
2301 g_assert (sparc_is_imm22 (disp));
2302 sparc_branch (code, 1, sparc_ba, disp);
2304 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
2305 sparc_branch (code, 1, sparc_ba, 0);
2311 sparc_jmp (code, ins->sreg1, sparc_g0);
2319 sparc_clr_reg (code, ins->dreg);
2320 sparc_branch (code, 1, opcode_to_sparc_cond (ins->opcode), 2);
2322 sparc_set (code, 1, ins->dreg);
2324 case OP_COND_EXC_EQ:
2325 case OP_COND_EXC_NE_UN:
2326 case OP_COND_EXC_LT:
2327 case OP_COND_EXC_LT_UN:
2328 case OP_COND_EXC_GT:
2329 case OP_COND_EXC_GT_UN:
2330 case OP_COND_EXC_GE:
2331 case OP_COND_EXC_GE_UN:
2332 case OP_COND_EXC_LE:
2333 case OP_COND_EXC_LE_UN:
2334 case OP_COND_EXC_OV:
2335 case OP_COND_EXC_NO:
2337 case OP_COND_EXC_NC:
2339 //EMIT_COND_SYSTEM_EXCEPTION (branch_cc_table [ins->opcode - OP_COND_EXC_EQ],
2340 // (ins->opcode < OP_COND_EXC_NE_UN), ins->inst_p1);
2352 EMIT_COND_BRANCH (ins, opcode_to_sparc_cond (ins->opcode));
2355 /* floating point opcodes */
2357 double d = *(double*)ins->inst_p0;
2359 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_R8, ins->inst_p0);
2360 sparc_sethi (code, 0, sparc_o7);
2361 sparc_lddf_imm (code, sparc_o7, 0, ins->dreg);
2365 float f = *(float*)ins->inst_p0;
2367 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_R4, ins->inst_p0);
2368 sparc_sethi (code, 0, sparc_o7);
2369 sparc_ldf_imm (code, sparc_o7, 0, ins->dreg);
2371 /* Extend to double */
2372 sparc_fstod (code, ins->dreg, ins->dreg);
2375 case OP_STORER8_MEMBASE_REG:
2376 if (!sparc_is_imm13 (ins->inst_offset + 4)) {
2377 sparc_set (code, ins->inst_offset, sparc_o7);
2378 if (ins->inst_offset % 8) {
2380 sparc_add (code, FALSE, ins->inst_destbasereg, sparc_o7, sparc_o7);
2381 sparc_stf (code, ins->sreg1, sparc_o7, sparc_g0);
2382 sparc_stf_imm (code, ins->sreg1 + 1, sparc_o7, 4);
2384 sparc_stdf (code, ins->sreg1, ins->inst_destbasereg, sparc_o7);
2387 if (ins->inst_offset % 8) {
2389 sparc_stf_imm (code, ins->sreg1, ins->inst_destbasereg, ins->inst_offset);
2390 sparc_stf_imm (code, ins->sreg1 + 1, ins->inst_destbasereg, ins->inst_offset + 4);
2392 sparc_stdf_imm (code, ins->sreg1, ins->inst_destbasereg, ins->inst_offset);
2395 case OP_LOADR8_MEMBASE:
2396 g_assert ((ins->inst_offset % 8) == 0);
2397 EMIT_LOAD_MEMBASE (ins, lddf);
2399 case OP_STORER4_MEMBASE_REG:
2400 /* This requires a double->single conversion */
2401 sparc_fdtos (code, ins->sreg1, sparc_f0);
2402 if (!sparc_is_imm13 (ins->inst_offset)) {
2403 sparc_set (code, ins->inst_offset, sparc_o7);
2404 sparc_stf (code, sparc_f0, ins->inst_destbasereg, sparc_o7);
2407 sparc_stf_imm (code, sparc_f0, ins->inst_destbasereg, ins->inst_offset);
2409 case OP_LOADR4_MEMBASE:
2410 EMIT_LOAD_MEMBASE (ins, ldf);
2411 /* Extend to double */
2412 sparc_fstod (code, ins->dreg, ins->dreg);
2415 sparc_fmovs (code, ins->sreg1, ins->dreg);
2416 sparc_fmovs (code, ins->sreg1 + 1, ins->dreg + 1);
2419 g_assert (sparc_is_imm13 (cfg->stack_offset));
2420 sparc_st_imm (code, ins->sreg1, sparc_sp, cfg->stack_offset - 8);
2421 sparc_ldf_imm (code, sparc_sp, cfg->stack_offset - 8, sparc_f0);
2422 sparc_fitos (code, sparc_f0, sparc_f0);
2423 sparc_fstod (code, sparc_f0, ins->dreg);
2426 g_assert (sparc_is_imm13 (cfg->stack_offset));
2427 sparc_st_imm (code, ins->sreg1, sparc_sp, cfg->stack_offset - 8);
2428 sparc_ldf_imm (code, sparc_sp, cfg->stack_offset - 8, sparc_f0);
2429 sparc_fitod (code, sparc_f0, ins->dreg);
2431 case OP_FCONV_TO_I1:
2434 case OP_FCONV_TO_U1:
2437 case OP_FCONV_TO_I2:
2440 case OP_FCONV_TO_U2:
2443 case OP_FCONV_TO_I4:
2445 sparc_fdtoi (code, ins->sreg1, sparc_f0);
2446 sparc_stdf_imm (code, sparc_f0, sparc_sp, cfg->stack_offset - 8);
2447 sparc_ld_imm (code, sparc_sp, cfg->stack_offset - 8, ins->dreg);
2449 case OP_FCONV_TO_U4:
2453 case OP_FCONV_TO_I8:
2454 case OP_FCONV_TO_U8:
2457 case OP_LCONV_TO_R_UN: {
2461 case OP_LCONV_TO_OVF_I: {
2462 guint32 *br [3], *label [1];
2465 * Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000
2467 sparc_cmp_imm (code, ins->sreg1, 0);
2469 sparc_branch (code, 1, sparc_bneg, 0);
2473 /* ms word must be 0 */
2474 sparc_cmp_imm (code, ins->sreg2, 0);
2476 sparc_branch (code, 1, sparc_be, 0);
2480 /* FIXME: throw exception */
2483 sparc_patch (br [0], code);
2485 /* ms word must 0xfffffff */
2486 sparc_cmp_imm (code, ins->sreg2, -1);
2487 sparc_branch (code, 1, sparc_bne, label [0]);
2490 sparc_patch (br [1], code);
2491 if (ins->sreg1 != ins->dreg)
2492 sparc_mov_reg_reg (code, ins->sreg1, ins->dreg);
2496 sparc_faddd (code, ins->sreg1, ins->sreg2, ins->dreg);
2499 sparc_fsubd (code, ins->sreg1, ins->sreg2, ins->dreg);
2502 sparc_fmuld (code, ins->sreg1, ins->sreg2, ins->dreg);
2505 sparc_fdivd (code, ins->sreg1, ins->sreg2, ins->dreg);
2508 sparc_fnegs (code, ins->sreg1, ins->dreg);
2511 sparc_fdivd (code, ins->sreg1, ins->sreg2, sparc_f0);
2512 sparc_fmuld (code, ins->sreg2, sparc_f0, sparc_f0);
2513 sparc_fsubd (code, ins->sreg1, sparc_f0, ins->dreg);
2516 sparc_fcmpd (code, ins->sreg1, ins->sreg2);
2523 sparc_fcmpd (code, ins->sreg1, ins->sreg2);
2524 sparc_clr_reg (code, ins->dreg);
2525 switch (ins->opcode) {
2528 sparc_fbranch (code, 1, opcode_to_sparc_cond (ins->opcode), 4);
2530 sparc_set (code, 1, ins->dreg);
2531 sparc_fbranch (code, 1, sparc_fbu, 2);
2533 sparc_set (code, 1, ins->dreg);
2536 sparc_fbranch (code, 1, opcode_to_sparc_cond (ins->opcode), 2);
2538 sparc_set (code, 1, ins->dreg);
2544 EMIT_FLOAT_COND_BRANCH (ins, opcode_to_sparc_cond (ins->opcode));
2547 /* clt.un + brfalse */
2549 sparc_fbranch (code, 1, sparc_fbul, 0);
2552 EMIT_FLOAT_COND_BRANCH (ins, sparc_fba);
2553 sparc_patch ((guint8*)p, (guint8*)code);
2557 /* cgt.un + brfalse */
2559 sparc_fbranch (code, 1, sparc_fbug, 0);
2562 EMIT_FLOAT_COND_BRANCH (ins, sparc_fba);
2563 sparc_patch ((guint8*)p, (guint8*)code);
2567 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbne);
2568 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu);
2571 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbl);
2572 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu);
2575 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbg);
2576 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu);
2579 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbge);
2580 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu);
2583 EMIT_FLOAT_COND_BRANCH (ins, sparc_fble);
2584 EMIT_FLOAT_COND_BRANCH (ins, sparc_fbu);
2586 case CEE_CKFINITE: {
2592 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
2594 g_warning ("%s:%d: unknown opcode %s\n", __FILE__, __LINE__, mono_inst_name (ins->opcode));
2596 g_assert_not_reached ();
2599 if ((cfg->opt & MONO_OPT_BRANCH) && (((guint8*)code - cfg->native_code - offset) > max_len)) {
2600 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
2601 mono_inst_name (ins->opcode), max_len, (guint8*)code - cfg->native_code - offset);
2602 g_assert_not_reached ();
2608 last_offset = offset;
2613 cfg->code_len = (guint8*)code - cfg->native_code;
2617 mono_arch_register_lowlevel_calls (void)
2622 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
2624 MonoJumpInfo *patch_info;
2626 /* FIXME: Move part of this to arch independent code */
2627 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
2628 unsigned char *ip = patch_info->ip.i + code;
2629 const unsigned char *target = NULL;
2631 switch (patch_info->type) {
2632 case MONO_PATCH_INFO_BB:
2633 target = patch_info->data.bb->native_offset + code;
2635 case MONO_PATCH_INFO_ABS:
2636 target = patch_info->data.target;
2638 case MONO_PATCH_INFO_LABEL:
2639 target = patch_info->data.inst->inst_c0 + code;
2641 case MONO_PATCH_INFO_IP:
2642 *((gpointer *)(ip)) = ip;
2644 case MONO_PATCH_INFO_METHOD_REL:
2646 *((gpointer *)(ip)) = code + patch_info->data.offset;
2648 case MONO_PATCH_INFO_INTERNAL_METHOD: {
2649 MonoJitICallInfo *mi = mono_find_jit_icall_by_name (patch_info->data.name);
2651 g_warning ("unknown MONO_PATCH_INFO_INTERNAL_METHOD %s", patch_info->data.name);
2652 g_assert_not_reached ();
2654 target = mono_icall_get_wrapper (mi);
2657 case MONO_PATCH_INFO_METHOD_JUMP: {
2660 /* get the trampoline to the method from the domain */
2661 target = mono_arch_create_jump_trampoline (patch_info->data.method);
2662 if (!domain->jump_target_hash)
2663 domain->jump_target_hash = g_hash_table_new (NULL, NULL);
2664 list = g_hash_table_lookup (domain->jump_target_hash, patch_info->data.method);
2665 list = g_slist_prepend (list, ip);
2666 g_hash_table_insert (domain->jump_target_hash, patch_info->data.method, list);
2669 case MONO_PATCH_INFO_METHOD:
2670 if (patch_info->data.method == method) {
2673 /* get the trampoline to the method from the domain */
2674 target = mono_arch_create_jit_trampoline (patch_info->data.method);
2676 case MONO_PATCH_INFO_SWITCH: {
2677 guint32 *p = (guint32*)ip;
2678 gpointer *jump_table = mono_code_manager_reserve (domain->code_mp, sizeof (gpointer) * patch_info->table_size);
2681 target = jump_table;
2683 for (i = 0; i < patch_info->table_size; i++) {
2684 jump_table [i] = code + (int)patch_info->data.table [i];
2688 case MONO_PATCH_INFO_METHODCONST:
2689 case MONO_PATCH_INFO_CLASS:
2690 case MONO_PATCH_INFO_IMAGE:
2691 case MONO_PATCH_INFO_FIELD:
2693 *((gconstpointer *)(ip + 1)) = patch_info->data.target;
2695 case MONO_PATCH_INFO_IID:
2697 mono_class_init (patch_info->data.klass);
2698 *((guint32 *)(ip + 1)) = patch_info->data.klass->interface_id;
2700 case MONO_PATCH_INFO_VTABLE:
2702 *((gconstpointer *)(ip + 1)) = mono_class_vtable (domain, patch_info->data.klass);
2704 case MONO_PATCH_INFO_CLASS_INIT: {
2705 /* Might already been changed to a nop */
2706 target = mono_create_class_init_trampoline (mono_class_vtable (domain, patch_info->data.klass));
2709 case MONO_PATCH_INFO_SFLDA: {
2710 MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
2711 if (!vtable->initialized && !(vtable->klass->flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT) && mono_class_needs_cctor_run (vtable->klass, method))
2712 /* Done by the generated code */
2716 mono_runtime_class_init (vtable);
2719 *((gconstpointer *)(ip + 1)) =
2720 (char*)vtable->data + patch_info->data.field->offset;
2723 case MONO_PATCH_INFO_R4: {
2724 float *f = g_new0 (float, 1);
2725 *f = *(float*)patch_info->data.target;
2729 case MONO_PATCH_INFO_R8: {
2730 double *d = g_new0 (double, 1);
2731 *d = *(double*)patch_info->data.target;
2735 case MONO_PATCH_INFO_EXC_NAME:
2737 *((gconstpointer *)(ip + 1)) = patch_info->data.name;
2739 case MONO_PATCH_INFO_LDSTR:
2741 *((gconstpointer *)(ip + 1)) =
2742 mono_ldstr (domain, patch_info->data.token->image,
2743 mono_metadata_token_index (patch_info->data.token->token));
2745 case MONO_PATCH_INFO_TYPE_FROM_HANDLE: {
2747 MonoClass *handle_class;
2749 handle = mono_ldtoken (patch_info->data.token->image,
2750 patch_info->data.token->token, &handle_class);
2751 mono_class_init (handle_class);
2752 mono_class_init (mono_class_from_mono_type (handle));
2755 *((gconstpointer *)(ip + 1)) =
2756 mono_type_get_object (domain, handle);
2759 case MONO_PATCH_INFO_LDTOKEN: {
2761 MonoClass *handle_class;
2763 handle = mono_ldtoken (patch_info->data.token->image,
2764 patch_info->data.token->token, &handle_class);
2765 mono_class_init (handle_class);
2768 *((gconstpointer *)(ip + 1)) = handle;
2772 g_assert_not_reached ();
2774 sparc_patch (ip, target);
2779 * Allow tracing to work with this interface (with an optional argument)
2783 * This may be needed on some archs or for debugging support.
2786 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2788 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2790 /* split prolog-epilog requirements? */
2791 *code = 256; /* max bytes needed: check this number */
2795 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2797 int stack, code_size;
2798 guint32 *code = (guint32*)p;
2800 /* Save registers to stack */
2801 sparc_st_imm (code, sparc_i0, sparc_fp, 68);
2802 sparc_st_imm (code, sparc_i1, sparc_fp, 72);
2803 sparc_st_imm (code, sparc_i2, sparc_fp, 76);
2804 sparc_st_imm (code, sparc_i3, sparc_fp, 80);
2805 sparc_st_imm (code, sparc_i4, sparc_fp, 84);
2807 sparc_set (code, cfg->method, sparc_o0);
2808 sparc_mov_reg_reg (code, sparc_fp, sparc_o1);
2810 mono_add_patch_info (cfg, (guint8*)code-cfg->native_code, MONO_PATCH_INFO_ABS, func);
2811 sparc_sethi (code, 0, sparc_o7);
2812 sparc_jmpl_imm (code, sparc_o7, 0, sparc_callsite);
2815 mono_arch_instrument_mem_needs (cfg->method, &stack, &code_size);
2817 g_assert ((code - (guint32*)p) <= (code_size * 4));
2831 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2834 int arg_size = 0, save_mode = SAVE_NONE;
2835 MonoMethod *method = cfg->method;
2836 int rtype = method->signature->ret->type;
2840 case MONO_TYPE_VOID:
2841 /* special case string .ctor icall */
2842 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2843 save_mode = SAVE_ONE;
2845 save_mode = SAVE_NONE;
2849 save_mode = SAVE_TWO;
2853 save_mode = SAVE_FP;
2855 case MONO_TYPE_VALUETYPE:
2856 if (method->signature->ret->data.klass->enumtype) {
2857 rtype = method->signature->ret->data.klass->enum_basetype->type;
2860 save_mode = SAVE_STRUCT;
2863 save_mode = SAVE_ONE;
2867 /* Save the result to the stack and also put it into the output registers */
2869 switch (save_mode) {
2871 sparc_st_imm (code, sparc_i0, sparc_fp, 68);
2872 sparc_st_imm (code, sparc_i0, sparc_fp, 72);
2873 sparc_mov_reg_reg (code, sparc_i0, sparc_o1);
2874 sparc_mov_reg_reg (code, sparc_i1, sparc_o2);
2877 sparc_st_imm (code, sparc_i0, sparc_fp, 68);
2878 sparc_mov_reg_reg (code, sparc_i0, sparc_o1);
2881 sparc_stdf (code, sparc_f0, sparc_fp, 72);
2882 sparc_ld_imm (code, sparc_fp, 72, sparc_o1);
2883 sparc_ld_imm (code, sparc_fp, 72, sparc_o2);
2886 sparc_ld_imm (code, sparc_fp, 64, sparc_o1);
2893 sparc_set (code, cfg->method, sparc_o0);
2895 mono_add_patch_info (cfg, (guint8*)code-cfg->native_code, MONO_PATCH_INFO_ABS, func);
2896 sparc_sethi (code, 0, sparc_o7);
2897 sparc_jmpl_imm (code, sparc_o7, 0, sparc_callsite);
2900 /* Restore result */
2902 switch (save_mode) {
2904 sparc_ld_imm (code, sparc_fp, 68, sparc_i0);
2905 sparc_ld_imm (code, sparc_fp, 72, sparc_i0);
2908 sparc_ld_imm (code, sparc_fp, 68, sparc_i0);
2911 sparc_lddf_imm (code, sparc_fp, 72, sparc_f0);
2922 mono_arch_max_epilog_size (MonoCompile *cfg)
2924 int exc_count = 0, max_epilog_size = 16 + 20*4;
2925 MonoJumpInfo *patch_info;
2927 if (cfg->method->save_lmf)
2928 max_epilog_size += 128;
2930 if (mono_jit_trace_calls != NULL)
2931 max_epilog_size += 50;
2933 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
2934 max_epilog_size += 50;
2936 /* count the number of exception infos */
2938 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
2939 if (patch_info->type == MONO_PATCH_INFO_EXC)
2944 * make sure we have enough space for exceptions
2945 * 16 is the size of two push_imm instructions and a call
2947 max_epilog_size += exc_count*16;
2949 return max_epilog_size;
2953 mono_arch_emit_prolog (MonoCompile *cfg)
2955 MonoMethod *method = cfg->method;
2957 MonoMethodSignature *sig;
2959 int alloc_size, pos, max_offset, i;
2963 cfg->code_size = 256;
2964 code = cfg->native_code = g_malloc (cfg->code_size);
2967 * Align stack_offset. It is aligned at the end of allocate_vars, but
2968 * spillvars may make in unaligned.
2970 cfg->stack_offset += (MONO_ARCH_FRAME_ALIGNMENT - 1);
2971 cfg->stack_offset &= ~(MONO_ARCH_FRAME_ALIGNMENT - 1);
2973 if (!sparc_is_imm13 (- cfg->stack_offset)) {
2974 /* Can't use sparc_o7 here, since we're still in the caller's frame */
2975 sparc_set (code, (- cfg->stack_offset), sparc_g1);
2976 sparc_save (code, sparc_sp, sparc_g1, sparc_sp);
2979 sparc_save_imm (code, sparc_sp, - cfg->stack_offset, sparc_sp);
2981 sig = method->signature;
2986 cinfo = get_call_info (sig, FALSE);
2988 for (i = 0; i < sig->param_count; ++i) {
2989 ArgInfo *ainfo = cinfo->args + pos;
2990 guint32 stack_offset;
2991 inst = cfg->varinfo [pos];
2993 stack_offset = ainfo->offset + 68;
2995 /* Save the split arguments so they will reside entirely on the stack */
2996 if (ainfo->storage == ArgInSplitRegStack) {
2997 /* Save the register to the stack */
2998 g_assert (inst->opcode == OP_REGOFFSET);
2999 if (!sparc_is_imm13 (stack_offset))
3001 sparc_st_imm (code, sparc_i5, inst->inst_basereg, stack_offset);
3004 if (sig->params [i]->type == MONO_TYPE_R8) {
3005 /* Save the argument to a dword aligned stack location */
3007 * stack_offset contains the offset of the argument on the stack.
3008 * inst->inst_offset contains the dword aligned offset where the value
3011 if (ainfo->storage == ArgInIRegPair) {
3012 if (!sparc_is_imm13 (inst->inst_offset + 4))
3014 sparc_st_imm (code, sparc_i0 + ainfo->reg, inst->inst_basereg, inst->inst_offset);
3015 sparc_st_imm (code, sparc_i0 + ainfo->reg + 1, inst->inst_basereg, inst->inst_offset + 4);
3018 if (ainfo->storage == ArgInSplitRegStack) {
3019 if (stack_offset != inst->inst_offset) {
3020 /* stack_offset is not dword aligned, so we need to make a copy */
3021 sparc_st_imm (code, sparc_i5, inst->inst_basereg, inst->inst_offset);
3022 sparc_ld_imm (code, sparc_fp, stack_offset + 4, sparc_o7);
3023 sparc_st_imm (code, sparc_o7, inst->inst_basereg, inst->inst_offset + 4);
3027 if (ainfo->storage == ArgOnStackPair) {
3028 if (stack_offset != inst->inst_offset) {
3029 /* stack_offset is not dword aligned, so we need to make a copy */
3030 sparc_ld_imm (code, sparc_fp, stack_offset, sparc_o7);
3031 sparc_st_imm (code, sparc_o7, inst->inst_basereg, inst->inst_offset);
3032 sparc_ld_imm (code, sparc_fp, stack_offset + 4, sparc_o7);
3033 sparc_st_imm (code, sparc_o7, inst->inst_basereg, inst->inst_offset + 4);
3037 g_assert_not_reached ();
3040 if ((ainfo->storage == ArgInIReg) && (inst->opcode != OP_REGVAR)) {
3041 /* Argument in register, but need to be saved to stack */
3042 if (!sparc_is_imm13 (stack_offset))
3044 sparc_st_imm (code, sparc_i0 + ainfo->reg, inst->inst_basereg, stack_offset);
3047 if ((ainfo->storage == ArgInIRegPair) && (inst->opcode != OP_REGVAR)) {
3048 /* Argument in regpair, but need to be saved to stack */
3049 g_assert (((inst->inst_offset) % 8) == 0);
3050 if (!sparc_is_imm13 (inst->inst_offset + 4))
3052 sparc_st_imm (code, sparc_i0 + ainfo->reg, inst->inst_basereg, inst->inst_offset);
3053 sparc_st_imm (code, sparc_i0 + ainfo->reg + 1, inst->inst_basereg, inst->inst_offset + 4);
3061 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
3062 code = mono_arch_instrument_prolog (cfg, mono_trace_enter_method, code, TRUE);
3064 cfg->code_len = code - cfg->native_code;
3066 g_assert (cfg->code_len <= cfg->code_size);
3072 mono_arch_emit_epilog (MonoCompile *cfg)
3074 MonoJumpInfo *patch_info;
3075 MonoMethod *method = cfg->method;
3079 code = cfg->native_code + cfg->code_len;
3081 if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
3082 code = mono_arch_instrument_epilog (cfg, mono_trace_leave_method, code, TRUE);
3085 sparc_restore_imm (code, sparc_g0, 0, sparc_g0);
3092 if (method->save_lmf) {
3093 pos = -sizeof (MonoLMF);
3096 if (method->save_lmf) {
3098 /* ebx = previous_lmf */
3099 x86_pop_reg (code, X86_EBX);
3101 x86_pop_reg (code, X86_EDI);
3102 /* *(lmf) = previous_lmf */
3103 x86_mov_membase_reg (code, X86_EDI, 0, X86_EBX, 4);
3105 /* discard method info */
3106 x86_pop_reg (code, X86_ESI);
3108 /* restore caller saved regs */
3109 x86_pop_reg (code, X86_EBP);
3110 x86_pop_reg (code, X86_ESI);
3111 x86_pop_reg (code, X86_EDI);
3112 x86_pop_reg (code, X86_EBX);
3116 if (1 || cfg->flags & MONO_CFG_HAS_CALLS) {
3117 //ppc_lwz (code, sparc_l0, cfg->stack_usage + 8, cfg->frame_reg);
3118 //ppc_mtlr (code, sparc_l0);
3120 //ppc_addic (code, ppc_sp, cfg->frame_reg, cfg->stack_usage);
3121 for (i = 13; i < 32; ++i) {
3122 if (cfg->used_int_regs & (1 << i)) {
3124 //ppc_lwz (code, i, -pos, cfg->frame_reg);
3129 /* add code to raise exceptions */
3130 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
3131 switch (patch_info->type) {
3132 case MONO_PATCH_INFO_EXC:
3133 /*x86_patch (patch_info->ip.i + cfg->native_code, code);
3134 x86_push_imm (code, patch_info->data.target);
3135 x86_push_imm (code, patch_info->ip.i + cfg->native_code);
3136 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
3137 patch_info->data.name = "throw_exception_by_name";
3138 patch_info->ip.i = code - cfg->native_code;
3139 x86_jump_code (code, 0);*/
3148 cfg->code_len = code - cfg->native_code;
3150 g_assert (cfg->code_len < cfg->code_size);
3155 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
3160 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
3165 mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
3167 /* add the this argument */
3168 if (this_reg != -1) {
3170 MONO_INST_NEW (cfg, this, OP_SETREG);
3171 this->type = this_type;
3172 this->sreg1 = this_reg;
3173 this->dreg = sparc_o0;
3174 mono_bblock_add_inst (cfg->cbb, this);
3178 /* Set the 'struct/union return pointer' location on the stack */
3179 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, sparc_sp, 64, vt_reg);
3185 mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
3191 * mono_arch_get_argument_info:
3192 * @csig: a method signature
3193 * @param_count: the number of parameters to consider
3194 * @arg_info: an array to store the result infos
3196 * Gathers information on parameters such as size, alignment and
3197 * padding. arg_info should be large enought to hold param_count + 1 entries.
3199 * Returns the size of the activation frame.
3202 mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
3204 int k, frame_size = 0;
3205 int size, align, pad;
3210 cinfo = get_call_info (csig, FALSE);
3212 if (csig->hasthis) {
3213 ainfo = &cinfo->args [0];
3214 arg_info [0].offset = 68 + ainfo->offset;
3217 for (k = 0; k < param_count; k++) {
3218 ainfo = &cinfo->args [k + csig->hasthis];
3220 arg_info [k + 1].offset = 68 + ainfo->offset;
3221 arg_info [k + 1].size = mono_type_size (csig->params [k], &align);