[pypy-commit] pypy jit-targets: move the decition wheter to unroll or not back into optimizeopt

hakanardo noreply at buildbot.pypy.org
Sat Nov 5 10:02:29 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-targets
Changeset: r48770:0aa80cc1b315
Date: 2011-11-05 08:44 +0100
http://bitbucket.org/pypy/pypy/changeset/0aa80cc1b315/

Log:	move the decition wheter to unroll or not back into optimizeopt

diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -766,7 +766,8 @@
         self.compiled_loop_token.cpu.dump_loop_token(self)
 
 class TargetToken(AbstractDescr):
-    def __init__(self):
+    def __init__(self, merge_point):
+        self.merge_point = merge_point
         self.exported_state = None
         
 class TreeLoop(object):
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
@@ -557,7 +557,6 @@
 
     def store_final_boxes_in_guard(self, op):
         descr = op.getdescr()
-        print 'HHHHHHHHHHHH', descr, id(descr)
         assert isinstance(descr, compile.ResumeGuardDescr)
         modifier = resume.ResumeDataVirtualAdder(descr, self.resumedata_memo)
         newboxes = modifier.finish(self.values, self.pendingfields)
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -80,28 +80,33 @@
         if expected_short:
             expected_short = self.parse(expected_short)
         operations =  loop.operations
+        jumpop = operations[-1]
+        assert jumpop.getopnum() == rop.JUMP
+        inputargs = loop.inputargs
+        loop.inputargs = None
+
+        jump_args = jumpop.getarglist()[:]
+        operations = operations[:-1]
         cloned_operations = [op.clone() for op in operations]
         
         preamble = TreeLoop('preamble')
         #loop.preamble.inputargs = loop.inputargs
         #loop.preamble.token = LoopToken()
         preamble.start_resumedescr = FakeDescr()
-        assert operations[-1].getopnum() == rop.JUMP
-        inputargs = loop.inputargs
-        jump_args = operations[-1].getarglist()
-        targettoken = TargetToken()
-        operations[-1].setdescr(targettoken)
-        cloned_operations[-1].setdescr(targettoken)
-        preamble.operations = [ResOperation(rop.TARGET, inputargs, None, descr=TargetToken())] + \
-                              operations[:-1] +  \
-                              [ResOperation(rop.TARGET, jump_args, None, descr=targettoken)] 
+
+        token = LoopToken() # FIXME: Make this a MergePointToken?
+        preamble.operations = [ResOperation(rop.TARGET, inputargs, None, descr=TargetToken(token))] + \
+                              operations +  \
+                              [ResOperation(rop.TARGET, jump_args, None, descr=TargetToken(token))]
         self._do_optimize_loop(preamble, call_pure_results)
 
         inliner = Inliner(inputargs, jump_args)
-        loop.inputargs = None
         loop.start_resumedescr = preamble.start_resumedescr
         loop.operations = [preamble.operations[-1]] + \
-                          [inliner.inline_op(op, clone=False) for op in cloned_operations]
+                          [inliner.inline_op(op, clone=False) for op in cloned_operations] + \
+                          [ResOperation(rop.TARGET, [inliner.inline_arg(a) for a in jump_args],
+                                        None, descr=TargetToken(token))] 
+                          #[inliner.inline_op(jumpop)]
 
         self._do_optimize_loop(loop, call_pure_results)
         extra_same_as = []
diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -126,30 +126,34 @@
         self.import_state(start_targetop)
         
         lastop = loop.operations[-1]
-        if lastop.getopnum() == rop.TARGET or lastop.getopnum() == rop.JUMP:
-            loop.operations = loop.operations[:-1]
+        assert lastop.getopnum() == rop.TARGET
+        loop.operations = loop.operations[:-1]
+        #if lastop.getopnum() == rop.TARGET or lastop.getopnum() == rop.JUMP:
+        #    loop.operations = loop.operations[:-1]
         #FIXME: FINISH
         
         self.optimizer.propagate_all_forward(clear=False)
         
-        if lastop.getopnum() == rop.TARGET:
+        #if lastop.getopnum() == rop.TARGET:
+        if not self.did_peel_one: # Enforce the previous behaviour of always peeling  exactly one iteration (for now)
             self.optimizer.flush()
             KillHugeIntBounds(self.optimizer).apply()
 
             loop.operations = self.optimizer.get_newoperations()
             self.export_state(lastop)
             loop.operations.append(lastop)
-        elif lastop.getopnum() == rop.JUMP:
-            assert lastop.getdescr() is start_targetop.getdescr()
-            self.close_loop(lastop)
+        else:
+            assert lastop.getdescr().merge_point is start_targetop.getdescr().merge_point
+            jumpop = ResOperation(rop.JUMP, lastop.getarglist(), None, descr=start_targetop.getdescr())
+            self.close_loop(jumpop)
             short_preamble_loop = self.produce_short_preamble(lastop)
             assert isinstance(loop.token, LoopToken)
             if loop.token.short_preamble:
                 loop.token.short_preamble.append(short_preamble_loop) # FIXME: ??
             else:
                 loop.token.short_preamble = [short_preamble_loop]
-        else:
-            loop.operations = self.optimizer.get_newoperations()
+        #else:
+        #    loop.operations = self.optimizer.get_newoperations()
 
     def export_state(self, targetop):
         original_jump_args = targetop.getarglist()
@@ -197,9 +201,11 @@
         assert isinstance(target_token, TargetToken)
         exported_state = target_token.exported_state
         if not exported_state:
+            self.did_peel_one = False
             # FIXME: Set up some sort of empty state with no virtuals
             return
-
+        self.did_peel_one = True
+        
         self.short = []
         self.short_seen = {}
         self.short_boxes = exported_state.short_boxes
@@ -245,8 +251,7 @@
         self.optimizer.flush()
         self.optimizer.emitting_dissabled = False
 
-    def close_loop(self, jumpop):
-        assert jumpop
+    def close_loop(self, jumpop):        
         virtual_state = self.imported_state.virtual_state
         short_inputargs = self.imported_state.short_inputargs
         constant_inputargs = self.imported_state.constant_inputargs


More information about the pypy-commit mailing list