From 504cc6b10a9820e46366808d6097132469a9b28c Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 13 Jan 2017 20:29:05 +0100 Subject: [PATCH] Replace the 'preserved' constraint with a per-register form of 'corrupted'; it's going to work almost exactly the same, but is easier to get my head around and friendlier to the new allocator. --- mach/powerpc/mcg/table | 56 +++++++++++----------- mach/proto/mcg/hop.h | 1 + mach/proto/mcg/pass_instructionselection.c | 6 +-- util/mcgg/gram.y | 7 ++- util/mcgg/iburg.c | 16 +++---- util/mcgg/iburg.h | 2 +- util/mcgg/mcgg.h | 2 +- util/mcgg/scan.l | 1 - 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/mach/powerpc/mcg/table b/mach/powerpc/mcg/table index b72990c36..496101238 100644 --- a/mach/powerpc/mcg/table +++ b/mach/powerpc/mcg/table @@ -10,9 +10,9 @@ REGISTERS * be moved from register to register or spilt). */ - r12 int volatile; - r11 int volatile; - r10 int volatile; + r12 int volatile; + r11 int volatile; + r10 int volatile; r9 int volatile; r8 int volatile; r7 int volatile; @@ -21,21 +21,21 @@ REGISTERS r4 int volatile; r3 int volatile iret; - r31 int; - r30 int; - r29 int; - r28 int; - r27 int; - r26 int; - r25 int; - r24 int; - r23 int; - r22 int; - r21 int; - r20 int; - r19 int; - r18 int; - r17 int; + r31 int; + r30 int; + r29 int; + r28 int; + r27 int; + r26 int; + r25 int; + r24 int; + r23 int; + r22 int; + r21 int; + r20 int; + r19 int; + r18 int; + r17 int; r16 int; r15 int; r14 int; @@ -179,12 +179,12 @@ PATTERNS emit "lfs %out, 0(sp)" emit "addi sp, sp, 4" cost 8; - + out:(double)reg = POP.D emit "lfd %out, 0(sp)" emit "addi sp, sp, 8" cost 8; - + SETRET.I(in:(iret)reg) emit "! setret4" cost 1; @@ -237,7 +237,7 @@ PATTERNS SETSP.I(in:(int)reg) emit "mr sp, %in" cost 4; - + out:(int)reg = ANY.I cost 1; @@ -398,7 +398,7 @@ PATTERNS cost 4; out:(int)reg = FROMSD.I(in:(double)reg) - with preserved(%in) + with corrupted(%in) emit "fctiwz %in, %in" emit "stfdu %in, -8(sp)" emit "lwz %out, 4(sp)" @@ -448,7 +448,7 @@ PATTERNS emit "mr %out.0, %in1" emit "mr %out.1, %in2" cost 8; - + out:(int)reg = FROML0.I(in:(long)reg) emit "mr %out, %in.0" cost 4; @@ -644,14 +644,14 @@ PATTERNS cost 4; out:(int)reg = MOD.I(left:(int)reg, right:(int)reg) - with preserved(%left), preserved(%right) + with corrupted(%left), corrupted(%right) emit "divw %out, %left, %right" emit "mullw %out, %out, %right" emit "subf %out, %out, %left" cost 12; out:(int)reg = MODU.I(left:(int)reg, right:(int)reg) - with preserved(%left), preserved(%right) + with corrupted(%left), corrupted(%right) emit "divwu %out, %left, %right" emit "mullw %out, %out, %right" emit "subf %out, %out, %left" @@ -714,7 +714,7 @@ PATTERNS out:(float)reg = LOAD.F(addr:address) emit "lfs %out, %addr" cost 4; - + out:(double)reg = LOAD.D(addr:address) emit "lfd %out, %addr" cost 4; @@ -741,7 +741,7 @@ PATTERNS out:(type)reg = add(mul(m1:(type)reg, m2:(type)reg), m3:(type)reg) \ emit insn " %out, %m1, %m2, %m3" \ cost 4; \ - + #define FMARIGHT(type, insn, add, mul) \ out:(type)reg = add(m3:(type)reg, mul(m1:(type)reg, m2:(type)reg)) \ emit insn " %out, %m1, %m2, %m3" \ @@ -762,7 +762,7 @@ PATTERNS out:(type)reg = neg(add(mul(m1:(type)reg, m2:(type)reg), m3:(type)reg)) \ emit insn " %out, %m1, %m2, %m3" \ cost 4; \ - + #define FMANEGRIGHT(type, insn, neg, add, mul) \ out:(type)reg = neg(add(m3:(type)reg, mul(m1:(type)reg, m2:(type)reg))) \ emit insn " %out, %m1, %m2, %m3" \ diff --git a/mach/proto/mcg/hop.h b/mach/proto/mcg/hop.h index 6a97d8535..7e4b443e2 100644 --- a/mach/proto/mcg/hop.h +++ b/mach/proto/mcg/hop.h @@ -43,6 +43,7 @@ struct hop ARRAYOF(struct value) inputs; ARRAYOF(struct value) outputs; ARRAYOF(struct value) throughs; + ARRAYOF(struct value) corrupted; struct hashtable* vregmapping; }; diff --git a/mach/proto/mcg/pass_instructionselection.c b/mach/proto/mcg/pass_instructionselection.c index cf959e382..dfb1497c1 100644 --- a/mach/proto/mcg/pass_instructionselection.c +++ b/mach/proto/mcg/pass_instructionselection.c @@ -89,12 +89,12 @@ static void constrain_input_reg(int child, uint32_t attr) value->attrs = attr; } -static void constrain_input_reg_preserved(int child) +static void constrain_input_reg_corrupted(int child) { struct value* value = find_value_of_child(child); struct constraint* c; - array_appendu(¤t_hop->throughs, value); + array_appendu(¤t_hop->corrupted, value); } static uint32_t find_type_from_constraint(uint32_t attr) @@ -148,7 +148,7 @@ static const struct burm_emitter_data emitter_data = &emit_value, &emit_eoi, &constrain_input_reg, - &constrain_input_reg_preserved, + &constrain_input_reg_corrupted, &constrain_output_reg, &constrain_output_reg_equal_to, }; diff --git a/util/mcgg/gram.y b/util/mcgg/gram.y index 2258a2d40..eab714f16 100644 --- a/util/mcgg/gram.y +++ b/util/mcgg/gram.y @@ -39,7 +39,6 @@ extern int yylex(void); %term NOTEQUALS %term PATTERNS %term PREFERS -%term PRESERVED %term REGISTERS %term WHEN %term WITH @@ -67,7 +66,7 @@ extern int yylex(void); %% spec - : REGISTERS registers + : REGISTERS registers DECLARATIONS declarations PATTERNS patterns ; @@ -172,8 +171,8 @@ constraint $$->type = CONSTRAINT_EQUALS; $$->left = $2; $$->right = $5; } | CORRUPTED '(' ID ')' { $$ = calloc(1, sizeof(*$$)); $$->type = CONSTRAINT_CORRUPTED_ATTR; $$->left = $3; } - | PRESERVED '(' '%' ID ')' { $$ = calloc(1, sizeof(*$$)); - $$->type = CONSTRAINT_PRESERVED; $$->left = $4; } + | CORRUPTED '(' '%' ID ')' { $$ = calloc(1, sizeof(*$$)); + $$->type = CONSTRAINT_CORRUPTED_REG; $$->left = $4; } ; qfragments diff --git a/util/mcgg/iburg.c b/util/mcgg/iburg.c index ef31223d4..03498b7c4 100644 --- a/util/mcgg/iburg.c +++ b/util/mcgg/iburg.c @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) exit(1); } } - + emitheader(); registerterminals(); @@ -918,7 +918,7 @@ static bool find_child_index(Tree node, const char* name, int* index, Tree* foun return true; return false; } - + static void emit_predicate_expr(Rule r, struct expr* p) { bool first = true; @@ -1051,16 +1051,16 @@ static void emit_input_constraints(Rule r) int index; struct constraint* c = r->constraints.item[i]; - if (c->type == CONSTRAINT_PRESERVED) + if (c->type == CONSTRAINT_CORRUPTED_REG) { if (strcmp(c->left, r->label) == 0) - yyerror("cannot preserve an output register!"); + yyerror("only input registers can be corrupted!"); index = 0; if (!find_child_index(r->pattern, c->left, &index, NULL)) label_not_found(r, c->left); - print("%1data->constrain_input_reg_preserved(%d);\n", index); + print("%1data->constrain_input_reg_corrupted(%d);\n", index); } } } @@ -1098,10 +1098,10 @@ static void emitinsndata(Rule rules) int index = 0; emit_input_regs(r->pattern, &index); } - + emit_output_constraints(r); emit_input_constraints(r); - + while (f) { char* data = strdup(f->data); @@ -1154,7 +1154,7 @@ static void emitinsndata(Rule rules) assert(f->data[1] == 0); print("%1data->emit_eoi();\n"); break; - + default: print("%1data->emit_string(\"%s\");\n", f->data); } diff --git a/util/mcgg/iburg.h b/util/mcgg/iburg.h index f9ea1efb1..fa26742d0 100644 --- a/util/mcgg/iburg.h +++ b/util/mcgg/iburg.h @@ -22,7 +22,7 @@ enum { CONSTRAINT_EQUALS, CONSTRAINT_CORRUPTED_ATTR, - CONSTRAINT_PRESERVED, + CONSTRAINT_CORRUPTED_REG, }; struct constraint diff --git a/util/mcgg/mcgg.h b/util/mcgg/mcgg.h index e9ed5b45d..9ddf922c8 100644 --- a/util/mcgg/mcgg.h +++ b/util/mcgg/mcgg.h @@ -36,7 +36,7 @@ struct burm_emitter_data void (*emit_value)(int child); void (*emit_eoi)(void); void (*constrain_input_reg)(int child, uint32_t attr); - void (*constrain_input_reg_preserved)(int child); + void (*constrain_input_reg_corrupted)(int child); void (*constrain_output_reg)(uint32_t attr); void (*constrain_output_reg_equal_to)(int child); }; diff --git a/util/mcgg/scan.l b/util/mcgg/scan.l index 447a7d395..272dd2bf1 100644 --- a/util/mcgg/scan.l +++ b/util/mcgg/scan.l @@ -46,7 +46,6 @@ static int braces = 0; "fragment" return FRAGMENT; "named" return NAMED; "prefers" return PREFERS; -"preserved" return PRESERVED; "when" return WHEN; "with" return WITH; "==" return EQUALS; -- 2.34.1