Properly propagate the registers returned by stmt:reg rules.
authorDavid Given <dg@cowlark.com>
Sun, 22 Jan 2017 10:00:38 +0000 (11:00 +0100)
committerDavid Given <dg@cowlark.com>
Sun, 22 Jan 2017 10:00:38 +0000 (11:00 +0100)
mach/proto/mcg/hop.c
mach/proto/mcg/pass_instructionselection.c
util/mcgg/iburg.c
util/mcgg/mcgg_common.h

index a0589f6..a6b57f9 100644 (file)
@@ -280,7 +280,7 @@ static void appendheader(struct hop* hop)
 {
     int i;
 
-    appendf("%d", hop->id);
+    appendf("$%d.%d", hop->value->ir->id, hop->value->subid);
     if (hop->ir)
         appendf(" from $%d", hop->ir->id);
     appendf(":");
index c9d80b2..72f949a 100644 (file)
@@ -206,33 +206,46 @@ static struct insn* walk_instructions(struct burm_node* node, int goal)
 
         if (!insn->insndata->is_fragment)
         {
+            struct value* firstchild = NULL;
             insn->hop = current_hop = new_hop(current_bb, insn->ir);
             current_hop->insndata = insn->insndata;
             emit(insn);
 
+            if (insn->children[0])
+            {
+                if (insn->children[0]->hop)
+                    firstchild = insn->children[0]->hop->value;
+                else
+                    firstchild = &insn->children[0]->ir->value;
+            }
+
             current_hop->value = &insn->value;
-            switch (node->label)
+
+            if (insn_no == INSN_STMT)
+            {
+                tracef('I', "I: label=%d\n", node->label);
+                hop_get_value_usage(current_hop, firstchild)->input = true;
+                hop_get_value_usage(current_hop, current_hop->value)->output = true;
+                hop_add_insel(current_hop, "@copy %V %V", firstchild, current_hop->value);
+            }
+            else
             {
-                case ir_to_esn(IR_REG, 0):
-                    current_hop->value = &node->ir->value;
-                    break;
-
-                case ir_to_esn(IR_NOP, 'I'):
-                case ir_to_esn(IR_NOP, 'F'):
-                case ir_to_esn(IR_NOP, 'L'):
-                case ir_to_esn(IR_NOP, 'D'):
+                switch (node->label)
                 {
-                    struct insn* child = insn->children[0];
-                    struct value* value;
-                    if (child->hop)
-                        value = child->hop->value;
-                    else
-                        value = &child->ir->value;
-
-                    hop_get_value_usage(current_hop, value)->input = true;
-                    hop_get_value_usage(current_hop, current_hop->value)->output = true;
-                    hop_add_insel(current_hop, "@copy %V %V", value, current_hop->value);
-                    break;
+                    case ir_to_esn(IR_REG, 0):
+                        hop_get_value_usage(current_hop, &node->ir->value)->input = true;
+                        hop_get_value_usage(current_hop, current_hop->value)->output = true;
+                        hop_add_insel(current_hop, "@copy %V %V", &node->ir->value, current_hop->value);
+                        break;
+
+                    case ir_to_esn(IR_NOP, 'I'):
+                    case ir_to_esn(IR_NOP, 'F'):
+                    case ir_to_esn(IR_NOP, 'L'):
+                    case ir_to_esn(IR_NOP, 'D'):
+                        hop_get_value_usage(current_hop, firstchild)->input = true;
+                        hop_get_value_usage(current_hop, current_hop->value)->output = true;
+                        hop_add_insel(current_hop, "@copy %V %V", firstchild, current_hop->value);
+                        break;
                 }
             }
 
index 03498b7..4bbb4c3 100644 (file)
@@ -143,10 +143,14 @@ int main(int argc, char* argv[])
                const static struct terminfo NOPL = { "NOP.L", NULL, NULL };
                const static struct terminfo NOPD = { "NOP.D", NULL, NULL };
                const static struct terminfo RET = { "RET", NULL, NULL };
+               Rule r;
 
                nonterm("reg", true);
 
-               rule(NULL, tree(&reg, NULL, NULL))->cost = 1;
+               r = rule(NULL, tree(&reg, NULL, NULL));
+               r->cost = 1;
+               assert(r->ern == INSN_STMT);
+
                rule(&reg, tree(&REG, NULL, NULL))->cost = 1;
                rule(&reg, tree(&NOPI, tree(&reg, NULL, NULL), NULL))->cost = 1;
                rule(&reg, tree(&NOPF, tree(&reg, NULL, NULL), NULL))->cost = 1;
index 09bc86d..b6d9cc8 100644 (file)
@@ -17,5 +17,10 @@ enum
     NONTERM_STMT = 1
 };
 
+enum
+{
+       INSN_STMT = 1
+};
+
 #endif