bison-patches
[Top][All Lists]
Advanced

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

03-fyi-output-locality.patch


From: Akim Demaille
Subject: 03-fyi-output-locality.patch
Date: Mon, 17 Dec 2001 18:20:46 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/output.c (action_row, save_column, default_goto)
        (sort_actions, matching_state, pack_vector): Better variable
        locality.
        
        
Index: src/output.c
--- src/output.c Sun, 16 Dec 2001 16:24:24 +0100 akim
+++ src/output.c Sun, 16 Dec 2001 16:38:21 +0100 akim
@@ -309,55 +309,44 @@
 action_row (int state)
 {
   int i;
-  int j;
   int m = 0;
   int n = 0;
-  int default_rule;
-  int nreds;
-  int rule;
-  int shift_state;
-  int symbol;
-  reductions *redp;
-  shifts *shiftp;
-  errs *errp;
-  int nodefault = 0;           /* set nonzero to inhibit having any default 
reduction */
+  int default_rule = 0;
+  reductions *redp = state_table[state]->reductions;
+  int nreds = redp ? redp->nreds : 0;
+  shifts *shiftp = state_table[state]->shifts;
+  errs *errp = state_table[state]->errs;
+  /* set nonzero to inhibit having any default reduction */
+  int nodefault = 0;
 
   for (i = 0; i < ntokens; i++)
     actrow[i] = 0;
 
-  default_rule = 0;
-  nreds = 0;
-  redp = state_table[state]->reductions;
-
-  if (redp)
+  if (nreds >= 1)
     {
-      nreds = redp->nreds;
-
-      if (nreds >= 1)
-       {
-         /* loop over all the rules available here which require
-            lookahead */
-         m = state_table[state]->lookaheads;
-         n = state_table[state + 1]->lookaheads;
-
-         for (i = n - 1; i >= m; i--)
-           /* and find each token which the rule finds acceptable
-              to come next */
-           for (j = 0; j < ntokens; j++)
-             /* and record this rule as the rule to use if that
-                token follows.  */
-             if (BITISSET (LA (i), j))
-               actrow[j] = -LAruleno[i];
-       }
+      int j;
+      /* loop over all the rules available here which require
+        lookahead */
+      m = state_table[state]->lookaheads;
+      n = state_table[state + 1]->lookaheads;
+
+      for (i = n - 1; i >= m; i--)
+       /* and find each token which the rule finds acceptable
+          to come next */
+       for (j = 0; j < ntokens; j++)
+         /* and record this rule as the rule to use if that
+            token follows.  */
+         if (BITISSET (LA (i), j))
+           actrow[j] = -LAruleno[i];
     }
 
   /* Now see which tokens are allowed for shifts in this state.  For
      them, record the shift as the thing to do.  So shift is preferred
      to reduce.  */
-  shiftp = state_table[state]->shifts;
   for (i = 0; i < shiftp->nshifts; i++)
     {
-      shift_state = shiftp->shifts[i];
+      int symbol;
+      int shift_state = shiftp->shifts[i];
       if (!shift_state)
        continue;
 
@@ -376,12 +365,10 @@
 
   /* See which tokens are an explicit error in this state (due to
      %nonassoc).  For them, record MINSHORT as the action.  */
-  errp = state_table[state]->errs;
-
   if (errp)
     for (i = 0; i < errp->nerrs; i++)
       {
-       symbol = errp->errs[i];
+       int symbol = errp->errs[i];
        actrow[symbol] = MINSHORT;
       }
 
@@ -398,13 +385,12 @@
          for (i = m; i < n; i++)
            {
              int count = 0;
-             rule = -LAruleno[i];
+             int rule = -LAruleno[i];
+             int j;
 
              for (j = 0; j < ntokens; j++)
-               {
-                 if (actrow[j] == rule)
-                   count++;
-               }
+               if (actrow[j] == rule)
+                 count++;
 
              if (count > max)
                {
@@ -418,11 +404,10 @@
 
          if (max > 0)
            {
+             int j;
              for (j = 0; j < ntokens; j++)
-               {
-                 if (actrow[j] == default_rule)
-                   actrow[j] = 0;
-               }
+               if (actrow[j] == default_rule)
+                 actrow[j] = 0;
 
              default_rule = -default_rule;
            }
@@ -433,11 +418,9 @@
      So replace any action which says "error" with "use default".  */
 
   if (default_rule == 0)
-    for (j = 0; j < ntokens; j++)
-      {
-       if (actrow[j] == MINSHORT)
-         actrow[j] = 0;
-      }
+    for (i = 0; i < ntokens; i++)
+      if (actrow[i] == MINSHORT)
+       actrow[i] = 0;
 
   return default_rule;
 }
@@ -541,7 +524,7 @@
   short *sp1;
   short *sp2;
   int count;
-  int symno;
+  int symno = symbol - ntokens + nstates;
 
   short begin = goto_map[symbol];
   short end = goto_map[symbol + 1];
@@ -554,8 +537,6 @@
   if (count == 0)
     return;
 
-  symno = symbol - ntokens + nstates;
-
   froms[symno] = sp1 = sp = XCALLOC (short, count);
   tos[symno] = sp2 = XCALLOC (short, count);
 
@@ -574,13 +555,10 @@
 default_goto (int symbol)
 {
   int i;
-  int m;
-  int n;
-  int default_state;
-  int max;
-
-  m = goto_map[symbol];
-  n = goto_map[symbol + 1];
+  int m = goto_map[symbol];
+  int n = goto_map[symbol + 1];
+  int default_state = -1;
+  int max = 0;
 
   if (m == n)
     return -1;
@@ -591,9 +569,6 @@
   for (i = m; i < n; i++)
     state_count[to_state[i]]++;
 
-  max = 0;
-  default_state = -1;
-
   for (i = 0; i < nstates; i++)
     if (state_count[i] > max)
       {
@@ -644,10 +619,6 @@
 sort_actions (void)
 {
   int i;
-  int j;
-  int k;
-  int t;
-  int w;
 
   order = XCALLOC (short, nvectors);
   nentries = 0;
@@ -655,9 +626,10 @@
   for (i = 0; i < nvectors; i++)
     if (tally[i] > 0)
       {
-       t = tally[i];
-       w = width[i];
-       j = nentries - 1;
+       int k;
+       int t = tally[i];
+       int w = width[i];
+       int j = nentries - 1;
 
        while (j >= 0 && (width[order[j]] < w))
          j--;
@@ -677,15 +649,11 @@
 static int
 matching_state (int vector)
 {
-  int i;
-  int j;
-  int k;
+  int i = order[vector];
   int t;
   int w;
-  int match;
   int prev;
 
-  i = order[vector];
   if (i >= nstates)
     return -1;
 
@@ -694,11 +662,13 @@
 
   for (prev = vector - 1; prev >= 0; prev--)
     {
-      j = order[prev];
+      int j = order[prev];
+      int k;
+      int match = 1;
+
       if (width[j] != w || tally[j] != t)
        return -1;
 
-      match = 1;
       for (k = 0; match && k < t; k++)
        if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
          match = 0;
@@ -714,26 +684,19 @@
 static int
 pack_vector (int vector)
 {
-  int i;
+  int i = order[vector];
   int j;
-  int k;
-  int t;
+  int t = tally[i];
   int loc = 0;
-  int ok;
-  short *from;
-  short *to;
-
-  i = order[vector];
-  t = tally[i];
+  short *from = froms[i];
+  short *to = tos[i];
 
   assert (t);
 
-  from = froms[i];
-  to = tos[i];
-
   for (j = lowzero - from[0]; j < MAXTABLE; j++)
     {
-      ok = 1;
+      int k;
+      int ok = 1;
 
       for (k = 0; ok && k < t; k++)
        {



reply via email to

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