From: David Given Date: Sun, 22 Jan 2017 10:00:38 +0000 (+0100) Subject: Properly propagate the registers returned by stmt:reg rules. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4e020a9c765b4a3dc3f57b2b60273acb694187e9;p=ack.git Properly propagate the registers returned by stmt:reg rules. --- diff --git a/mach/proto/mcg/hop.c b/mach/proto/mcg/hop.c index a0589f65d..a6b57f9c6 100644 --- a/mach/proto/mcg/hop.c +++ b/mach/proto/mcg/hop.c @@ -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(":"); diff --git a/mach/proto/mcg/pass_instructionselection.c b/mach/proto/mcg/pass_instructionselection.c index c9d80b2b0..72f949a08 100644 --- a/mach/proto/mcg/pass_instructionselection.c +++ b/mach/proto/mcg/pass_instructionselection.c @@ -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; } } diff --git a/util/mcgg/iburg.c b/util/mcgg/iburg.c index 03498b7c4..4bbb4c376 100644 --- a/util/mcgg/iburg.c +++ b/util/mcgg/iburg.c @@ -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(®, NULL, NULL))->cost = 1; + r = rule(NULL, tree(®, NULL, NULL)); + r->cost = 1; + assert(r->ern == INSN_STMT); + rule(®, tree(®, NULL, NULL))->cost = 1; rule(®, tree(&NOPI, tree(®, NULL, NULL), NULL))->cost = 1; rule(®, tree(&NOPF, tree(®, NULL, NULL), NULL))->cost = 1; diff --git a/util/mcgg/mcgg_common.h b/util/mcgg/mcgg_common.h index 09bc86d83..b6d9cc82b 100644 --- a/util/mcgg/mcgg_common.h +++ b/util/mcgg/mcgg_common.h @@ -17,5 +17,10 @@ enum NONTERM_STMT = 1 }; +enum +{ + INSN_STMT = 1 +}; + #endif