Replace the 'preserved' constraint with a per-register form of 'corrupted';
authorDavid Given <dg@cowlark.com>
Fri, 13 Jan 2017 19:29:05 +0000 (20:29 +0100)
committerDavid Given <dg@cowlark.com>
Fri, 13 Jan 2017 19:29:05 +0000 (20:29 +0100)
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
mach/proto/mcg/hop.h
mach/proto/mcg/pass_instructionselection.c
util/mcgg/gram.y
util/mcgg/iburg.c
util/mcgg/iburg.h
util/mcgg/mcgg.h
util/mcgg/scan.l

index b72990c..4961012 100644 (file)
@@ -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"                                        \
index 6a97d85..7e4b443 100644 (file)
@@ -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;
 };
index cf959e3..dfb1497 100644 (file)
@@ -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(&current_hop->throughs, value);
+    array_appendu(&current_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,
 };
index 2258a2d..eab714f 100644 (file)
@@ -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
index ef31223..03498b7 100644 (file)
@@ -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);
                        }
index f9ea1ef..fa26742 100644 (file)
@@ -22,7 +22,7 @@ enum
 {
        CONSTRAINT_EQUALS,
        CONSTRAINT_CORRUPTED_ATTR,
-       CONSTRAINT_PRESERVED,
+       CONSTRAINT_CORRUPTED_REG,
 };
 
 struct constraint
index e9ed5b4..9ddf922 100644 (file)
@@ -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);
 };
index 447a7d3..272dd2b 100644 (file)
@@ -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;