Author: zoltan
Date: 2006-05-19 16:17:46 -0400 (Fri, 19 May 2006)
New Revision: 60878
Modified:
branches/vargaz/mini-linear-il/mono/mono/mini/ChangeLog
branches/vargaz/mini-linear-il/mono/mono/mini/linear-scan.c
branches/vargaz/mini-linear-il/mono/mono/mini/liveness.c
branches/vargaz/mini-linear-il/mono/mono/mini/mini.c
branches/vargaz/mini-linear-il/mono/mono/mini/mini.h
Log:
2006-05-19 Zoltan Varga <[EMAIL PROTECTED]>
* linear-scan.c (mono_linear_scan2): Avoid negative 'gains'.
* mini.h (MonoJitStats): Add a 'regvars' statistics.
* liveness.c linear-scan.c: Improve debug output.
* mini.c (mono_allocate_stack_slots_full2): Fix some problems with the
original
code, add comments and debug code.
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/ChangeLog
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/ChangeLog 2006-05-19
20:06:23 UTC (rev 60877)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/ChangeLog 2006-05-19
20:17:46 UTC (rev 60878)
@@ -1,5 +1,14 @@
2006-05-19 Zoltan Varga <[EMAIL PROTECTED]>
+ * linear-scan.c (mono_linear_scan2): Avoid negative 'gains'.
+
+ * mini.h (MonoJitStats): Add a 'regvars' statistics.
+
+ * liveness.c linear-scan.c: Improve debug output.
+
+ * mini.c (mono_allocate_stack_slots_full2): Fix some problems with the
original
+ code, add comments and debug code.
+
* mini.c (mono_allocate_stack_slots_full2): A variant of the original
allocate_stack_slots () function using the interval based liveness
information.
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/linear-scan.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/linear-scan.c 2006-05-19
20:06:23 UTC (rev 60877)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/linear-scan.c 2006-05-19
20:17:46 UTC (rev 60878)
@@ -294,7 +294,7 @@
for (l = vars; l; l = l->next) {
vmv = l->data;
- LSCAN_DEBUG (printf ("VAR %d %08x %08x C%d\n", vmv->idx,
vmv->range.first_use.abs_pos,
+ LSCAN_DEBUG (printf ("VAR R%d %08x %08x C%d\n", cfg->varinfo
[vmv->idx]->dreg, vmv->range.first_use.abs_pos,
vmv->range.last_use.abs_pos, vmv->spill_costs));
}
@@ -313,7 +313,7 @@
unhandled = g_list_delete_link (unhandled, unhandled);
- LSCAN_DEBUG (printf ("Processing R%d: ", current->idx));
+ LSCAN_DEBUG (printf ("Processing R%d: ", cfg->varinfo
[current->idx]->dreg));
LSCAN_DEBUG (mono_linterval_print (current->interval));
LSCAN_DEBUG (printf ("\n"));
@@ -332,14 +332,14 @@
if (v->interval->last_range->to < pos) {
active = g_list_delete_link (active, l);
- LSCAN_DEBUG (printf ("Interval R%d has
expired\n", v->idx));
+ LSCAN_DEBUG (printf ("Interval R%d has
expired\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
else if (!mono_linterval_covers (v->interval,
pos)) {
inactive = g_list_append (inactive, v);
active = g_list_delete_link (active, l);
- LSCAN_DEBUG (printf ("Interval R%d
became inactive\n", v->idx));
+ LSCAN_DEBUG (printf ("Interval R%d
became inactive\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
@@ -356,14 +356,14 @@
if (v->interval->last_range->to < pos) {
inactive = g_list_delete_link
(inactive, l);
- LSCAN_DEBUG (printf ("\tInterval R%d
has expired\n", v->idx));
+ LSCAN_DEBUG (printf ("\tInterval R%d
has expired\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
else if (mono_linterval_covers (v->interval,
pos)) {
active = g_list_append (active, v);
inactive = g_list_delete_link
(inactive, l);
- LSCAN_DEBUG (printf ("\tInterval R%d
became active\n", v->idx));
+ LSCAN_DEBUG (printf ("\tInterval R%d
became active\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
@@ -379,7 +379,7 @@
if (v->reg >= 0) {
free_pos [v->reg] = 0;
- LSCAN_DEBUG (printf ("\threg %d is busy\n",
v->reg));
+ LSCAN_DEBUG (printf ("\threg %d is busy (cost
%d)\n", v->reg, v->spill_costs));
}
}
@@ -409,7 +409,7 @@
if (free_pos [reg] >= current->interval->last_range->to) {
/* Register available for whole interval */
current->reg = reg;
- LSCAN_DEBUG (printf ("\tAssigned hreg %d to R%d\n",
reg, current->idx));
+ LSCAN_DEBUG (printf ("\tAssigned hreg %d to R%d\n",
reg, cfg->varinfo [current->idx]->dreg));
active = g_list_append (active, current);
gains [current->reg] += current->spill_costs;
@@ -426,9 +426,13 @@
/* FIXME: Optimize the selection of the interval */
if (active) {
+ GList *min_spill_pos;
#if 0
+ /*
+ * This favors registers with big spill costs,
thus larger liveness ranges,
+ * thus actually leading to worse code size.
+ */
guint32 min_spill_value = G_MAXINT32;
- GList *min_spill_pos;
for (l = active; l != NULL; l = l->next) {
vmv = (MonoMethodVar*)l->data;
@@ -438,20 +442,20 @@
min_spill_value =
vmv->spill_costs;
}
}
+#else
+ /* Spill either the first active or the current
interval */
+ min_spill_pos = active;
+#endif
vmv = (MonoMethodVar*)min_spill_pos->data;
-#endif
-
- /* Spill either the first active or the current
interval */
- vmv = (MonoMethodVar*)active->data;
if (vmv->spill_costs < current->spill_costs) {
// if
(vmv->interval->last_range->to < current->interval->last_range->to) {
gains [vmv->reg] -= vmv->spill_costs;
vmv->reg = -1;
- LSCAN_DEBUG (printf ("\tSpilled R%d\n",
vmv->idx));
- active = g_list_delete_link (active,
active);
+ LSCAN_DEBUG (printf ("\tSpilled R%d\n",
cfg->varinfo [vmv->idx]->dreg));
+ active = g_list_delete_link (active,
min_spill_pos);
}
else
- LSCAN_DEBUG (printf ("\tSpilled
current\n"));
+ LSCAN_DEBUG (printf ("\tSpilled current
(cost %d)\n", current->spill_costs));
}
else
LSCAN_DEBUG (printf ("\tSpilled current\n"));
@@ -459,9 +463,14 @@
}
/* Decrease the gains by the cost of saving+restoring the register */
- for (i = 0; i < n_regs; ++i)
- /* FIXME: This is x86 only */
- gains [i] -= cfg->method->save_lmf ? 1 : 2;
+ for (i = 0; i < n_regs; ++i) {
+ if (gains [i]) {
+ /* FIXME: This is x86 only */
+ gains [i] -= cfg->method->save_lmf ? 1 : 2;
+ if (gains [i] < 0)
+ gains [i] = 0;
+ }
+ }
/* Do the actual register assignment */
n_regvars = 0;
@@ -475,29 +484,22 @@
vmv->reg = GPOINTER_TO_INT (g_list_nth_data (regs,
vmv->reg));
if ((gains [reg_index] > regalloc_cost (cfg, vmv)) &&
(cfg->varinfo [vmv->idx]->opcode != OP_REGVAR)) {
+ if (cfg->verbose_level > 2)
+ printf ("REGVAR R%d G%d C%d %s\n",
cfg->varinfo [vmv->idx]->dreg, gains [reg_index], regalloc_cost (cfg, vmv),
mono_arch_regname (vmv->reg));
cfg->varinfo [vmv->idx]->opcode = OP_REGVAR;
cfg->varinfo [vmv->idx]->dreg = vmv->reg;
n_regvars ++;
- if (cfg->verbose_level > 2)
- printf ("REGVAR %d G%d C%d %s\n",
vmv->idx, gains [reg_index], regalloc_cost (cfg, vmv), mono_arch_regname
(vmv->reg));
}
else {
if (cfg->verbose_level > 2)
- printf ("COSTLY: %s R%d G%d C%d %s\n",
mono_method_full_name (cfg->method, TRUE), vmv->idx, gains [reg_index],
regalloc_cost (cfg, vmv), mono_arch_regname (vmv->reg));
+ printf ("COSTLY: %s R%d G%d C%d %s\n",
mono_method_full_name (cfg->method, TRUE), cfg->varinfo [vmv->idx]->dreg, gains
[reg_index], regalloc_cost (cfg, vmv), mono_arch_regname (vmv->reg));
vmv->reg = -1;
}
}
}
- {
- static int all_n_regvars = 0;
+ mono_jit_stats.regvars += n_regvars;
- all_n_regvars += n_regvars;
-
- if (cfg->verbose_level > 2)
- printf ("ALL REGVARS: %d\n", all_n_regvars);
- }
-
/* Compute used regs */
used_regs = 0;
for (l = vars; l; l = l->next) {
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/liveness.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/liveness.c 2006-05-19
20:06:23 UTC (rev 60877)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/liveness.c 2006-05-19
20:17:46 UTC (rev 60878)
@@ -760,7 +760,7 @@
MonoLiveRange2 *range;
for (range = interval->range; range != NULL; range = range->next)
- printf ("[%d-%d) ", range->from, range->to);
+ printf ("[%x-%x) ", range->from, range->to);
}
/**
@@ -821,7 +821,7 @@
const char *spec = INS_INFO (ins->opcode);
int sreg;
- LIVENESS_DEBUG (printf ("\t%d: ", inst_num); mono_print_ins (ins));
+ LIVENESS_DEBUG (printf ("\t%x: ", inst_num); mono_print_ins (ins));
if (ins->opcode == OP_NOP)
return;
@@ -897,6 +897,8 @@
if (disabled)
return;
+ LIVENESS_DEBUG (printf ("LIVENESS 2 %s\n", mono_method_full_name
(cfg->method, TRUE)));
+
/*
if (strstr (cfg->method->name, "test_") != cfg->method->name)
return;
@@ -999,11 +1001,11 @@
mono_linterval_add_range (cfg, vi->interval, 0, 1);
}
-#if 0
+#if 1
for (idx = 0; idx < max_vars; ++idx) {
MonoMethodVar *vi = MONO_VARINFO (cfg, idx);
- LIVENESS_DEBUG (printf ("LIVENESS R%d: ", idx));
+ LIVENESS_DEBUG (printf ("LIVENESS R%d: ", cfg->varinfo
[idx]->dreg));
LIVENESS_DEBUG (mono_linterval_print (vi->interval));
LIVENESS_DEBUG (printf ("\n"));
}
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/mini.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/mini.c 2006-05-19
20:06:23 UTC (rev 60877)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/mini.c 2006-05-19
20:17:46 UTC (rev 60878)
@@ -7932,8 +7932,14 @@
return 1;
}
+#if 0
+#define LSCAN_DEBUG(a) do { a; } while (0)
+#else
+#define LSCAN_DEBUG(a)
+#endif
+
static gint32*
-mono_allocate_stack_slots_full2 (MonoCompile *m, gboolean backward, guint32
*stack_size, guint32 *stack_align)
+mono_allocate_stack_slots_full2 (MonoCompile *cfg, gboolean backward, guint32
*stack_size, guint32 *stack_align)
{
int i, slot, offset, size;
guint32 align;
@@ -7945,17 +7951,19 @@
MonoType *t;
int nvtypes;
- scalar_stack_slots = mono_mempool_alloc0 (m->mempool, sizeof
(StackSlotInfo) * MONO_TYPE_PINNED);
+ LSCAN_DEBUG (printf ("Allocate Stack Slots 2 for %s:\n",
mono_method_full_name (cfg->method, TRUE)));
+
+ scalar_stack_slots = mono_mempool_alloc0 (cfg->mempool, sizeof
(StackSlotInfo) * MONO_TYPE_PINNED);
vtype_stack_slots = NULL;
nvtypes = 0;
- offsets = mono_mempool_alloc (m->mempool, sizeof (gint32) *
m->num_varinfo);
- for (i = 0; i < m->num_varinfo; ++i)
+ offsets = mono_mempool_alloc (cfg->mempool, sizeof (gint32) *
cfg->num_varinfo);
+ for (i = 0; i < cfg->num_varinfo; ++i)
offsets [i] = -1;
- for (i = m->locals_start; i < m->num_varinfo; i++) {
- inst = m->varinfo [i];
- vmv = MONO_VARINFO (m, i);
+ for (i = cfg->locals_start; i < cfg->num_varinfo; i++) {
+ inst = cfg->varinfo [i];
+ vmv = MONO_VARINFO (cfg, i);
if ((inst->flags & MONO_INST_IS_DEAD) || inst->opcode ==
OP_REGVAR || inst->opcode == OP_REGOFFSET)
continue;
@@ -7971,7 +7979,7 @@
MonoMethodVar *current = unhandled->data;
vmv = current;
- inst = m->varinfo [vmv->idx];
+ inst = cfg->varinfo [vmv->idx];
/* inst->unused indicates native sized value types, this is
used by the
* pinvoke wrappers when they call functions returning
structures */
@@ -7994,7 +8002,7 @@
/* Fall through */
case MONO_TYPE_VALUETYPE:
if (!vtype_stack_slots)
- vtype_stack_slots = mono_mempool_alloc0
(m->mempool, sizeof (StackSlotInfo) * 256);
+ vtype_stack_slots = mono_mempool_alloc0
(cfg->mempool, sizeof (StackSlotInfo) * 256);
for (i = 0; i < nvtypes; ++i)
if (t->data.klass == vtype_stack_slots
[i].vtype)
break;
@@ -8019,16 +8027,16 @@
case MONO_TYPE_I4:
#else
case MONO_TYPE_I8:
-#endif
/* Share non-float stack slots of the same size */
slot_info = &scalar_stack_slots [MONO_TYPE_CLASS];
break;
+#endif
default:
slot_info = &scalar_stack_slots [t->type];
}
slot = 0xffffff;
- if (m->comp_done & MONO_COMP_LIVENESS) {
+ if (cfg->comp_done & MONO_COMP_LIVENESS) {
int pos;
gboolean changed;
@@ -8056,15 +8064,15 @@
if (v->interval->last_range->to < pos) {
slot_info->active =
g_list_delete_link (slot_info->active, l);
- slot_info->slots =
g_slist_prepend_mempool (m->mempool, slot_info->slots, GINT_TO_POINTER (offsets
[v->idx]));
- //LSCAN_DEBUG (printf
("Interval R%d has expired\n", v->idx));
+ slot_info->slots =
g_slist_prepend_mempool (cfg->mempool, slot_info->slots, GINT_TO_POINTER
(offsets [v->idx]));
+ LSCAN_DEBUG (printf ("Interval
R%d has expired, adding 0x%x to slots\n", cfg->varinfo [v->idx]->dreg, offsets
[v->idx]));
changed = TRUE;
break;
}
else if (!mono_linterval_covers
(v->interval, pos)) {
slot_info->inactive =
g_list_append (slot_info->inactive, v);
slot_info->active =
g_list_delete_link (slot_info->active, l);
- //LSCAN_DEBUG (printf
("Interval R%d became inactive\n", v->idx));
+ LSCAN_DEBUG (printf ("Interval
R%d became inactive\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
@@ -8081,15 +8089,16 @@
if (v->interval->last_range->to < pos) {
slot_info->inactive =
g_list_delete_link (slot_info->inactive, l);
- slot_info->slots =
g_slist_prepend_mempool (m->mempool, slot_info->slots, GINT_TO_POINTER (offsets
[v->idx]));
- //LSCAN_DEBUG (printf
("\tInterval R%d has expired\n", v->idx));
+ // FIXME: Enabling this seems
to cause impossible to debug crashes
+ //slot_info->slots =
g_slist_prepend_mempool (cfg->mempool, slot_info->slots, GINT_TO_POINTER
(offsets [v->idx]));
+ LSCAN_DEBUG (printf ("Interval
R%d has expired, adding 0x%x to slots\n", cfg->varinfo [v->idx]->dreg, offsets
[v->idx]));
changed = TRUE;
break;
}
else if (mono_linterval_covers
(v->interval, pos)) {
slot_info->active =
g_list_append (slot_info->active, v);
slot_info->inactive =
g_list_delete_link (slot_info->inactive, l);
- //LSCAN_DEBUG (printf
("\tInterval R%d became active\n", v->idx));
+ LSCAN_DEBUG (printf
("\tInterval R%d became active\n", cfg->varinfo [v->idx]->dreg));
changed = TRUE;
break;
}
@@ -8113,25 +8122,27 @@
/* FIXME: We might want to consider the
inactive intervals as well if slot_info->slots is empty */
- slot_info->active = mono_varlist_insert_sorted
(m, slot_info->active, vmv, TRUE);
+ slot_info->active = mono_varlist_insert_sorted
(cfg, slot_info->active, vmv, TRUE);
}
}
+#if 0
{
static int count = 0;
count ++;
- /*
- if (count == atoi (getenv ("COUNT")))
- printf ("LAST: %s\n", mono_method_full_name
(m->method, TRUE));
- if (count > atoi (getenv ("COUNT")))
+ if (count == atoi (getenv ("COUNT3")))
+ printf ("LAST: %s\n", mono_method_full_name
(cfg->method, TRUE));
+ if (count > atoi (getenv ("COUNT3")))
slot = 0xffffff;
else {
mono_print_tree_nl (inst);
}
- */
}
+#endif
+ LSCAN_DEBUG (printf ("R%d %s -> 0x%x\n", inst->dreg,
mono_type_full_name (t), slot));
+
if (slot == 0xffffff) {
/*
* Allways allocate valuetypes to sizeof (gpointer) to
allow more
@@ -12206,6 +12217,7 @@
g_print ("Allocated code size: %ld\n",
mono_jit_stats.allocated_code_size);
g_print ("Inlineable methods: %ld\n",
mono_jit_stats.inlineable_methods);
g_print ("Inlined methods: %ld\n",
mono_jit_stats.inlined_methods);
+ g_print ("Regvars: %ld\n",
mono_jit_stats.regvars);
g_print ("Locals stack size: %ld\n",
mono_jit_stats.locals_stack_size);
g_print ("\nCreated object count: %ld\n",
mono_stats.new_object_count);
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/mini.h
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/mini.h 2006-05-19
20:06:23 UTC (rev 60877)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/mini.h 2006-05-19
20:17:46 UTC (rev 60878)
@@ -735,6 +735,7 @@
gulong basic_blocks;
gulong max_basic_blocks;
gulong locals_stack_size;
+ gulong regvars;
gulong cas_declsec_check;
gulong cas_linkdemand_icall;
gulong cas_linkdemand_pinvoke;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches