[pypy-commit] pypy result-in-resops: (fijal, arigo) Kill kill kill.

arigo noreply at buildbot.pypy.org
Fri Oct 12 17:42:19 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: result-in-resops
Changeset: r58068:b83240c8204f
Date: 2012-10-12 17:41 +0200
http://bitbucket.org/pypy/pypy/changeset/b83240c8204f/

Log:	(fijal, arigo) Kill kill kill.

diff --git a/pypy/jit/metainterp/resoperation.py b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -2,16 +2,12 @@
 """ This files describes the model used in pyjitpl. Note that all of the
 following are IMMUTABLE. That means that we cannot just randomly change
 parameters, instead we need to create a new version and setup the correct
-forwarding. Optimizeopt uses optimize_value extra parameter for setting
-up the forwarding of resops. Public interface:
+forwarding. Public interface:
 
 * create_resop, create_resop_0, create_resop_1, create_resop_2, create_resop_3
 
   create resops of various amount of arguments
 
-* BoxInt, BoxFloat, BoxPtr - various types of Boxes. Boxes are inputargs to
-  the loop.
-
 * ConstInt, ConstFloat, ConstPtr - constant versions of boxes
 
 """
@@ -240,10 +236,6 @@
     def is_constant(self):
         return False
 
-    @specialize.arg(1)
-    def get_extra(self, key):
-        raise KeyError
-
     def get_key_op(self, optimizer):
         return self
 
@@ -288,175 +280,6 @@
     except AttributeError:
         return box.value
 
-class Box(AbstractValue):
-    __slots__ = ()
-    _counter = 0
-    _extended_display = True
-
-    def nonconstbox(self):
-        return self
-
-    def _get_hash_(self):
-        return compute_identity_hash(self)
-
-    def __repr__(self):
-        result = str(self)
-        if self._extended_display:
-            result += '(%s)' % self._getrepr_()
-        return result
-
-    def __str__(self):
-        if not hasattr(self, '_str'):
-            try:
-                if self.type == INT:
-                    t = 'i'
-                elif self.type == FLOAT:
-                    t = 'f'
-                else:
-                    t = 'p'
-            except AttributeError:
-                t = 'b'
-            self._str = '%s%d' % (t, Box._counter)
-            Box._counter += 1
-        return self._str
-
-    def _get_str(self):    # for debugging only
-        return self.constbox()._get_str()
-
-    def forget_value(self):
-        raise NotImplementedError
-
-    def is_constant(self):
-        return False
-
-    @specialize.arg(1)
-    def get_extra(self, key):
-        if key == 'llgraph_var2index':
-            return self.llgraph_var2index
-        if key == 'optimize_value':
-            try:
-                return self._optimize_value
-            except AttributeError:
-                raise KeyError
-        raise KeyError
-
-    @specialize.arg(1)
-    def set_extra(self, key, value):
-        if key == 'llgraph_var2index':
-            self.llgraph_var2index = value
-            return
-        if key == 'optimize_value':
-            self._optimize_value = value
-            return
-        raise KeyError
-
-    @specialize.arg(1)
-    def del_extra(self, key):
-        if key == 'optimize_value':
-            if hasattr(self, '_optimize_value'):
-                del self._optimize_value
-
-class BoxInt(Box):
-    type = INT
-    _attrs_ = ('value',)
-
-    def __init__(self, value=0):
-        if not we_are_translated():
-            if is_valid_int(value):
-                value = int(value)    # bool -> int
-            else:
-                assert isinstance(value, Symbolic)
-        self.value = value
-
-    def forget_value(self):
-        self.value = 0
-
-    def constbox(self):
-        return ConstInt(self.value)
-
-    def getint(self):
-        return self.value
-
-    def getaddr(self):
-        return heaptracker.int2adr(self.value)
-
-    def nonnull(self):
-        return self.value != 0
-
-    def _getrepr_(self):
-        return self.value
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'bi')
-
-    def eq_value(self, other):
-        return self.value == other.getint()
-
-class BoxFloat(Box):
-    type = FLOAT
-    _attrs_ = ('value',)
-
-    def __init__(self, valuestorage=longlong.ZEROF):
-        assert lltype.typeOf(valuestorage) is longlong.FLOATSTORAGE
-        self.value = valuestorage
-
-    def forget_value(self):
-        self.value = longlong.ZEROF
-
-    def constbox(self):
-        return ConstFloat(self.value)
-
-    def getfloatstorage(self):
-        return self.value
-
-    def nonnull(self):
-        return self.value != longlong.ZEROF
-
-    def _getrepr_(self):
-        return self.getfloat()
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'bf')
-
-    def eq_value(self, other):
-        return self.value == other.getfloatstorage()
-
-class BoxPtr(Box):
-    type = REF
-    _attrs_ = ('value',)
-
-    def __init__(self, value=lltype.nullptr(llmemory.GCREF.TO)):
-        assert lltype.typeOf(value) == llmemory.GCREF
-        self.value = value
-
-    def forget_value(self):
-        self.value = lltype.nullptr(llmemory.GCREF.TO)
-
-    def constbox(self):
-        return ConstPtr(self.value)
-
-    def getref_base(self):
-        return self.value
-
-    def getref(self, PTR):
-        return lltype.cast_opaque_ptr(PTR, self.getref_base())
-    getref._annspecialcase_ = 'specialize:arg(1)'
-
-    def getaddr(self):
-        return llmemory.cast_ptr_to_adr(self.value)
-
-    def nonnull(self):
-        return bool(self.value)
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'bp')
-
-    def eq_value(self, other):
-        return self.value == other.getref_base()
-
-    _getrepr_ = repr_pointer
-
-NULLBOX = BoxPtr()
 
 class Const(AbstractValue):
     __slots__ = ()
@@ -654,46 +477,6 @@
     _hash = 0
     opnum = 0
 
-    DOCUMENTED_KEYS = {
-        'failargs': 'arguments for guard ops that are alive. '
-                    'valid from optimizations (store_final_args) until '
-                    'the backend',
-        'llgraph_var2index': 'llgraph internal attribute',
-        'optimize_value': 'value replacement for the optimizer. only valid for'
-                          ' the length of optimization pass',
-        'optimize_replace': 'replacement for the op by another op, can be '
-                            'chained',
-    }
-
-    extras = None
-    # ResOps are immutable, however someone can store a temporary
-    # extra mutable stuff here, in the extras field. Other fields (including
-    # descr) should be deeply immutable. This replaces various dictionaries
-    # that has been previously used.
-
-    @specialize.arg(1)
-    def get_extra(self, key):
-        if key not in self.DOCUMENTED_KEYS:
-            raise Exception("Please document '%s' extra parameter and it's lifetime" % key)
-        if not hasattr(self, key):
-            raise KeyError
-        return getattr(self, key)
-
-    @specialize.arg(1)
-    def has_extra(self, key):
-        return hasattr(self, key)
-
-    @specialize.arg(1)
-    def set_extra(self, key, value):
-        if key not in self.DOCUMENTED_KEYS:
-            raise Exception("Please document '%s' extra parameter and it's lifetime" % key)
-        setattr(self, key, value)
-
-    @specialize.arg(1)
-    def del_extra(self, key):
-        if hasattr(self, key):
-            delattr(self, key)
-
     @classmethod
     def getopnum(cls):
         return cls.opnum
@@ -1394,6 +1177,7 @@
     '_FINAL_LAST',
 
     'LABEL/*d/N',
+    'INPUT/0/*',
 
     '_GUARD_FIRST',
     '_GUARD_FOLDABLE_FIRST',
diff --git a/pypy/jit/metainterp/test/test_resoperation.py b/pypy/jit/metainterp/test/test_resoperation.py
--- a/pypy/jit/metainterp/test/test_resoperation.py
+++ b/pypy/jit/metainterp/test/test_resoperation.py
@@ -17,15 +17,18 @@
     def __ne__(self, other):
         return not self == other
 
-    def __hash__(self):
-        return hash(self.v)
-
     def __str__(self):
         return self.v
 
     def is_constant(self):
         return False
 
+    def _get_hash_(self):
+        return 75 + self.v
+
+    def eq(self, other):
+        return self.v == other.v
+
 class FakeDescr(AbstractDescr):
     def __repr__(self):
         return 'descr'
@@ -109,37 +112,6 @@
             return FakeBox('rrr')
         return None
 
-def test_copy_if_modified_by_optimization():
-    mydescr = FakeDescr()
-    op = rop.create_resop_0(rop.rop.GUARD_NO_EXCEPTION, None)
-    op.setdescr(mydescr)
-    assert op.copy_if_modified_by_optimization(MockOpt({})) is op
-    op = rop.create_resop_1(rop.rop.INT_IS_ZERO, 1, FakeBox('a'))
-    assert op.copy_if_modified_by_optimization(MockOpt({})) is op
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('a')])))
-    assert op2 is not op
-    assert op2.getarg(0) == FakeBox('rrr')
-    op = rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox("a"), FakeBox("b"))
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('c')])))
-    assert op2 is op
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('b')])))
-    assert op2 is not op
-    assert op2._arg0 is op._arg0
-    assert op2._arg1 != op._arg1
-    assert op2.getint() == op.getint()
-    op = rop.create_resop_3(rop.rop.STRSETITEM, None, FakeBox('a'),
-                            FakeBox('b'), FakeBox('c'))
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('b')])))
-    assert op2 is not op
-    op = rop.create_resop(rop.rop.CALL_i, 13, [FakeBox('a'), FakeBox('b'),
-                            FakeBox('c')], descr=mydescr)
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('aa')])))
-    assert op2 is op
-    op2 = op.copy_if_modified_by_optimization(MockOpt(set([FakeBox('b')])))
-    assert op2 is not op
-    assert op2.getarglist() == [FakeBox("a"), FakeBox("rrr"), FakeBox("c")]
-    assert op2.getdescr() == mydescr
-
 def test_copy_and_change():    
     op = rop.create_resop_1(rop.rop.INT_IS_ZERO, 1, FakeBox('a'))
     op2 = op.copy_and_change(rop.rop.INT_IS_TRUE)
@@ -169,13 +141,9 @@
     op2 = op.copy_and_change(rop.rop.CALL_i, [FakeBox('a')])
     assert op2.getarglist() == ['a']
 
-def test_get_set_extra():
-    op = rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox("a"), FakeBox("b"))
-    op.set_extra("failargs", 2)
-    assert op.get_extra("failargs") == 2
-
 def test_hashes_eq():
-    arg1 = rop.create_resop_1(rop.rop.FLOAT_NEG, 12.5, rop.BoxFloat(3.5))
+    arg1 = rop.create_resop_1(rop.rop.FLOAT_NEG, 12.5,
+                              rop.create_resop_0(rop.rop.INPUT_f, 3.5))
     op = rop.create_resop_2(rop.rop.FLOAT_ADD, 13.5, rop.ConstFloat(3.0),
                             arg1)
     ope = rop.create_resop_2(rop.rop.FLOAT_ADD, 13.5, rop.ConstFloat(3.0),
@@ -204,39 +172,35 @@
     s = lltype.malloc(S)
     nonnull_ref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
     nullref = lltype.nullptr(llmemory.GCREF.TO)
-    op = rop.create_resop_1(rop.rop.NEWSTR, nullref, rop.BoxInt(5))
-    op1 = rop.create_resop_1(rop.rop.NEWSTR, nonnull_ref, rop.BoxInt(5))
+    op = rop.create_resop_1(rop.rop.NEWSTR, nullref, FakeBox(5))
+    op1 = rop.create_resop_1(rop.rop.NEWSTR, nonnull_ref, FakeBox(5))
     assert op._get_hash_() != op1._get_hash_()
     assert not op.eq(op1)
-    op = rop.create_resop_1(rop.rop.NEWSTR, nullref, rop.BoxInt(5))
-    op1 = rop.create_resop_1(rop.rop.NEWSTR, nullref, rop.BoxInt(15))
+    op = rop.create_resop_1(rop.rop.NEWSTR, nullref, FakeBox(5))
+    op1 = rop.create_resop_1(rop.rop.NEWSTR, nullref, FakeBox(5))
+    assert op._get_hash_() == op1._get_hash_()
+    assert op.eq(op1)
+    op = rop.create_resop_1(rop.rop.NEWSTR, nullref, FakeBox(5))
+    op1 = rop.create_resop_1(rop.rop.NEWSTR, nullref, FakeBox(15))
     assert op._get_hash_() != op1._get_hash_()
     assert not op.eq(op1)
 
     descr = FakeDescr()
     descr2 = FakeDescr()
-    op = rop.create_resop(rop.rop.CALL_i, 12, [rop.BoxInt(0), rop.BoxFloat(2.0),
-                                               rop.BoxPtr(nullref)], descr)
-    op1 = rop.create_resop(rop.rop.CALL_i, 12, [rop.BoxInt(0),
-                                                rop.BoxFloat(2.0),
-                                                rop.BoxPtr(nullref)], descr2)
-    op2 = rop.create_resop(rop.rop.CALL_i, 12, [rop.BoxInt(0),
-                                                rop.BoxFloat(2.5),
-                                                rop.BoxPtr(nullref)], descr)
-    op3 = rop.create_resop(rop.rop.CALL_i, 15, [rop.BoxInt(0),
-                                                rop.BoxFloat(2.0),
-                                                rop.BoxPtr(nullref)], descr)
-    op4 = rop.create_resop(rop.rop.CALL_i, 12, [rop.BoxInt(0),
-                                                rop.BoxFloat(2.0),
-                                                rop.BoxPtr(nonnull_ref)], descr)
+    op = rop.create_resop(rop.rop.CALL_i, 12, [FakeBox(0), FakeBox(2),
+                                               FakeBox(4)], descr)
+    op1 = rop.create_resop(rop.rop.CALL_i, 12, [FakeBox(0), FakeBox(2),
+                                                FakeBox(4)], descr2)
+    op2 = rop.create_resop(rop.rop.CALL_i, 12, [FakeBox(0), FakeBox(3),
+                                                FakeBox(4)], descr)
+    op3 = rop.create_resop(rop.rop.CALL_i, 15, [FakeBox(0), FakeBox(2),
+                                                FakeBox(4)], descr)
     assert op1._get_hash_() != op._get_hash_()
     assert op2._get_hash_() != op._get_hash_()
     assert op3._get_hash_() != op._get_hash_()
-    assert op4._get_hash_() != op._get_hash_()
     assert not op.eq(op1)
     assert not op.eq(op2)
     assert not op.eq(op3)
-    assert not op.eq(op4)
 
     # class StrangeDescr(AbstractDescr):
     #     def _get_hash_(self):


More information about the pypy-commit mailing list