]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add a few comments, and shuffle the definition of NOP to keep the
authorguy <guy>
Tue, 9 Nov 2004 01:20:18 +0000 (01:20 +0000)
committerguy <guy>
Tue, 9 Nov 2004 01:20:18 +0000 (01:20 +0000)
definitions for register atoms together.

A conditional jump uses the X register as well as the A register if it's
comparing the A register against the X register rather than a constant;
handle that case when computing the set of registers used by a block.

optimize.c

index 1ae7e523f121268bce8aa71402c137c3b6859c02..748fc42bd318f148e55fe7f1419d9ef85d746c4c 100644 (file)
@@ -22,7 +22,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.79 2004-11-08 09:03:37 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.80 2004-11-09 01:20:18 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -47,11 +47,20 @@ static const char rcsid[] _U_ =
 extern int dflag;
 #endif
 
+/*
+ * Represents a deleted instruction.
+ */
+#define NOP -1
+
+/*
+ * Register numbers for use-def values.
+ * 0 through BPF_MEMWORDS-1 represent the corresponding scratch memory
+ * location.  A_ATOM is the accumulator and X_ATOM is the index
+ * register.
+ */
 #define A_ATOM BPF_MEMWORDS
 #define X_ATOM (BPF_MEMWORDS+1)
 
-#define NOP -1
-
 /*
  * This define is used to represent *both* the accumulator and
  * x register in use-def computations.
@@ -419,6 +428,15 @@ atomdef(s)
        return -1;
 }
 
+/*
+ * Compute the sets of registers used, defined, and killed by 'b'.
+ *
+ * "Used" means that a statement in 'b' uses the register before any
+ * statement in 'b' defines it.
+ * "Defined" means that a statement in 'b' defines it.
+ * "Killed" means that a statement in 'b' defines it before any
+ * statement in 'b' uses it.
+ */
 static void
 compute_local_ud(b)
        struct block *b;
@@ -452,8 +470,26 @@ compute_local_ud(b)
                        def |= ATOMMASK(atom);
                }
        }
-       if (!ATOMELEM(def, A_ATOM) && BPF_CLASS(b->s.code) == BPF_JMP)
-               use |= ATOMMASK(A_ATOM);
+       if (BPF_CLASS(b->s.code) == BPF_JMP) {
+               /*
+                * XXX - what about RET?
+                */
+               atom = atomuse(&b->s);
+               if (atom >= 0) {
+                       if (atom == AX_ATOM) {
+                               if (!ATOMELEM(def, X_ATOM))
+                                       use |= ATOMMASK(X_ATOM);
+                               if (!ATOMELEM(def, A_ATOM))
+                                       use |= ATOMMASK(A_ATOM);
+                       }
+                       else if (atom < N_ATOMS) {
+                               if (!ATOMELEM(def, atom))
+                                       use |= ATOMMASK(atom);
+                       }
+                       else
+                               abort();
+               }
+       }
 
        b->def = def;
        b->kill = kill;