#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'.
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);
}
* 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 */
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) {
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);
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)
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 ++;
* 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;
//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;
/*
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;
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) {
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 */
}
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);
}
}
}
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)));
/*
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));
}
/*
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));
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;
/* 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) {
}
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;
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;