X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fliveness.c;h=ee87dfa082ad509892177d58242c5dc7bf962971;hb=66e33aa2ee25b9de6ff80e41aa7036b9a8352479;hp=5f304b390fd41f0c9fbc36ef9b3bc22315042b4a;hpb=c19e821763cc90c6b12b31bf394dd29e6923dfdb;p=mono.git diff --git a/mono/mini/liveness.c b/mono/mini/liveness.c index 5f304b390fd..ee87dfa082a 100644 --- a/mono/mini/liveness.c +++ b/mono/mini/liveness.c @@ -20,6 +20,8 @@ #define BITS_PER_CHUNK MONO_BITSET_BITS_PER_CHUNK +#define BB_ID_SHIFT 18 + /* * The liveness2 pass can't handle long vars on 32 bit platforms because the component * vars have the same 'idx'. @@ -42,14 +44,14 @@ optimize_initlocals (MonoCompile *cfg); static inline MonoBitSet* mono_bitset_mp_new (MonoMemPool *mp, guint32 size, guint32 max_size) { - guint8 *mem = mono_mempool_alloc0 (mp, size); + guint8 *mem = (guint8 *)mono_mempool_alloc0 (mp, size); return mono_bitset_mem_new (mem, max_size, MONO_BITSET_DONT_FREE); } static inline MonoBitSet* mono_bitset_mp_new_noinit (MonoMemPool *mp, guint32 size, guint32 max_size) { - guint8 *mem = mono_mempool_alloc (mp, size); + guint8 *mem = (guint8 *)mono_mempool_alloc (mp, size); return mono_bitset_mem_new (mem, max_size, MONO_BITSET_DONT_FREE); } @@ -152,7 +154,7 @@ mono_liveness_handle_exception_clauses (MonoCompile *cfg) * Determine which clauses are outer try clauses, i.e. they are not contained in any * other non-try clause. */ - outer_try = mono_mempool_alloc0 (cfg->mempool, sizeof (gboolean) * header->num_clauses); + outer_try = (gboolean *)mono_mempool_alloc0 (cfg->mempool, sizeof (gboolean) * header->num_clauses); for (i = 0; i < header->num_clauses; ++i) outer_try [i] = TRUE; /* Iterate over the clauses backward, so outer clauses come first */ @@ -217,7 +219,7 @@ analyze_liveness_bb (MonoCompile *cfg, MonoBasicBlock *bb) MonoInst *ins; int sreg, inst_num; MonoMethodVar *vars = cfg->vars; - guint32 abs_pos = (bb->dfn << 16); + guint32 abs_pos = (bb->dfn << BB_ID_SHIFT); /* Start inst_num from > 0, so last_use.abs_pos is only 0 for dead variables */ for (inst_num = 2, ins = bb->code; ins; ins = ins->next, inst_num += 2) { @@ -236,7 +238,7 @@ analyze_liveness_bb (MonoCompile *cfg, MonoBasicBlock *bb) continue; if (ins->opcode == OP_LDADDR) { - MonoInst *var = ins->inst_p0; + MonoInst *var = (MonoInst *)ins->inst_p0; int idx = var->inst_c0; MonoMethodVar *vi = MONO_VARINFO (cfg, idx); @@ -492,7 +494,7 @@ mono_analyze_liveness (MonoCompile *cfg) for (i = 0; i < cfg->num_bblocks; ++i) { MonoBasicBlock *bb = cfg->bblocks [i]; guint32 max; - guint32 abs_pos = (bb->dfn << 16); + guint32 abs_pos = (bb->dfn << BB_ID_SHIFT); MonoMethodVar *vars = cfg->vars; if (!bb->live_out_set) @@ -512,7 +514,7 @@ mono_analyze_liveness (MonoCompile *cfg) if (bits_in & 1) update_live_range (&vars [k], abs_pos + 0); if (bits_out & 1) - update_live_range (&vars [k], abs_pos + 0xffff); + update_live_range (&vars [k], abs_pos + ((1 << BB_ID_SHIFT) - 1)); bits_in >>= 1; bits_out >>= 1; k ++; @@ -538,7 +540,7 @@ mono_analyze_liveness (MonoCompile *cfg) * VOLATILE, since that would prevent it from being allocated to * registers. */ - if (!cfg->disable_deadce_vars && !(cfg->generic_sharing_context && mono_method_signature (cfg->method)->hasthis && cfg->varinfo [vi->idx] == cfg->args [0])) + if (!cfg->disable_deadce_vars && !(cfg->gshared && mono_method_signature (cfg->method)->hasthis && cfg->varinfo [vi->idx] == cfg->args [0])) cfg->varinfo [vi->idx]->flags |= MONO_INST_IS_DEAD; } vi->range.first_use.abs_pos = 0; @@ -614,7 +616,7 @@ optimize_initlocals (MonoCompile *cfg) //printf ("DEAD: "); mono_print_ins (ins); if (cfg->disable_initlocals_opt_refs && var->type == STACK_OBJ) continue; - if ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST)) { + if ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST) || (ins->opcode == OP_R4CONST)) { NULLIFY_INS (ins); MONO_VARINFO (cfg, var->inst_c0)->spill_costs -= 1; /* @@ -658,7 +660,7 @@ mono_linterval_add_range (MonoCompile *cfg, MonoLiveInterval *interval, int from next_range->from = from; } else { /* Insert it */ - new_range = mono_mempool_alloc (cfg->mempool, sizeof (MonoLiveRange2)); + new_range = (MonoLiveRange2 *)mono_mempool_alloc (cfg->mempool, sizeof (MonoLiveRange2)); new_range->from = from; new_range->to = to; new_range->next = NULL; @@ -751,8 +753,8 @@ mono_linterval_split (MonoCompile *cfg, MonoLiveInterval *interval, MonoLiveInte g_assert (pos > interval->range->from && pos <= interval->last_range->to); - *i1 = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); - *i2 = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); + *i1 = (MonoLiveInterval *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); + *i2 = (MonoLiveInterval *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); for (r = interval->range; r; r = r->next) { if (pos > r->to) { @@ -788,7 +790,7 @@ update_liveness2 (MonoCompile *cfg, MonoInst *ins, gboolean set_volatile, int in LIVENESS_DEBUG (printf ("\t%x: ", inst_num); mono_print_ins (ins)); - if (ins->opcode == OP_NOP) + if (ins->opcode == OP_NOP || ins->opcode == OP_IL_SEQ_POINT) return; /* DREG */ @@ -810,14 +812,21 @@ update_liveness2 (MonoCompile *cfg, MonoInst *ins, gboolean set_volatile, int in } else { /* Try dead code elimination */ - if ((var != cfg->ret) && !(var->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT)) && ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST)) && !(var->flags & MONO_INST_VOLATILE)) { + if (!cfg->disable_deadce_vars && (var != cfg->ret) && !(var->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT)) && ((ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || (ins->opcode == OP_R8CONST)) && !(var->flags & MONO_INST_VOLATILE)) { LIVENESS_DEBUG (printf ("\tdead def of R%d, eliminated\n", ins->dreg)); NULLIFY_INS (ins); return; + } else { + int inst_num_add = 1; + MonoInst *next = ins->next; + while (next && next->opcode == OP_IL_SEQ_POINT) { + inst_num_add++; + next = next->next; + } + + LIVENESS_DEBUG (printf ("\tdead def of R%d, add range to R%d: [%x, %x]\n", ins->dreg, ins->dreg, inst_num, inst_num + inst_num_add)); + mono_linterval_add_range (cfg, vi->interval, inst_num, inst_num + inst_num_add); } - - LIVENESS_DEBUG (printf ("\tdead def of R%d, add range to R%d: [%x, %x]\n", ins->dreg, ins->dreg, inst_num, inst_num + 1)); - mono_linterval_add_range (cfg, vi->interval, inst_num, inst_num + 1); } } } @@ -852,6 +861,23 @@ mono_analyze_liveness2 (MonoCompile *cfg) if (disabled) return; + if (cfg->num_bblocks >= (1 << (32 - BB_ID_SHIFT - 1))) + /* Ranges would overflow */ + return; + + for (bnum = cfg->num_bblocks - 1; bnum >= 0; --bnum) { + MonoBasicBlock *bb = cfg->bblocks [bnum]; + MonoInst *ins; + + nins = 0; + for (nins = 0, ins = bb->code; ins; ins = ins->next, ++nins) + nins ++; + + if (nins >= ((1 << BB_ID_SHIFT) - 1)) + /* Ranges would overflow */ + return; + } + LIVENESS_DEBUG (printf ("LIVENESS 2 %s\n", mono_method_full_name (cfg->method, TRUE))); /* @@ -863,12 +889,12 @@ mono_analyze_liveness2 (MonoCompile *cfg) last_use = g_new0 (gint32, max_vars); reverse_len = 1024; - reverse = mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * reverse_len); + reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * reverse_len); for (idx = 0; idx < max_vars; ++idx) { MonoMethodVar *vi = MONO_VARINFO (cfg, idx); - vi->interval = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); + vi->interval = (MonoLiveInterval *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoLiveInterval)); } /* @@ -879,12 +905,12 @@ mono_analyze_liveness2 (MonoCompile *cfg) MonoBasicBlock *bb = cfg->bblocks [bnum]; MonoInst *ins; - block_from = (bb->dfn << 16) + 1; /* so pos > 0 */ + block_from = (bb->dfn << BB_ID_SHIFT) + 1; /* so pos > 0 */ if (bnum < cfg->num_bblocks - 1) /* Beginning of the next bblock */ - block_to = (cfg->bblocks [bnum + 1]->dfn << 16) + 1; + block_to = (cfg->bblocks [bnum + 1]->dfn << BB_ID_SHIFT) + 1; else - block_to = (bb->dfn << 16) + 0xffff; + block_to = (bb->dfn << BB_ID_SHIFT) + ((1 << BB_ID_SHIFT) - 1); LIVENESS_DEBUG (printf ("LIVENESS BLOCK BB%d:\n", bb->block_num)); @@ -915,7 +941,7 @@ mono_analyze_liveness2 (MonoCompile *cfg) for (nins = 0, pos = block_from, ins = bb->code; ins; ins = ins->next, ++nins, ++pos) { if (nins >= reverse_len) { int new_reverse_len = reverse_len * 2; - MonoInst **new_reverse = mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * new_reverse_len); + MonoInst **new_reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * new_reverse_len); memcpy (new_reverse, reverse, sizeof (MonoInst*) * reverse_len); reverse = new_reverse; reverse_len = new_reverse_len; @@ -999,17 +1025,17 @@ update_liveness_gc (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, gint32 /* Add it to the last callsite */ g_assert (*callsites); - last = (*callsites)->data; + last = (GCCallSite *)(*callsites)->data; last->param_slots = g_slist_prepend_mempool (cfg->mempool, last->param_slots, ins); } else if (ins->flags & MONO_INST_GC_CALLSITE) { - GCCallSite *callsite = mono_mempool_alloc0 (cfg->mempool, sizeof (GCCallSite)); + GCCallSite *callsite = (GCCallSite *)mono_mempool_alloc0 (cfg->mempool, sizeof (GCCallSite)); int i; LIVENESS_DEBUG (printf ("\t%x: ", ins->backend.pc_offset); mono_print_ins (ins)); LIVENESS_DEBUG (printf ("\t\tlive: ")); callsite->bb = bb; - callsite->liveness = mono_mempool_alloc0 (cfg->mempool, ALIGN_TO (cfg->num_varinfo, 8) / 8); + callsite->liveness = (guint8 *)mono_mempool_alloc0 (cfg->mempool, ALIGN_TO (cfg->num_varinfo, 8) / 8); callsite->pc_offset = ins->backend.pc_offset; for (i = 0; i < cfg->num_varinfo; ++i) { if (last_use [i] != 0) { @@ -1065,7 +1091,7 @@ mono_analyze_liveness_gc (MonoCompile *cfg) } reverse_len = 1024; - reverse = mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * reverse_len); + reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * reverse_len); for (bb = cfg->bb_entry; bb; bb = bb->next_bb) { MonoInst *ins; @@ -1107,7 +1133,7 @@ mono_analyze_liveness_gc (MonoCompile *cfg) for (nins = 0, pos = block_from, ins = bb->code; ins; ins = ins->next, ++nins, ++pos) { if (nins >= reverse_len) { int new_reverse_len = reverse_len * 2; - MonoInst **new_reverse = mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * new_reverse_len); + MonoInst **new_reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * new_reverse_len); memcpy (new_reverse, reverse, sizeof (MonoInst*) * reverse_len); reverse = new_reverse; reverse_len = new_reverse_len;