X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fcfold.c;h=da291f47ab54fe474de156ea760709537c8a0d38;hb=a4240142a9a1a7187cd4b181efa94aeaee7f79ef;hp=89221fe721c090006102ac2c3edeb6b6b80873a4;hpb=3331634f37c395ea87d15a2f3338b2bc66a8470a;p=mono.git diff --git a/mono/mini/cfold.c b/mono/mini/cfold.c index 89221fe721c..da291f47ab5 100644 --- a/mono/mini/cfold.c +++ b/mono/mini/cfold.c @@ -7,8 +7,12 @@ * * (C) 2003 Ximian, Inc. http://www.ximian.com */ +#include + #include "mini.h" +#include "ir-emit.h" +/* WTF is this doing here?!?!? */ int mono_is_power_of_two (guint32 val) { @@ -58,15 +62,6 @@ mono_is_power_of_two (guint32 val) res = (cast)arg1->inst_c0 op (cast)arg2->inst_c0; \ break; \ -#undef MONO_INST_NEW -#define MONO_INST_NEW(cfg,dest,op) do { \ - (dest) = mono_mempool_alloc ((cfg)->mempool, sizeof (MonoInst)); \ - (dest)->inst_p0 = (dest)->inst_p1 = (dest)->next = NULL; \ - (dest)->opcode = (op); \ - (dest)->flags = 0; \ - (dest)->dreg = (dest)->sreg1 = (dest)->sreg2 = -1; \ - } while (0) - #define ALLOC_DEST(cfg, dest, ins) do { \ if (!(dest)) { \ MONO_INST_NEW ((cfg), (dest), -1); \ @@ -74,6 +69,8 @@ mono_is_power_of_two (guint32 val) } \ } while (0) +#ifndef DISABLE_JIT + /** * mono_constant_fold_ins: * @@ -107,7 +104,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns FOLD_BINOP (OP_IXOR, ^); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } } else if (arg1->opcode == OP_ICONST) { /* @@ -142,13 +139,13 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns FOLD_BINOP2_IMM (OP_IOR_IMM, |); FOLD_BINOP2_IMM (OP_IXOR_IMM, ^); FOLD_BINOP2_IMM (OP_ISUB_IMM, -); - FOLD_BINOP2_IMM (OP_ISHL_IMM, <<); - FOLD_BINOP2_IMM (OP_ISHR_IMM, >>); + FOLD_BINOPC2_IMM (OP_ISHL_IMM, <<, gint32); + FOLD_BINOPC2_IMM (OP_ISHR_IMM, >>, gint32); FOLD_BINOPC2_IMM (OP_ISHR_UN_IMM, >>, guint32); FOLD_BINOP2_IMM (OP_SHL_IMM, <<); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } break; case OP_ISUB: @@ -164,7 +161,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns FOLD_BINOPC (OP_ISHR_UN, >>, guint32); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } break; case OP_IDIV: @@ -182,7 +179,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns FOLD_BINOPC (OP_IREM_UN, %, guint32); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } break; case OP_IDIV_IMM: @@ -202,7 +199,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns g_assert_not_reached (); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } break; /* case OP_INEG: */ @@ -210,26 +207,28 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns case OP_INEG: if (arg1->opcode == OP_ICONST) { /* INEG sets cflags on x86, and the LNEG decomposition depends on that */ - if ((ins->opcode == OP_INEG) && ins->next && (ins->next->opcode == OP_ADC_IMM)) +#if SIZEOF_REGISTER == 4 + if (ins->opcode == OP_INEG) return NULL; +#endif ALLOC_DEST (cfg, dest, ins); switch (ins->opcode) { FOLD_UNOP (OP_INEG,-); FOLD_UNOP (OP_INOT,~); } dest->opcode = OP_ICONST; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); } break; case OP_MOVE: -#if SIZEOF_VOID_P == 8 +#if SIZEOF_REGISTER == 8 if ((arg1->opcode == OP_ICONST) || (arg1->opcode == OP_I8CONST)) { #else if (arg1->opcode == OP_ICONST) { #endif ALLOC_DEST (cfg, dest, ins); dest->opcode = arg1->opcode; - dest->sreg1 = dest->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (dest); dest->inst_c0 = arg1->inst_c0; } break; @@ -290,7 +289,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns NULLIFY_INS (ins); next->opcode = OP_ICONST; next->inst_c0 = res; - next->sreg1 = next->sreg2 = -1; + MONO_INST_NULLIFY_SREGS (next); } else { ALLOC_DEST (cfg, dest, ins); dest->opcode = OP_ICONST; @@ -336,6 +335,19 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns dest->inst_c0 = res; } break; + case OP_COND_EXC_EQ: + res = arg1->inst_c0 == arg2->inst_c0; + if (!res) { + if (overwrite) { + NULLIFY_INS (ins); + NULLIFY_INS (next); + } else { + ALLOC_DEST (cfg, dest, ins); + dest->opcode = OP_ICONST; + dest->inst_c0 = res; + } + } + break; case OP_NOP: case OP_BR: /* This happens when a conditional branch is eliminated */ @@ -349,6 +361,24 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns return NULL; } } + if ((arg1->opcode == OP_PCONST) && (arg2->opcode == OP_PCONST) && ins->next) { + MonoInst *next = ins->next; + + if (next->opcode == OP_LCEQ) { + gboolean res = arg1->inst_p0 == arg2->inst_p0; + if (overwrite) { + NULLIFY_INS (ins); + next->opcode = OP_ICONST; + next->inst_c0 = res; + MONO_INST_NULLIFY_SREGS (next); + } else { + ALLOC_DEST (cfg, dest, ins); + dest->opcode = OP_ICONST; + dest->inst_c0 = res; + } + break; + } + } break; } case OP_FMOVE: @@ -372,3 +402,6 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns return dest; } + + +#endif /* DISABLE_JIT */