void hop_add_string_insel(struct hop* hop, const char* string)
{
- struct insel* insel = new_insel(INSEL_STRING);
- insel->u.string = string;
- array_append(&hop->insels, insel);
+ 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);
+ }
}
void hop_add_hreg_insel(struct hop* hop, struct hreg* hreg, int index)
while (hashtable_next(hop->valueusage, &hit))
{
struct valueusage* usage = hit.value;
- struct vreg* left = actual(usage->invreg);
- struct vreg* right = actual(usage->outvreg);
- if (left != right)
+ if (usage->input && usage->output)
{
- appendf(" ");
- appendvreg(usage->invreg);
- appendf("->");
- appendvreg(usage->outvreg);
+ struct vreg* left = actual(usage->invreg);
+ struct vreg* right = actual(usage->outvreg);
+ if (left != right)
+ {
+ appendf(" ");
+ appendvreg(usage->invreg);
+ appendf("->");
+ appendvreg(usage->outvreg);
+ }
}
}
appendf("\n");
+ return buffer;
}
if (hop->pseudo)
- appendf("@");
+ appendf("@%s ", hop->pseudo);
for (i=0; i<hop->insels.count; i++)
{
extern void pass_assign_vregs(void);
extern void pass_calculate_vreg_spillibility(void);
+extern void pass_convert_copies_to_moves(void);
extern void pass_convert_inputs_to_phis(void);
extern void pass_convert_locals_to_ssa(void);
extern void pass_convert_nonlocal_phis(void);
--- /dev/null
+#include "mcg.h"
+
+void pass_convert_copies_to_moves(void)
+{
+ int i, j;
+
+ for (i=0; i<cfg.preorder.count; i++)
+ {
+ struct basicblock* bb = cfg.preorder.item[i];
+ for (j=0; j<bb->hops.count; j++)
+ {
+ struct hop* hop = bb->hops.item[j];
+ if (hop->pseudo && (strcmp(hop->pseudo, "copy") == 0))
+ {
+ struct valueusage* usage;
+ struct hashtable_iterator hit = {};
+ struct vreg* invreg = NULL;
+ struct vreg* outvreg = NULL;
+ while (hashtable_next(hop->valueusage, &hit))
+ {
+ usage = hit.value;
+ if (usage->input)
+ {
+ assert(!invreg);
+ invreg = usage->invreg;
+ }
+ if (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;
+ }
+ }
+ }
+}
+
+/* vim: set sw=4 ts=4 expandtab : */