[pypy-svn] pypy default: make sure to match also the descr of operations

antocuni commits-noreply at bitbucket.org
Fri Feb 25 10:27:34 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r42275:c3d44e598019
Date: 2011-02-25 10:26 +0100
http://bitbucket.org/pypy/pypy/changeset/c3d44e598019/

Log:	make sure to match also the descr of operations

diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -180,8 +180,8 @@
         if '#' in line:
             line = line[:line.index('#')]
         # find the resvar, if any
-        if '=' in line:
-            resvar, _, line = line.partition('=')
+        if ' = ' in line:
+            resvar, _, line = line.partition(' = ')
             resvar = resvar.strip()
         else:
             resvar = None
@@ -194,12 +194,14 @@
         opname = opname.strip()
         assert args.endswith(')')
         args = args[:-1]
-        if args:
-            args = args.split(',')
-            args = map(str.strip, args)
+        args = args.split(',')
+        args = map(str.strip, args)
+        if args[-1].startswith('descr='):
+            descr = args.pop()
+            descr = descr[len('descr='):]
         else:
-            args = []
-        return opname, resvar, args
+            descr = None
+        return opname, resvar, args, descr
 
     @classmethod
     def preprocess_expected_src(cls, src):
@@ -208,11 +210,11 @@
         # replaced with the corresponding operations, so that tests don't have
         # to repeat it every time
         ticker_check = """
-            ticker0 = getfield_raw(ticker_address)
+            ticker0 = getfield_raw(ticker_address, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
             ticker1 = int_sub(ticker0, 1)
-            setfield_raw(ticker_address, ticker1)
+            setfield_raw(ticker_address, ticker1, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
             ticker_cond = int_lt(ticker1, 0)
-            guard_false(ticker_cond)
+            guard_false(ticker_cond, descr=...)
         """
         src = src.replace('--TICK--', ticker_check)
         return src
@@ -235,12 +237,13 @@
         if not cond:
             raise InvalidMatch(message)
 
-    def match_op(self, op, (exp_opname, exp_res, exp_args)):
+    def match_op(self, op, (exp_opname, exp_res, exp_args, exp_descr)):
         self._assert(op.name == exp_opname, "operation mismatch")
         self.match_var(op.res, exp_res)
         self._assert(len(op.args) == len(exp_args), "wrong number of arguments")
         for arg, exp_arg in zip(op.args, exp_args):
             self._assert(self.match_var(arg, exp_arg), "variable mismatch")
+        self._assert(op.descr == exp_descr or exp_descr == '...', "descr mismatch")
 
     def _next_op(self, iter_ops, assert_raises=False):
         try:

diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -25,14 +25,14 @@
         loop, = log.loops_by_filename(self.filepath)
         assert loop.match("""
             i9 = int_le(i7, i8)
-            guard_true(i9)
+            guard_true(i9, descr=...)
             i11 = int_add_ovf(i7, 1)
-            guard_no_overflow()
+            guard_no_overflow(descr=...)
             i12 = int_and(i8, i11)
             i13 = int_add_ovf(i6, i12)
-            guard_no_overflow()
+            guard_no_overflow(descr=...)
             --TICK--
-            jump(p0, p1, p2, p3, p4, p5, i13, i11, i8)
+            jump(p0, p1, p2, p3, p4, p5, i13, i11, i8, descr=...)
         """)
 
     def test_factorial(self):
@@ -47,12 +47,12 @@
         loop, = log.loops_by_filename(self.filepath)
         assert loop.match("""
             i7 = int_gt(i4, 1)
-            guard_true(i7)
+            guard_true(i7, descr=...)
             i8 = int_mul_ovf(i5, i4)
-            guard_no_overflow()
+            guard_no_overflow(descr=...)
             i10 = int_sub(i4, 1)
             --TICK--
-            jump(p0, p1, p2, p3, i10, i8)
+            jump(p0, p1, p2, p3, i10, i8, descr=...)
         """)
         #
         log = self.run(fact, [25], threshold=20)
@@ -60,14 +60,14 @@
         loop, = log.loops_by_filename(self.filepath)
         assert loop.match("""
             i7 = int_gt(i4, 1)
-            guard_true(i7)
-            p9 = call(ConstClass(fromint), i4)
-            guard_no_exception()
-            p11 = call(ConstClass(rbigint.mul), p5, p9)
-            guard_no_exception()
+            guard_true(i7, descr=...)
+            p9 = call(ConstClass(fromint), i4, descr=...)
+            guard_no_exception(descr=...)
+            p11 = call(ConstClass(rbigint.mul), p5, p9, descr=...)
+            guard_no_exception(descr=...)
             i13 = int_sub(i4, 1)
             --TICK--
-            jump(p0, p1, p2, p3, i13, p11)
+            jump(p0, p1, p2, p3, i13, p11, descr=...)
         """)
 
 
@@ -100,9 +100,9 @@
         loop, = log.loops_by_filename(self.filepath)
         assert loop.match_by_id('call_rec', """
             ...
-            p53 = call_assembler(p35, p7, ConstPtr(ptr21), ConstPtr(ptr49), 0, ConstPtr(ptr51), -1, ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr48))
-            guard_not_forced()
-            guard_no_exception()
+            p53 = call_assembler(p35, p7, ConstPtr(ptr21), ConstPtr(ptr49), 0, ConstPtr(ptr51), -1, ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr52), ConstPtr(ptr48), descr=...)
+            guard_not_forced(descr=...)
+            guard_no_exception(descr=...)
             ...
         """)
 

diff --git a/pypy/tool/jitlogparser/test/test_parser.py b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -21,6 +21,7 @@
     assert ops[0].repr() == 'i9 = int_lt(i7, 1003)'
     assert ops[2].descr is not None
     assert len(ops[2].args) == 1
+    assert ops[-1].repr() == 'i13 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)'
 
 def test_parse_non_code():
     ops = parse('''

diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -112,11 +112,13 @@
 
     def test_parse_op(self):
         res = OpMatcher.parse_op("  a =   int_add(  b,  3 ) # foo")
-        assert res == ("int_add", "a", ["b", "3"])
+        assert res == ("int_add", "a", ["b", "3"], None)
         res = OpMatcher.parse_op("guard_true(a)")
-        assert res == ("guard_true", None, ["a"])
-        res = OpMatcher.parse_op("force_token()")
-        assert res == ("force_token", None, [])
+        assert res == ("guard_true", None, ["a"], None)
+        res = OpMatcher.parse_op("setfield_gc(p0, i0, descr=<foobar>)")
+        assert res == ("setfield_gc", None, ["p0", "i0"], "<foobar>")
+        res = OpMatcher.parse_op("i1 = getfield_gc(p0, descr=<foobar>)")
+        assert res == ("getfield_gc", "i1", ["p0"], "<foobar>")
 
     def test_exact_match(self):
         loop = """
@@ -126,19 +128,19 @@
         """
         expected = """
             i5 = int_add(i2, 1)
-            jump(i5)
+            jump(i5, descr=...)
         """
         assert self.match(loop, expected)
         #
         expected = """
             i5 = int_sub(i2, 1)
-            jump(i5)
+            jump(i5, descr=...)
         """
         assert not self.match(loop, expected)
         #
         expected = """
             i5 = int_add(i2, 1)
-            jump(i5)
+            jump(i5, descr=...)
             extra_stuff(i5)
         """
         assert not self.match(loop, expected)
@@ -149,6 +151,16 @@
         """
         assert not self.match(loop, expected)
 
+    def test_match_descr(self):
+        loop = """
+            [p0]
+            setfield_gc(p0, 1, descr=<foobar>)
+        """
+        assert self.match(loop, "setfield_gc(p0, 1, descr=<foobar>)")
+        assert self.match(loop, "setfield_gc(p0, 1, descr=...)")
+        assert not self.match(loop, "setfield_gc(p0, 1)")
+        assert not self.match(loop, "setfield_gc(p0, 1, descr=<zzz>)")
+
 
     def test_partial_match(self):
         loop = """
@@ -163,7 +175,7 @@
             i1 = int_add(0, 1)
             ...
             i4 = int_mul(i1, 1000)
-            jump(i4)
+            jump(i4, descr=...)
         """
         assert self.match(loop, expected)
 
@@ -174,13 +186,13 @@
             i2 = int_sub(i1, 10)
             i3 = int_mul(i2, 1000)
             i4 = int_mul(i1, 1000)
-            jump(i4)
+            jump(i4, descr=...)
         """
         expected = """
             i1 = int_add(0, 1)
             ...
             _ = int_mul(_, 1000)
-            jump(i4)
+            jump(i4, descr=...)
         """
         # this does not match, because the ... stops at the first int_mul, and
         # then the second one does not match
@@ -312,7 +324,7 @@
             'jump'
             ]
 
-    def test_match(self):
+    def test_loop_match(self):
         def f():
             i = 0
             while i < 1003:
@@ -323,23 +335,23 @@
         loop, = log.loops_by_id('increment')
         assert loop.match("""
             i6 = int_lt(i4, 1003)
-            guard_true(i6)
+            guard_true(i6, descr=...)
             i8 = int_add(i4, 1)
             # signal checking stuff
-            i10 = getfield_raw(37212896)
+            i10 = getfield_raw(37212896, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
             i12 = int_sub(i10, 1)
-            setfield_raw(37212896, i12)
+            setfield_raw(37212896, i12, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
             i14 = int_lt(i12, 0)
-            guard_false(i14)
-            jump(p0, p1, p2, p3, i8)
+            guard_false(i14, descr=...)
+            jump(p0, p1, p2, p3, i8, descr=...)
         """)
         #
         assert loop.match("""
             i6 = int_lt(i4, 1003)
-            guard_true(i6)
+            guard_true(i6, descr=...)
             i8 = int_add(i4, 1)
             --TICK--
-            jump(p0, p1, p2, p3, i8)
+            jump(p0, p1, p2, p3, i8, descr=...)
         """)
         #
         assert not loop.match("""
@@ -347,7 +359,7 @@
             guard_true(i6)
             i8 = int_add(i5, 1) # variable mismatch
             --TICK--
-            jump(p0, p1, p2, p3, i8)
+            jump(p0, p1, p2, p3, i8, descr=...)
         """)
 
     def test_match_by_id(self):
@@ -367,7 +379,7 @@
         """)
         assert loop.match_by_id('product', """
             i4 = int_sub_ovf(i3, 1)
-            guard_no_overflow()
+            guard_no_overflow(descr=...)
         """)
 
     def test_match_constants(self):
@@ -380,12 +392,12 @@
         log = self.run(f)
         loop, = log.loops_by_id('increment')
         assert loop.match_by_id('increment', """
-            p12 = call(ConstClass(rbigint.add), p4, ConstPtr(ptr11))
-            guard_no_exception()
+            p12 = call(ConstClass(rbigint.add), p4, ConstPtr(ptr11), descr=...)
+            guard_no_exception(descr=...)
         """)
         #
         assert not loop.match_by_id('increment', """
-            p12 = call(ConstClass(rbigint.SUB), p4, ConstPtr(ptr11))
-            guard_no_exception()
+            p12 = call(ConstClass(rbigint.SUB), p4, ConstPtr(ptr11), descr=...)
+            guard_no_exception(descr=...)
         """)
         

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -33,7 +33,10 @@
         return self._is_guard
 
     def repr(self):
-        arglist = ', '.join(self.getargs())
+        args = self.getargs()
+        if self.descr is not None:
+            args.append('descr=%s' % self.descr)
+        arglist = ', '.join(args)
         if self.res is not None:
             return '%s = %s(%s)' % (self.getres(), self.name, arglist)
         else:


More information about the Pypy-commit mailing list