dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] libjit ./ChangeLog tools/gen-rules-parser.y


From: Aleksey Demakov
Subject: [dotgnu-pnet-commits] libjit ./ChangeLog tools/gen-rules-parser.y
Date: Sat, 08 Apr 2006 07:02:58 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    libjit
Branch:         
Changes by:     Aleksey Demakov <address@hidden>        06/04/08 07:02:57

Modified files:
        .              : ChangeLog 
        tools          : gen-rules-parser.y 

Log message:
        Extended selection rules syntax.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/libjit/ChangeLog.diff?tr1=1.212&tr2=1.213&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/libjit/tools/gen-rules-parser.y.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: libjit/ChangeLog
diff -u libjit/ChangeLog:1.212 libjit/ChangeLog:1.213
--- libjit/ChangeLog:1.212      Thu Apr  6 23:42:31 2006
+++ libjit/ChangeLog    Sat Apr  8 07:02:57 2006
@@ -1,3 +1,8 @@
+2006-04-08  Aleksey Demakov  <address@hidden>
+
+       * tools/gen-rules-parser.y: extend pattern syntax to allow mark
+         registers as clobbered. Fix bugs.
+
 2006-04-07  Klaus Treichel  <address@hidden>
 
        * jit/jit-internal.h (struct _jit_function): add indirector field.
Index: libjit/tools/gen-rules-parser.y
diff -u libjit/tools/gen-rules-parser.y:1.2 libjit/tools/gen-rules-parser.y:1.3
--- libjit/tools/gen-rules-parser.y:1.2 Mon Apr  3 05:10:35 2006
+++ libjit/tools/gen-rules-parser.y     Sat Apr  8 07:02:57 2006
@@ -142,6 +142,12 @@
 #define        GENSEL_PATT_SPACE                       14
 
 /*
+ * Register flags.
+ */
+#define GENSEL_FLAG_CLOBBER                    1
+#define GENSEL_FLAG_EARLY_CLOBBER              2
+
+/*
  * Option value.
  */
 typedef struct gensel_value *gensel_value_t;
@@ -158,6 +164,7 @@
 struct gensel_option
 {
        int                     option;
+       int                     flags;
        gensel_value_t          values;
        gensel_option_t         next;
 };
@@ -184,12 +191,15 @@
 static char *gensel_imm_names[] = {
        "imm_value", "imm_value2", "imm_value3"
 };
+static char *gensel_reg_flags[] = {
+       "0", "_JIT_REGS_CLOBBER", "_JIT_REGS_EARLY_CLOBBER"
+};
 
 /*
  * Create an option.
  */
 static gensel_option_t
-gensel_create_option(int option, gensel_value_t values)
+gensel_create_option_2(int option, int flags, gensel_value_t values)
 {
        gensel_option_t op;
 
@@ -200,12 +210,22 @@
        }
 
        op->option = option;
+       op->flags = flags;
        op->values = values;
        op->next = 0;
        return op;
 }
 
 /*
+ * Create an option.
+ */
+static gensel_option_t
+gensel_create_option(int option, gensel_value_t values)
+{
+       return gensel_create_option_2(option, 0, values);
+}
+
+/*
  * Free a list of values.
  */
 static void
@@ -624,6 +644,27 @@
        }
 }
 
+static int
+clause_contains_registers(gensel_clause_t clause)
+{
+       gensel_option_t pattern;
+       pattern = clause->pattern;
+       while(pattern)
+       {
+               switch(pattern->option)
+               {
+               case GENSEL_PATT_REG:
+               case GENSEL_PATT_FREG:
+               case GENSEL_PATT_LREG:
+               case GENSEL_PATT_SCRATCH:
+               case GENSEL_PATT_CLOBBER:
+                       return 1;
+               }
+               pattern = pattern->next;
+       }
+       return 0;
+}
+
 /*
  * Output the clauses for a rule.
  */
@@ -636,6 +677,7 @@
        int first, seen_option;
        int regs, imms, index;
        int scratch, clobber_all;
+       int contains_registers;
 
        /* If the clause is manual, then output it as-is */
        if(gensel_search_option(options, GENSEL_OPT_MANUAL))
@@ -648,8 +690,23 @@
                return;
        }
 
+       clause = clauses;
+       contains_registers = 0;
+       while(clause)
+       {
+               contains_registers = clause_contains_registers(clause);
+               if(contains_registers)
+               {
+                       break;
+               }
+               clause = clause->next;
+       }
+
        printf("\t%s inst;\n", gensel_inst_type);
-       printf("\t_jit_regs_t regs;\n");
+       if(contains_registers)
+       {
+               printf("\t_jit_regs_t regs;\n");
+       }
        gensel_declare_regs(clauses, options);
        if(gensel_search_option(options, GENSEL_OPT_SPILL_BEFORE))
        {
@@ -673,7 +730,7 @@
        /* Output the clause checking and dispatching code */
        clause = clauses;
        first = 1;
-       while(clause != 0)
+       while(clause)
        {
                if(clause->next)
                {
@@ -692,89 +749,102 @@
                                case GENSEL_PATT_REG:
                                case GENSEL_PATT_LREG:
                                case GENSEL_PATT_FREG:
-                                       if(index > 0 || seen_option)
+                                       /* Do not check if the value is in
+                                          a register as the allocator will
+                                          load them anyway as long as other
+                                          conditions are met. */
+#if 0
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->in_register", 
args[index]);
+#endif
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMM:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_constant", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMMZERO:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_nint_constant && 
", args[index]);
                                        printf("insn->%s->address == 0", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMMS8:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_nint_constant && 
", args[index]);
                                        printf("insn->%s->address >= -128 && ", 
args[index]);
                                        printf("insn->%s->address <= 127", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMMU8:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_nint_constant && 
", args[index]);
                                        printf("insn->%s->address >= 0 && ", 
args[index]);
                                        printf("insn->%s->address <= 255", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMMS16:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_nint_constant && 
", args[index]);
                                        printf("insn->%s->address >= -32768 && 
", args[index]);
                                        printf("insn->%s->address <= 32767", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IMMU16:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->is_nint_constant && 
", args[index]);
                                        printf("insn->%s->address >= 0 && ", 
args[index]);
                                        printf("insn->%s->address <= 65535", 
args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_LOCAL:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
                                        printf("insn->%s->in_frame && 
!(insn->%s->in_register)",
                                               args[index], args[index]);
+                                       seen_option = 1;
                                        ++index;
                                        break;
 
                                case GENSEL_PATT_IF:
-                                       if(index > 0 || seen_option)
+                                       if(seen_option)
                                        {
                                                printf(" && ");
                                        }
@@ -786,6 +856,10 @@
                                }
                                pattern = pattern->next;
                        }
+                       if(!seen_option)
+                       {
+                               printf("1");
+                       }
                        printf(")\n\t{\n");
                }
                else if(first)
@@ -824,111 +898,130 @@
                        }
                }
 
-               seen_option = 0;
-               printf("\t\t_jit_regs_init(&regs, ");
-               if(clobber_all)
-               {
-                       seen_option = 1;
-                       printf("_JIT_REGS_CLOBBER_ALL");
-               }
-               if(gensel_search_option(options, GENSEL_OPT_TERNARY))
-               {
-                       if(seen_option)
-                       {
-                               printf(" | ");
-                       }
-                       else
-                       {
-                               seen_option = 1;
-                       }
-                       printf("_JIT_REGS_TERNARY");
-               }
+               contains_registers = clause_contains_registers(clause);
+
                if(gensel_search_option(options, GENSEL_OPT_BINARY_BRANCH)
                   || gensel_search_option(options, GENSEL_OPT_UNARY_BRANCH))
                {
-                       if(seen_option)
+                       /* Spill all other registers back to their original 
positions */
+                       if(contains_registers)
                        {
-                               printf(" | ");
+                               clobber_all = 1;
                        }
                        else
                        {
-                               seen_option = 1;
+                               printf("\t\t_jit_regs_spill_all(gen);\n");
                        }
-                       printf("_JIT_REGS_BRANCH");
                }
-               if(gensel_search_option(options, GENSEL_OPT_COPY))
+
+               if(contains_registers)
                {
-                       if(seen_option)
-                       {
-                               printf(" | ");
-                       }
-                       else
+                       seen_option = 0;
+                       printf("\t\t_jit_regs_init(&regs, ");
+                       if(clobber_all)
                        {
                                seen_option = 1;
+                               printf("_JIT_REGS_CLOBBER_ALL");
                        }
-                       printf("_JIT_REGS_COPY");
-               }
-               if(gensel_search_option(options, GENSEL_OPT_STACK))
-               {
-                       if(seen_option)
+                       if(gensel_search_option(options, GENSEL_OPT_TERNARY))
                        {
-                               printf(" | ");
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_TERNARY");
                        }
-                       else
+                       if(gensel_search_option(options, 
GENSEL_OPT_BINARY_BRANCH)
+                          || gensel_search_option(options, 
GENSEL_OPT_UNARY_BRANCH))
                        {
-                               seen_option = 1;
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_BRANCH");
                        }
-                       printf("_JIT_REGS_STACK");
-               }
-               if(gensel_search_option(options, GENSEL_OPT_X87ARITH))
-               {
-                       if(seen_option)
+                       if(gensel_search_option(options, GENSEL_OPT_COPY))
                        {
-                               printf(" | ");
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_COPY");
                        }
-                       else
+                       if(gensel_search_option(options, GENSEL_OPT_STACK))
                        {
-                               seen_option = 1;
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_STACK");
                        }
-                       printf("_JIT_REGS_X87_ARITH");
-               }
-               if(gensel_search_option(options, GENSEL_OPT_COMMUTATIVE))
-               {
-                       if(seen_option)
+                       if(gensel_search_option(options, GENSEL_OPT_X87ARITH))
                        {
-                               printf(" | ");
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_X87_ARITH");
                        }
-                       else
+                       if(gensel_search_option(options, 
GENSEL_OPT_COMMUTATIVE))
                        {
-                               seen_option = 1;
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_COMMUTATIVE");
                        }
-                       printf("_JIT_REGS_COMMUTATIVE");
-               }
-               if(gensel_search_option(options, GENSEL_OPT_REVERSIBLE))
-               {
-                       if(seen_option)
+                       if(gensel_search_option(options, GENSEL_OPT_REVERSIBLE))
                        {
-                               printf(" | ");
+                               if(seen_option)
+                               {
+                                       printf(" | ");
+                               }
+                               else
+                               {
+                                       seen_option = 1;
+                               }
+                               printf("_JIT_REGS_REVERSIBLE");
                        }
-                       else
+                       if(!seen_option)
                        {
-                               seen_option = 1;
+                               printf("0");
                        }
-                       printf("_JIT_REGS_REVERSIBLE");
-               }
-               if(!seen_option)
-               {
-                       printf("0");
-               }
-               printf(");\n");
+                       printf(");\n");
 
-               if(!(gensel_search_option(options, GENSEL_OPT_TERNARY)
-                    || gensel_search_option(options, GENSEL_OPT_BINARY_NOTE)
-                    || gensel_search_option(options, GENSEL_OPT_BINARY_BRANCH)
-                    || gensel_search_option(options, GENSEL_OPT_UNARY_NOTE)
-                    || gensel_search_option(options, GENSEL_OPT_UNARY_BRANCH)))
-               {
-                       printf("\t\t_jit_regs_set_dest(&regs, insn, 0, -1, 
-1);\n");
+                       if(!(gensel_search_option(options, GENSEL_OPT_TERNARY)
+                            || gensel_search_option(options, 
GENSEL_OPT_BINARY_NOTE)
+                            || gensel_search_option(options, 
GENSEL_OPT_BINARY_BRANCH)
+                            || gensel_search_option(options, 
GENSEL_OPT_UNARY_NOTE)
+                            || gensel_search_option(options, 
GENSEL_OPT_UNARY_BRANCH)))
+                       {
+                               printf("\t\t_jit_regs_set_dest(&regs, insn, 0, 
-1, -1);\n");
+                       }
                }
 
                regs = 0;
@@ -942,16 +1035,19 @@
                        case GENSEL_PATT_FREG:
                                if(pattern->values && pattern->values->value)
                                {
-                                       printf("\t\t%s = 
_jit_regs_lookup(\"%s\")];\n",
+                                       printf("\t\t%s = 
_jit_regs_lookup(\"%s\");\n",
                                               gensel_reg_names[regs],
                                               pattern->values->value);
-                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, 0, %s, -1);\n",
-                                              args[index], 
gensel_reg_names[regs]);
+                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, %s, %s, -1);\n",
+                                              args[index],
+                                              gensel_reg_flags[pattern->flags],
+                                              gensel_reg_names[regs]);
                                }
                                else
                                {
-                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, 0, -1, -1);\n",
-                                              args[index]);
+                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, %s, -1, -1);\n",
+                                              args[index],
+                                              
gensel_reg_flags[pattern->flags]);
                                }
                                ++regs;
                                ++index;
@@ -969,8 +1065,9 @@
                                                printf("\t\t%s = 
_jit_regs_lookup(\"%s\")];\n",
                                                       
gensel_other_reg_names[regs],
                                                       
pattern->values->next->value);
-                                               
printf("\t\t_jit_regs_set_%s(&regs, insn, 0, %s, %s);\n",
+                                               
printf("\t\t_jit_regs_set_%s(&regs, insn, %s, %s, %s);\n",
                                                       args[index],
+                                                      
gensel_reg_flags[pattern->flags],
                                                       gensel_reg_names[regs],
                                                       
gensel_other_reg_names[regs]);
                                        }
@@ -979,14 +1076,17 @@
                                                printf("\t\t%s = 
_jit_regs_lookup(\"%s\")];\n",
                                                       gensel_reg_names[regs],
                                                       pattern->values->value);
-                                               
printf("\t\t_jit_regs_set_%s(&regs, insn, 0, %s, -1);\n",
-                                                      args[index], 
gensel_reg_names[regs]);
+                                               
printf("\t\t_jit_regs_set_%s(&regs, insn, %s, %s, -1);\n",
+                                                      args[index],
+                                                      
gensel_reg_flags[pattern->flags],
+                                                      gensel_reg_names[regs]);
                                        }
                                }
                                else
                                {
-                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, 0, -1, -1);\n",
-                                              args[index]);
+                                       printf("\t\t_jit_regs_set_%s(&regs, 
insn, %s, -1, -1);\n",
+                                              args[index],
+                                              
gensel_reg_flags[pattern->flags]);
                                }
                                ++regs;
                                ++index;
@@ -1040,14 +1140,17 @@
                        pattern = pattern->next;
                }
 
-               printf("\t\tif(!_jit_regs_assign(gen, &regs))\n");
-               printf("\t\t{\n");
-               printf("\t\t\treturn;\n");
-               printf("\t\t}\n");
-               printf("\t\tif(!_jit_regs_gen(gen, &regs))\n");
-               printf("\t\t{\n");
-               printf("\t\t\treturn;\n");
-               printf("\t\t}\n");
+               if(contains_registers)
+               {
+                       printf("\t\tif(!_jit_regs_assign(gen, &regs))\n");
+                       printf("\t\t{\n");
+                       printf("\t\t\treturn;\n");
+                       printf("\t\t}\n");
+                       printf("\t\tif(!_jit_regs_gen(gen, &regs))\n");
+                       printf("\t\t{\n");
+                       printf("\t\t\treturn;\n");
+                       printf("\t\t}\n");
+               }
 
                regs = 0;
                imms = 0;
@@ -1112,16 +1215,12 @@
                        pattern = pattern->next;
                }
 
-               if(gensel_search_option(options, GENSEL_OPT_BINARY_BRANCH)
-                  || gensel_search_option(options, GENSEL_OPT_UNARY_BRANCH))
-               {
-                       /* Spill all other registers back to their original 
positions */
-                       printf("\t\t_jit_regs_spill_all(gen);\n");
-               }
-
                gensel_output_clause(clause, options);
 
-               printf("\t\t_jit_regs_commit(gen, &regs);\n");
+               if(contains_registers)
+               {
+                       printf("\t\t_jit_regs_commit(gen, &regs);\n");
+               }
 
                printf("\t}\n");
                first = 0;
@@ -1271,7 +1370,7 @@
 %type <code>                   CODE_BLOCK
 %type <name>                   IDENTIFIER LITERAL
 %type <name>                   IfClause IdentifierList Literal
-%type <tag>                    OptionTag InputTag RegTag LRegTag
+%type <tag>                    OptionTag InputTag RegTag LRegTag RegFlag
 %type <clauses>                        Clauses Clause
 %type <options>                        Options OptionList Pattern Pattern2
 %type <option>                 Option PatternElement Scratch Clobber If Space
@@ -1415,16 +1514,29 @@
        ;
 
 PatternElement
-       : InputTag                      { $$ = gensel_create_option($1, 0); }
-       | RegTag '(' Value ')'          { $$ = gensel_create_option($1, $3); }
-       | LRegTag '(' Value ')'         { $$ = gensel_create_option($1, $3); }
-       | LRegTag '(' ValuePair ')'     { $$ = gensel_create_option($1, 
$3.head); }
+       : InputTag                      {
+                       $$ = gensel_create_option($1, 0);
+               }
+       | RegFlag RegTag                {
+                       $$ = gensel_create_option_2($2, $1, 0);
+               }
+       | RegFlag LRegTag               {
+                       $$ = gensel_create_option_2($2, $1, 0);
+               }
+       | RegFlag RegTag '(' Value ')'  {
+                       $$ = gensel_create_option_2($2, $1, $4);
+               }
+       | RegFlag LRegTag '(' Value ')' {
+                       $$ = gensel_create_option_2($2, $1, $4);
+               }
+       | RegFlag LRegTag '(' ValuePair ')'     {
+                       $$ = gensel_create_option_2($2, $1, $4.head);
+               }
        | Scratch
        | Clobber
        | If
        | Space
        ;
-
 Scratch
        : K_SCRATCH '(' ValueList ')'   {
                        $$ = gensel_create_option(GENSEL_PATT_SCRATCH, $3.head);
@@ -1505,10 +1617,7 @@
        ;
        
 InputTag
-       : K_REG                         { $$ = GENSEL_PATT_REG; }
-       | K_LREG                        { $$ = GENSEL_PATT_LREG; }
-       | K_FREG                        { $$ = GENSEL_PATT_FREG; }
-       | K_IMM                         { $$ = GENSEL_PATT_IMM; }
+       : K_IMM                         { $$ = GENSEL_PATT_IMM; }
        | K_IMMZERO                     { $$ = GENSEL_PATT_IMMZERO; }
        | K_IMMS8                       { $$ = GENSEL_PATT_IMMS8; }
        | K_IMMU8                       { $$ = GENSEL_PATT_IMMU8; }
@@ -1526,6 +1635,12 @@
        : K_LREG                        { $$ = GENSEL_PATT_LREG; }
        ;
 
+RegFlag
+       : /* empty */                   { $$ = 0; }
+       | '*'                           { $$ = GENSEL_FLAG_CLOBBER; }
+       | '+'                           { $$ = GENSEL_FLAG_EARLY_CLOBBER; }
+       ;
+
 Literal
        : LITERAL                       { $$ = $1; }
        | Literal LITERAL               {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]