Author: fijal
Branch: jit-leaner-frontend
Changeset: r83240:2acab7b506ec
Date: 2016-03-22 09:49 +0200
http://bitbucket.org/pypy/pypy/changeset/2acab7b506ec/

Log:    whack at this test until it passes

diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py 
b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -12,7 +12,7 @@
 from rpython.jit.metainterp.optimizeopt.util import sort_descrs, equaloplists
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.metainterp.logger import LogOperations
-from rpython.jit.tool.oparser import OpParser, pure_parse
+from rpython.jit.tool.oparser import OpParser, pure_parse, 
convert_loop_to_trace
 from rpython.jit.metainterp.quasiimmut import QuasiImmutDescr
 from rpython.jit.metainterp import compile, resume, history
 from rpython.jit.metainterp.jitprof import EmptyProfiler
@@ -545,50 +545,6 @@
             call_pure_results[list(k)] = v
         return call_pure_results
 
-    def pick_cls(self, inp):
-        if inp.type == 'i':
-            return history.IntFrontendOp
-        elif inp.type == 'r':
-            return history.RefFrontendOp
-        else:
-            assert inp.type == 'f'
-            return history.FloatFrontendOp
-
-    def convert_loop_to_packed(self, loop, skip_last=False):
-        from rpython.jit.metainterp.opencoder import Trace
-        from rpython.jit.metainterp.test.test_opencoder import FakeFrame
-
-        def get(a):
-            if isinstance(a, history.Const):
-                return a
-            return mapping[a]
-
-        class jitcode:
-            index = 200
-
-        inputargs = [self.pick_cls(inparg)(i) for i, inparg in
-                     enumerate(loop.inputargs)]
-        mapping = {}
-        for one, two in zip(loop.inputargs, inputargs):
-            mapping[one] = two
-        trace = Trace(inputargs)
-        ops = loop.operations
-        if skip_last:
-            ops = ops[:-1]
-        for op in ops:
-            newpos = trace.record_op(op.getopnum(), [get(arg) for arg in 
-                op.getarglist()], op.getdescr())
-            if rop.is_guard(op.getopnum()):
-                failargs = []
-                if op.getfailargs():
-                    failargs = [get(arg) for arg in op.getfailargs()]
-                frame = FakeFrame(100, jitcode, failargs)
-                resume.capture_resumedata([frame], None, [], trace)
-            if op.type != 'v':
-                newop = self.pick_cls(op)(newpos)
-                mapping[op] = newop
-        return trace
-
     def unroll_and_optimize(self, loop, call_pure_results=None,
                             jump_values=None):
         self.add_guard_future_condition(loop)
@@ -601,7 +557,7 @@
         #                           descr=jump_op.getdescr())
         #end_label = jump_op.copy_and_change(opnum=rop.LABEL)
         call_pure_results = self._convert_call_pure_results(call_pure_results)
-        t = self.convert_loop_to_packed(loop)
+        t = convert_loop_to_trace(loop)
         preamble_data = compile.LoopCompileData(t, runtime_boxes,
                                                 call_pure_results)
         start_state, preamble_ops = self._do_optimize_loop(preamble_data)
diff --git a/rpython/jit/metainterp/test/test_compile.py 
b/rpython/jit/metainterp/test/test_compile.py
--- a/rpython/jit/metainterp/test/test_compile.py
+++ b/rpython/jit/metainterp/test/test_compile.py
@@ -6,7 +6,7 @@
 from rpython.jit.metainterp import jitexc
 from rpython.jit.metainterp import jitprof, typesystem, compile
 from rpython.jit.metainterp.optimizeopt.test.test_util import LLtypeMixin
-from rpython.jit.tool.oparser import parse
+from rpython.jit.tool.oparser import parse, convert_loop_to_trace
 from rpython.jit.metainterp.optimizeopt import ALL_OPTS_DICT
 
 class FakeCPU(object):
@@ -94,15 +94,14 @@
     metainterp.staticdata = staticdata
     metainterp.cpu = cpu
     metainterp.history = History()
-    metainterp.history.set_inputargs(loop.inputargs[:])
-    for op in loop.operations:
-        newop = metainterp.history.record_nospec(op.getopnum(), 
op.getarglist(), op.getdescr())
-        op.position = newop.position
+    t = convert_loop_to_trace(loop)
+    metainterp.history.inputargs = t.inputargs
+    metainterp.history.trace = t
     #
     greenkey = 'faked'
     target_token = compile_loop(metainterp, greenkey, (0, 0),
-                                loop.inputargs,
-                                loop.operations[-1].getarglist(),
+                                t.inputargs,
+                                [t._mapping[x] for x in 
loop.operations[-1].getarglist()],
                                 None)
     jitcell_token = target_token.targeting_jitcell_token
     assert jitcell_token == target_token.original_jitcell_token
diff --git a/rpython/jit/tool/oparser.py b/rpython/jit/tool/oparser.py
--- a/rpython/jit/tool/oparser.py
+++ b/rpython/jit/tool/oparser.py
@@ -413,6 +413,54 @@
     return OpParser(input, cpu, namespace, boxkinds,
                     invent_fail_descr, nonstrict, postprocess).parse()
 
+def pick_cls(inp):
+    from rpython.jit.metainterp import history
+
+    if inp.type == 'i':
+        return history.IntFrontendOp
+    elif inp.type == 'r':
+        return history.RefFrontendOp
+    else:
+        assert inp.type == 'f'
+        return history.FloatFrontendOp
+
+def convert_loop_to_trace(loop, skip_last=False):
+    from rpython.jit.metainterp.opencoder import Trace
+    from rpython.jit.metainterp.test.test_opencoder import FakeFrame
+    from rpython.jit.metainterp import history, resume
+
+    def get(a):
+        if isinstance(a, history.Const):
+            return a
+        return mapping[a]
+
+    class jitcode:
+        index = 200
+
+    inputargs = [pick_cls(inparg)(i) for i, inparg in
+                 enumerate(loop.inputargs)]
+    mapping = {}
+    for one, two in zip(loop.inputargs, inputargs):
+        mapping[one] = two
+    trace = Trace(inputargs)
+    ops = loop.operations
+    if skip_last:
+        ops = ops[:-1]
+    for op in ops:
+        newpos = trace.record_op(op.getopnum(), [get(arg) for arg in 
+            op.getarglist()], op.getdescr())
+        if rop.is_guard(op.getopnum()):
+            failargs = []
+            if op.getfailargs():
+                failargs = [get(arg) for arg in op.getfailargs()]
+            frame = FakeFrame(100, jitcode, failargs)
+            resume.capture_resumedata([frame], None, [], trace)
+        if op.type != 'v':
+            newop = pick_cls(op)(newpos)
+            mapping[op] = newop
+    trace._mapping = mapping # for tests
+    return trace
+
 def pure_parse(*args, **kwds):
     kwds['invent_fail_descr'] = None
     return parse(*args, **kwds)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to