From: David Given Date: Mon, 23 Jan 2017 21:46:45 +0000 (+0100) Subject: Remove the pseudo stuff in favour of modified is_move instructions to represent X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c21beb974091b5e9bacb08aaece21a0cba5de90d;p=ack.git Remove the pseudo stuff in favour of modified is_move instructions to represent copies: it's all still the same logic with the conversion pass, but is now much simpler. --- diff --git a/mach/proto/mcg/hop.c b/mach/proto/mcg/hop.c index 67ebfa09c..b2e0b26c4 100644 --- a/mach/proto/mcg/hop.c +++ b/mach/proto/mcg/hop.c @@ -46,6 +46,16 @@ struct valueusage* hop_get_value_usage(struct hop* hop, struct value* value) return usage; } +void hop_add_move(struct hop* hop, struct value* src, struct value* dest) +{ + struct valueusage* usage; + + assert(hop->insels.count == 0); + hop_get_value_usage(hop, src)->input = true; + hop_get_value_usage(hop, dest)->output = true; + hop->is_move = true; +} + static struct insel* new_insel(enum insel_type type) { struct insel* insel = heap_alloc(&proc_heap, 1, sizeof(*insel)); @@ -55,21 +65,9 @@ static struct insel* new_insel(enum insel_type type) void hop_add_string_insel(struct hop* hop, const char* string) { - if ((hop->insels.count == 0) && (string[0] == '@')) - { - char* pseudo = strdup(string+1); - char* end = strchr(pseudo, ' '); - if (end) - *end = '\0'; - - hop->pseudo = pseudo; - } - else if (!hop->pseudo) - { - struct insel* insel = new_insel(INSEL_STRING); - insel->u.string = string; - array_append(&hop->insels, insel); - } + struct insel* insel = new_insel(INSEL_STRING); + insel->u.string = string; + array_append(&hop->insels, insel); } void hop_add_hreg_insel(struct hop* hop, struct hreg* hreg, int index) @@ -338,26 +336,17 @@ char* hop_render(struct hop* hop) while (hashtable_next(hop->valueusage, &hit)) { struct valueusage* usage = hit.value; - if (usage->input && usage->output) - { - struct vreg* left = actual(usage->invreg); - struct vreg* right = actual(usage->outvreg); - if (left != right) - { - appendf(" "); - appendvreg(usage->invreg); - appendf("->"); - appendvreg(usage->outvreg); - } - } + appendf(" "); + if (usage->input && usage->invreg) + appendvreg(actual(usage->invreg)); + appendf("->"); + if (usage->output && usage->outvreg) + appendvreg(actual(usage->outvreg)); } appendf("\n"); return buffer; } - if (hop->pseudo) - appendf("@%s ", hop->pseudo); - for (i=0; iinsels.count; i++) { struct insel* insel = hop->insels.item[i]; @@ -435,9 +424,6 @@ char* hop_render(struct hop* hop) default: assert(false); } - - if (hop->pseudo) - appendf(" "); } return buffer; diff --git a/mach/proto/mcg/hop.h b/mach/proto/mcg/hop.h index 063fe91c6..cff607165 100644 --- a/mach/proto/mcg/hop.h +++ b/mach/proto/mcg/hop.h @@ -47,7 +47,6 @@ struct hop ARRAYOF(struct insel) insels; struct value* value; bool is_move; - const char* pseudo; PMAPOF(struct value, struct value) equals_constraint; struct hashtable* valueusage; @@ -57,6 +56,7 @@ extern struct hop* new_hop(struct basicblock* bb, struct ir* ir); extern struct hop* new_move_hop(struct basicblock* bb); extern struct valueusage* hop_get_value_usage(struct hop* hop, struct value* value); +extern void hop_add_move(struct hop* hop, struct value* src, struct value* dest); extern void hop_add_string_insel(struct hop* hop, const char* string); extern void hop_add_hreg_insel(struct hop* hop, struct hreg* hreg, int index); diff --git a/mach/proto/mcg/pass_copiestomoves.c b/mach/proto/mcg/pass_copiestomoves.c index f13b42b2c..177821987 100644 --- a/mach/proto/mcg/pass_copiestomoves.c +++ b/mach/proto/mcg/pass_copiestomoves.c @@ -10,7 +10,7 @@ void pass_convert_copies_to_moves(void) for (j=0; jhops.count; j++) { struct hop* hop = bb->hops.item[j]; - if (hop->pseudo && (strcmp(hop->pseudo, "copy") == 0)) + if (hop->is_move) { struct valueusage* usage; struct hashtable_iterator hit = {}; @@ -19,25 +19,25 @@ void pass_convert_copies_to_moves(void) while (hashtable_next(hop->valueusage, &hit)) { usage = hit.value; - if (usage->input) + if (usage->input && !usage->output) { assert(!invreg); invreg = usage->invreg; } - if (usage->output) + if (!usage->input && usage->output) { assert(!outvreg); outvreg = usage->outvreg; } } - assert(invreg && outvreg); - usage = hop_get_value_usage(hop, outvreg->value); - assert(!usage->invreg); - assert(!usage->input); - usage->input = true; - usage->invreg = invreg; - hop->is_move = true; + if (invreg && outvreg) + { + usage = hop_get_value_usage(hop, outvreg->value); + assert(!usage->input); + usage->input = true; + usage->invreg = invreg; + } } } } diff --git a/mach/proto/mcg/pass_instructionselection.c b/mach/proto/mcg/pass_instructionselection.c index 72f949a08..eac6ae926 100644 --- a/mach/proto/mcg/pass_instructionselection.c +++ b/mach/proto/mcg/pass_instructionselection.c @@ -222,29 +222,20 @@ static struct insn* walk_instructions(struct burm_node* node, int goal) current_hop->value = &insn->value; 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); - } + hop_add_move(current_hop, firstchild, current_hop->value); else { switch (node->label) { 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); + hop_add_move(current_hop, &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); + hop_add_move(current_hop, firstchild, current_hop->value); break; } }