Skip to content

Commit

Permalink
Non-functioning attempt to make register corruption work with the new…
Browse files Browse the repository at this point in the history
… register

allocator.
  • Loading branch information
davidgiven committed Feb 21, 2024
1 parent 1de1989 commit bd4ae38
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BUILDDIR ?= $(ACK_TEMP_DIR)/ack-build

# What build flags do you want to use for native code?

CFLAGS ?= -g -Wno-return-type
CFLAGS ?= -g -Wno-return-type -O3
LDFLAGS ?=

# Various commands.
Expand Down
2 changes: 1 addition & 1 deletion mach/ez80/mcg/table
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ REGISTERS
dde aliases(de) named("de") double volatile dret;
dbc aliases(bc) named("bc") double volatile;

flags flags;
flags flags volatile;


DECLARATIONS
Expand Down
2 changes: 2 additions & 0 deletions mach/proto/mcg/hop.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ static void print_header(char k, struct hop* hop)
tracef(k, " r%%%d", hop->ins.item[i]->id);
for (i = 0; i < hop->throughs.count; i++)
tracef(k, " =%%%d", hop->throughs.item[i]->id);
for (i = 0; i < hop->corrupts.count; i++)
tracef(k, " !%%%d", hop->corrupts.item[i]->id);
for (i = 0; i < hop->outs.count; i++)
tracef(k, " w%%%d", hop->outs.item[i]->id);
tracef(k, " ");
Expand Down
1 change: 1 addition & 0 deletions mach/proto/mcg/hop.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct hop
ARRAYOF(struct vreg) ins;
ARRAYOF(struct vreg) outs;
ARRAYOF(struct vreg) throughs;
ARRAYOF(struct vreg) corrupts;

bool is_copy;
};
Expand Down
25 changes: 20 additions & 5 deletions mach/proto/mcg/pass_instructionselection.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,27 @@ static void constrain_output_reg_equal_to(int child)
get_constraint(current_hop, vreg)->equals_to = current_hop->output;
}

static void constrain_through_reg_corrupts(regclass_t regclass)
{
struct vreg* vreg = new_vreg();
vreg->defined = current_hop;
vreg->regclass = regclass;

array_appendu(&current_hop->corrupts, vreg);
}

static const struct burm_emitter_data emitter_data = {
&emit_string, &emit_fragment,
&emit_return_reg, &emit_reg,
&emit_value, &emit_eoi,
&connect_input_reg, &constrain_input_reg_preserved,
&connect_output_reg, &constrain_output_reg_equal_to,
&emit_string,
&emit_fragment,
&emit_return_reg,
&emit_reg,
&emit_value,
&emit_eoi,
&connect_input_reg,
&constrain_input_reg_preserved,
&connect_output_reg,
&constrain_output_reg_equal_to,
&constrain_through_reg_corrupts,
};

static void emit(struct insn* insn)
Expand Down
7 changes: 7 additions & 0 deletions mach/proto/mcg/pass_registerallocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ static void construct_interference_graph(void)
int nouts = hop->outs.count;
struct vreg** throughs = hop->throughs.item;
int nthroughs = hop->throughs.count;
struct vreg** corrupts = hop->corrupts.item;
int ncorrupts = hop->corrupts.count;

/* Record all used vregs. */

Expand All @@ -178,6 +180,11 @@ static void construct_interference_graph(void)
mark_vreg_list_interference(ins, nins, throughs, nthroughs);
mark_vreg_list_interference(outs, nouts, throughs, nthroughs);

/* Corrupted registers interfere with throughs, but are still
* available for inputs and outputs. */

mark_vreg_list_interference(corrupts, ncorrupts, throughs, nthroughs);

/* Any preserved input registers interfere with all output
* registers. */

Expand Down
16 changes: 9 additions & 7 deletions tests/plat/core/andv_e.e
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#
mes 2, EM_WSIZE, EM_PSIZE
#define W EM_WSIZE
#define P EM_PSIZE
mes 2, W, P

exp $_m_a_i_n
pro $_m_a_i_n, 0

/* And word-sized set */

four
rom EM_WSIZE
rom W

loc 32769
loc 1
loe four /* to defeat constant folding */
and
loc 1
cmu EM_WSIZE
cmu W
zeq *1

loc __LINE__
Expand All @@ -25,7 +27,7 @@ four
/* And triple-word-sized set */

four_by_three
rom EM_WSIZE*3
rom W*3

loc 32769
loc 32770
Expand All @@ -36,13 +38,13 @@ four_by_three
loe four_by_three
and
loc 4
cmu EM_WSIZE
cmu W
zne *2
loc 2
cmu EM_WSIZE
cmu W
zne *2
loc 1
cmu EM_WSIZE
cmu W
zeq *3
2
loc __LINE__
Expand Down
57 changes: 28 additions & 29 deletions util/mcgg/iburg.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ Rule rule(const struct terminfo* ti, Tree pattern)
if (!r->attr)
yyerror(
"'%s' doesn't seem to be a known register attribute", ti->attr);
if (r->attr->sizebits == -1)
yyerror(
"'%s' has an ambiguous size and can't be used here", ti->attr);
if (r->attr->sizebits == -1)
yyerror(
"'%s' has an ambiguous size and can't be used here", ti->attr);
}

return r;
Expand Down Expand Up @@ -687,11 +687,11 @@ static void emitregisterattrs(void)
assert(rc->number == i);

print("%1{ \"%s\", %d },\n", rc->name, rc->sizebits);
if (rc->number > burm_double_CLASS)
{
printh("#define %P%s_CLASS %d\n", rc->name, rc->number);
printh("#define %P%s_ATTR (1U<<%P%s_CLASS)\n", rc->name, rc->name);
}
if (rc->number > burm_double_CLASS)
{
printh("#define %P%s_CLASS %d\n", rc->name, rc->number);
printh("#define %P%s_ATTR (1U<<%P%s_CLASS)\n", rc->name, rc->name);
}
}
print("};\n\n");

Expand Down Expand Up @@ -1425,6 +1425,25 @@ static void emit_input_constraints(Rule r)
}
}

static void emit_through_constraints(Rule r)
{
int i;

for (i = 0; i < r->constraints.count; i++)
{
struct constraint* c = r->constraints.item[i];

if (c->type == CONSTRAINT_CORRUPTED_ATTR)
{
struct regattr* p = smap_get(&registerattrs, c->left);
if (!p)
yyerror("no such register attribute '%s'", c->left);

print("%1data->constrain_through_regclass_corrupted(%d);\n", p->number);
}
}
}

/* emitinsndata - emit the code generation data */
static void emitinsndata(Rule rules)
{
Expand Down Expand Up @@ -1464,6 +1483,7 @@ static void emitinsndata(Rule rules)

emit_output_constraints(r);
emit_input_constraints(r);
emit_through_constraints(r);

while (f)
{
Expand Down Expand Up @@ -1552,27 +1572,6 @@ static void emitinsndata(Rule rules)

print("%2%s,\n", r->lhs->is_fragment ? "true" : "false");

{
int i;
uint32_t attrs = 0;

for (i = 0; i < r->constraints.count; i++)
{
struct constraint* c = r->constraints.item[i];

if (c->type == CONSTRAINT_CORRUPTED_ATTR)
{
struct regattr* p = smap_get(&registerattrs, c->left);
if (!p)
yyerror("no such register attribute '%s'", c->left);

attrs |= 1 << (p->number);
}
}

print("%2%d, /* corruption attrs */\n", attrs);
}

print("%1},\n");
r = r->link;
}
Expand Down
2 changes: 1 addition & 1 deletion util/mcgg/mcgg.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct burm_emitter_data
void (*constrain_input_reg_preserved)(int child);
void (*connect_output_reg)(regclass_t regclass);
void (*constrain_output_reg_equal_to)(int child);
void (*constrain_through_regclass_corrupted)(regclass_t regclass);
};

typedef void burm_emitter_t(const struct burm_emitter_data* data);
Expand All @@ -62,7 +63,6 @@ struct burm_instruction_data
const char* name;
burm_emitter_t* emitter;
bool is_fragment;
uint32_t corrupts;
};

extern const struct burm_instruction_data burm_instruction_data[];
Expand Down

0 comments on commit bd4ae38

Please sign in to comment.