[pypy-commit] pypy result-in-resops: rename box to op

fijal noreply at buildbot.pypy.org
Tue Sep 25 11:44:03 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: result-in-resops
Changeset: r57550:6a304a8b3672
Date: 2012-09-23 21:17 +0200
http://bitbucket.org/pypy/pypy/changeset/6a304a8b3672/

Log:	rename box to op

diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -113,7 +113,7 @@
         if newvalue not in self._cached_fields and value in self._cached_fields:
             self._cached_fields[newvalue] = self._cached_fields[value]
             op = self._cached_fields_getfield_op[value].clone()
-            constbox = value.box
+            constbox = value.op
             assert isinstance(constbox, Const)
             op.setarg(0, constbox)
             self._cached_fields_getfield_op[newvalue] = op
@@ -294,7 +294,7 @@
 
     def turned_constant(self, value):
         assert value.is_constant()
-        newvalue = self.getvalue(value.box)
+        newvalue = self.getvalue(value.op)
         if value is not newvalue:
             for cf in self.cached_fields.itervalues():
                 cf.turned_constant(newvalue, value)
diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -60,11 +60,11 @@
 
         r = self.getvalue(op)
         if v2.is_constant():
-            val = v2.box.getint()
+            val = v2.op.getint()
             if val >= 0:
                 r.intbound.intersect(IntBound(0,val))
         elif v1.is_constant():
-            val = v1.box.getint()
+            val = v1.op.getint()
             if val >= 0:
                 r.intbound.intersect(IntBound(0,val))
 
@@ -108,7 +108,7 @@
         known_nonneg = (v1.intbound.known_ge(IntBound(0, 0)) and 
                         v2.intbound.known_ge(IntBound(0, 0)))
         if known_nonneg and v2.is_constant():
-            val = v2.box.getint()
+            val = v2.op.getint()
             if (val & (val-1)) == 0:
                 # nonneg % power-of-two ==> nonneg & (power-of-two - 1)
                 arg1 = op.getarg(0)
@@ -117,7 +117,7 @@
                 op = op.copy_and_change(rop.INT_AND, args=[arg1, arg2])
         self.emit_operation(op)
         if v2.is_constant():
-            val = v2.box.getint()
+            val = v2.op.getint()
             r = self.getvalue(op)
             if val < 0:
                 if val == -sys.maxint-1:
@@ -354,7 +354,7 @@
     def propagate_bounds_INT_LT(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 self.make_int_lt(op.getarg(0), op.getarg(1))
             else:
                 self.make_int_ge(op.getarg(0), op.getarg(1))
@@ -362,7 +362,7 @@
     def propagate_bounds_INT_GT(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 self.make_int_gt(op.getarg(0), op.getarg(1))
             else:
                 self.make_int_le(op.getarg(0), op.getarg(1))
@@ -370,7 +370,7 @@
     def propagate_bounds_INT_LE(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 self.make_int_le(op.getarg(0), op.getarg(1))
             else:
                 self.make_int_gt(op.getarg(0), op.getarg(1))
@@ -378,7 +378,7 @@
     def propagate_bounds_INT_GE(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 self.make_int_ge(op.getarg(0), op.getarg(1))
             else:
                 self.make_int_lt(op.getarg(0), op.getarg(1))
@@ -386,7 +386,7 @@
     def propagate_bounds_INT_EQ(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 v1 = self.getvalue(op.getarg(0))
                 v2 = self.getvalue(op.getarg(1))
                 if v1.intbound.intersect(v2.intbound):
@@ -397,7 +397,7 @@
     def propagate_bounds_INT_NE(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_0):
+            if r.op.same_constant(CONST_0):
                 v1 = self.getvalue(op.getarg(0))
                 v2 = self.getvalue(op.getarg(1))
                 if v1.intbound.intersect(v2.intbound):
@@ -408,7 +408,7 @@
     def propagate_bounds_INT_IS_TRUE(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 v1 = self.getvalue(op.getarg(0))
                 if v1.intbound.known_ge(IntBound(0, 0)):
                     v1.intbound.make_gt(IntBound(0, 0))
@@ -417,7 +417,7 @@
     def propagate_bounds_INT_IS_ZERO(self, op):
         r = self.getvalue(op)
         if r.is_constant():
-            if r.box.same_constant(CONST_1):
+            if r.op.same_constant(CONST_1):
                 v1 = self.getvalue(op.getarg(0))
                 # Clever hack, we can't use self.make_constant_int yet because
                 # the args aren't in the values dictionary yet so it runs into
diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -1,6 +1,6 @@
 from pypy.jit.metainterp import jitprof, resume, compile
 from pypy.jit.metainterp.executor import execute_nonspec
-from pypy.jit.metainterp.resoperation import BoxInt, BoxFloat, REF
+from pypy.jit.metainterp.resoperation import BoxInt, BoxFloat, REF, INT
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound, IntUnbounded, \
                                                      ImmutableIntUnbounded, \
                                                      IntLowerBound, MININT, MAXINT
@@ -29,7 +29,7 @@
         return LenBound(self.mode, self.descr, self.bound.clone())
 
 class OptValue(object):
-    _attrs_ = ('box', 'known_class', 'last_guard', 'level', 'intbound', 'lenbound', 'is_bool_box')
+    _attrs_ = ('known_class', 'last_guard', 'level', 'intbound', 'lenbound', 'is_bool_box')
     last_guard = None
 
     level = LEVEL_UNKNOWN
@@ -38,21 +38,31 @@
     lenbound = None
     is_bool_box = False
 
-    def __init__(self, box, level=None, known_class=None, intbound=None):
-        self.box = box
+    def getbox(self):
+        import pdb
+        pdb.set_trace()
+
+    def setbox(self, x):
+        import pdb
+        pdb.set_trace()
+
+    box = property(getbox, setbox)
+
+    def __init__(self, op, level=None, known_class=None, intbound=None):
+        self.op = op
         if level is not None:
             self.level = level
         self.known_class = known_class
         if intbound:
             self.intbound = intbound
         else:
-            if isinstance(box, BoxInt):
+            if op is not None and op.type == INT:
                 self.intbound = IntBound(MININT, MAXINT)
             else:
                 self.intbound = IntUnbounded()
 
-        if isinstance(box, Const):
-            self.make_constant(box)
+        if isinstance(op, Const):
+            self.make_constant(op)
         # invariant: box is a Const if and only if level == LEVEL_CONSTANT
 
     def make_len_gt(self, mode, descr, val):
@@ -118,10 +128,10 @@
 
 
     def force_box(self, optforce):
-        return self.box
+        return self.op
 
     def get_key_box(self):
-        return self.box
+        return self.op
 
     def force_at_end_of_preamble(self, already_forced, optforce):
         return self
@@ -139,9 +149,9 @@
 
     def is_null(self):
         if self.is_constant():
-            box = self.box
-            assert isinstance(box, Const)
-            return not box.nonnull()
+            op = self.op
+            assert isinstance(op, Const)
+            return not op.nonnull()
         return False
 
     def same_value(self, other):
@@ -154,7 +164,7 @@
     def make_constant(self, constbox):
         """Replace 'self.box' with a Const box."""
         assert isinstance(constbox, Const)
-        self.box = constbox
+        self.op = constbox
         self.level = LEVEL_CONSTANT
 
         if isinstance(constbox, ConstInt):
@@ -168,7 +178,7 @@
         if level == LEVEL_KNOWNCLASS:
             return self.known_class
         elif level == LEVEL_CONSTANT:
-            return cpu.ts.cls_of_box(self.box)
+            return cpu.ts.cls_of_box(self.op)
         else:
             return None
 
@@ -188,9 +198,9 @@
         if level == LEVEL_NONNULL or level == LEVEL_KNOWNCLASS:
             return True
         elif level == LEVEL_CONSTANT:
-            box = self.box
-            assert isinstance(box, Const)
-            return box.nonnull()
+            op = self.op
+            assert isinstance(op, Const)
+            return op.nonnull()
         elif self.intbound:
             if self.intbound.known_gt(IntBound(0, 0)) or \
                self.intbound.known_lt(IntBound(0, 0)):
@@ -208,7 +218,7 @@
         # Don't check this with 'isinstance(_, VirtualValue)'!
         # Even if it is a VirtualValue, the 'box' can be non-None,
         # meaning it has been forced.
-        return self.box is None
+        return False
 
     def is_forced_virtual(self):
         return False
@@ -470,7 +480,7 @@
         except KeyError:
             return None
         if value.is_constant():
-            constbox = value.box
+            constbox = value.op
             assert isinstance(constbox, Const)
             return constbox
         return None
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -34,10 +34,10 @@
         if oldop is not None and oldop.getdescr() is op.getdescr():
             value = self.getvalue(oldop)
             if value.is_constant():
-                if value.box.same_constant(CONST_1):
+                if value.op.same_constant(CONST_1):
                     self.make_constant(op, CONST_0)
                     return True
-                elif value.box.same_constant(CONST_0):
+                elif value.op.same_constant(CONST_0):
                     self.make_constant(op, CONST_1)
                     return True
 
@@ -88,7 +88,7 @@
     def optimize_INT_SUB(self, op):
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
-        if v2.is_constant() and v2.box.getint() == 0:
+        if v2.is_constant() and v2.op.getint() == 0:
             self.make_equal_to(op, v1)
         else:
             self.emit_operation(op)
@@ -103,9 +103,9 @@
         v2 = self.getvalue(arg2)
 
         # If one side of the op is 0 the result is the other side.
-        if v1.is_constant() and v1.box.getint() == 0:
+        if v1.is_constant() and v1.op.getint() == 0:
             self.replace(op, arg2)
-        elif v2.is_constant() and v2.box.getint() == 0:
+        elif v2.is_constant() and v2.op.getint() == 0:
             self.replace(op, arg1)
         else:
             self.emit_operation(op)
@@ -118,20 +118,20 @@
         v2 = self.getvalue(op.getarg(1))
 
         # If one side of the op is 1 the result is the other side.
-        if v1.is_constant() and v1.box.getint() == 1:
+        if v1.is_constant() and v1.op.getint() == 1:
             self.make_equal_to(op, v2)
-        elif v2.is_constant() and v2.box.getint() == 1:
+        elif v2.is_constant() and v2.op.getint() == 1:
             self.make_equal_to(op, v1)
-        elif (v1.is_constant() and v1.box.getint() == 0) or \
-             (v2.is_constant() and v2.box.getint() == 0):
+        elif (v1.is_constant() and v1.op.getint() == 0) or \
+             (v2.is_constant() and v2.op.getint() == 0):
             self.make_constant_int(op, 0)
         else:
             for lhs, rhs in [(v1, v2), (v2, v1)]:
                 if lhs.is_constant():
-                    x = lhs.box.getint()
+                    x = lhs.op.getint()
                     # x & (x - 1) == 0 is a quick test for power of 2
                     if x & (x - 1) == 0:
-                        new_rhs = ConstInt(highest_bit(lhs.box.getint()))
+                        new_rhs = ConstInt(highest_bit(lhs.op.getint()))
                         xxx
                         op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs])
                         break
@@ -141,7 +141,7 @@
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
 
-        if v2.is_constant() and v2.box.getint() == 1:
+        if v2.is_constant() and v2.op.getint() == 1:
             self.make_equal_to(op, v1)
         else:
             self.emit_operation(op)
@@ -150,7 +150,7 @@
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
 
-        if v2.is_constant() and v2.box.getint() == 0:
+        if v2.is_constant() and v2.op.getint() == 0:
             self.make_equal_to(op, v1)
         else:
             self.emit_operation(op)
@@ -159,7 +159,7 @@
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
 
-        if v2.is_constant() and v2.box.getint() == 0:
+        if v2.is_constant() and v2.op.getint() == 0:
             self.make_equal_to(op, v1)
         else:
             self.emit_operation(op)
@@ -175,10 +175,10 @@
             v2 = self.getvalue(rhs)
 
             if v1.is_constant():
-                if v1.box.getfloat() == 1.0:
+                if v1.op.getfloat() == 1.0:
                     self.make_equal_to(op, v2)
                     return
-                elif v1.box.getfloat() == -1.0:
+                elif v1.op.getfloat() == -1.0:
                     self.emit_operation(ResOperation(
                         rop.FLOAT_NEG, [rhs], op
                     ))
@@ -194,7 +194,7 @@
     def optimize_guard(self, op, constbox, emit_operation=True):
         value = self.getvalue(op.getarg(0))
         if value.is_constant():
-            box = value.box
+            box = value.op
             assert isinstance(box, Const)
             #if not box.same_constant(constbox):
             #    raise Exception('A GUARD_{VALUE,TRUE,FALSE} was proven to' +
@@ -481,14 +481,14 @@
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
 
-        if v2.is_constant() and v2.box.getint() == 1:
+        if v2.is_constant() and v2.op.getint() == 1:
             self.make_equal_to(op, v1)
             return
-        elif v1.is_constant() and v1.box.getint() == 0:
+        elif v1.is_constant() and v1.op.getint() == 0:
             self.make_constant_int(op, 0)
             return
         if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant():
-            val = v2.box.getint()
+            val = v2.op.getint()
             if val & (val - 1) == 0 and val > 0: # val == 2**shift
                 xxx
                 op = op.copy_and_change(rop.INT_RSHIFT,
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -503,7 +503,7 @@
         pv = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(pv, p0, descr=valuedescr)
         guard_nonnull(p0) []
-        p1 = getfield_gc(pv, descr=valuedescr)
+        p1 = getfield_gc_p(pv, descr=valuedescr)
         guard_nonnull(p1) []
         jump(p0)
         """
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -18,7 +18,10 @@
         self.forced = False
 
     def is_forced_virtual(self):
-        return self.box is not None
+        return self.forced
+
+    def is_virtual(self):
+        return not self.forced
 
     def get_key_box(self):
         if self.box is None:


More information about the pypy-commit mailing list