Author: zoltan
Date: 2006-04-03 09:23:44 -0400 (Mon, 03 Apr 2006)
New Revision: 58948
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini.c
trunk/mono/mono/mini/mini.h
Log:
2006-04-03 Zoltan Varga <[EMAIL PROTECTED]>
* mini.c: Modify the branch optimizations to preserve the invariant that
the entries inside the in_bb and out_bb arrays are unique.
(mono_unlink_bblock): Avoid creation of new arrays.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2006-04-03 13:21:48 UTC (rev 58947)
+++ trunk/mono/mono/mini/ChangeLog 2006-04-03 13:23:44 UTC (rev 58948)
@@ -1,3 +1,9 @@
+2006-04-03 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * mini.c: Modify the branch optimizations to preserve the invariant that
+ the entries inside the in_bb and out_bb arrays are unique.
+ (mono_unlink_bblock): Avoid creation of new arrays.
+
2006-04-02 Zoltan Varga <[EMAIL PROTECTED]>
* mini.c (mono_unlink_bblock): Fix regression caused by previous
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2006-04-03 13:21:48 UTC (rev 58947)
+++ trunk/mono/mono/mini/mini.c 2006-04-03 13:23:44 UTC (rev 58948)
@@ -781,45 +781,41 @@
void
mono_unlink_bblock (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to)
{
- MonoBasicBlock **newa;
- int i, pos, count;
+ int i, pos;
gboolean found;
- /*
- * In theory, count could only have the value 0 or 1, but some branch
opts
- * are still buggy, causing the same bblock to appear in in/out_bb
multiple
- * times (bug #77992)
- */
- count = 0;
+ found = FALSE;
for (i = 0; i < from->out_count; ++i) {
- if (to == from->out_bb [i])
- count ++;
+ if (to == from->out_bb [i]) {
+ found = TRUE;
+ break;
+ }
}
- if (count) {
- newa = mono_mempool_alloc (cfg->mempool, sizeof (gpointer) *
(from->out_count - count));
+ if (found) {
pos = 0;
for (i = 0; i < from->out_count; ++i) {
if (from->out_bb [i] != to)
- newa [pos ++] = from->out_bb [i];
+ from->out_bb [pos ++] = from->out_bb [i];
}
- from->out_count -= count;
- from->out_bb = newa;
+ g_assert (pos == from->out_count - 1);
+ from->out_count--;
}
- count = 0;
+ found = FALSE;
for (i = 0; i < to->in_count; ++i) {
- if (from == to->in_bb [i])
- count ++;
+ if (from == to->in_bb [i]) {
+ found = TRUE;
+ break;
+ }
}
if (found) {
- newa = mono_mempool_alloc (cfg->mempool, sizeof (gpointer) *
(to->in_count - count));
pos = 0;
for (i = 0; i < to->in_count; ++i) {
if (to->in_bb [i] != from)
- newa [pos ++] = to->in_bb [i];
+ to->in_bb [pos ++] = to->in_bb [i];
}
- to->in_count -= count;
- to->in_bb = newa;
+ g_assert (pos == to->in_count - 1);
+ to->in_count--;
}
}
@@ -8497,39 +8493,6 @@
}
}
-static void
-replace_or_add_in_block (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock
*orig, MonoBasicBlock *repl)
-{
- gboolean found = FALSE;
- int i;
-
- for (i = 0; i < bb->in_count; i++) {
- MonoBasicBlock *ib = bb->in_bb [i];
- if (ib == orig) {
- if (!repl) {
- if (bb->in_count > 1) {
- bb->in_bb [i] = bb->in_bb [bb->in_count
- 1];
- }
- bb->in_count--;
- } else {
- bb->in_bb [i] = repl;
- }
- found = TRUE;
- }
- }
-
- if (! found) {
- MonoBasicBlock **new_in_bb = mono_mempool_alloc (cfg->mempool,
sizeof (MonoBasicBlock*) * (bb->in_count + 1));
- for (i = 0; i < bb->in_count; i++) {
- new_in_bb [i] = bb->in_bb [i];
- }
- new_in_bb [i] = repl;
- bb->in_count++;
- bb->in_bb = new_in_bb;
- }
-}
-
-
static void
replace_out_block_in_code (MonoBasicBlock *bb, MonoBasicBlock *orig,
MonoBasicBlock *repl) {
MonoInst *inst;
@@ -8655,17 +8618,14 @@
printf ("remove_block_if_useless %s, removed BB%d\n",
mono_method_full_name (cfg->method, TRUE), bb->block_num);
}
- for (i = 0; i < bb->in_count; i++) {
- MonoBasicBlock *in_bb = bb->in_bb [i];
- replace_out_block (in_bb, bb, target_bb);
+ /* unlink_bblock () modifies the bb->in_bb array so can't use a
for loop here */
+ while (bb->in_count) {
+ MonoBasicBlock *in_bb = bb->in_bb [0];
+ mono_unlink_bblock (cfg, in_bb, bb);
+ link_bblock (cfg, in_bb, target_bb);
replace_out_block_in_code (in_bb, bb, target_bb);
- if (bb->in_count == 1) {
- replace_in_block (target_bb, bb, in_bb);
- } else {
- replace_or_add_in_block (cfg, target_bb, bb,
in_bb);
- }
}
-
+
mono_unlink_bblock (cfg, bb, target_bb);
if ((previous_bb != cfg->bb_entry) &&
@@ -8996,8 +8956,7 @@
*/
bb->last_ins->opcode = CEE_BR;
bb->last_ins->inst_target_bb =
taken_branch_target;
- replace_out_block (bb,
untaken_branch_target, NULL);
- replace_in_block
(untaken_branch_target, bb, NULL);
+ mono_unlink_bblock (cfg, bb,
untaken_branch_target);
changed = TRUE;
continue;
}
Modified: trunk/mono/mono/mini/mini.h
===================================================================
--- trunk/mono/mono/mini/mini.h 2006-04-03 13:21:48 UTC (rev 58947)
+++ trunk/mono/mono/mini/mini.h 2006-04-03 13:23:44 UTC (rev 58948)
@@ -169,6 +169,7 @@
gint32 dfn;
/* Basic blocks: incoming and outgoing counts and pointers */
+ /* Each bb should only appear once in each array */
gint16 out_count, in_count;
MonoBasicBlock **in_bb;
MonoBasicBlock **out_bb;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches