[pypy-commit] pypy jit-targets: retraces ending with a virtual state matching a previously compiled trace

hakanardo noreply at buildbot.pypy.org
Mon Nov 7 16:49:44 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-targets
Changeset: r48869:8e75cc4b5fbc
Date: 2011-11-07 16:40 +0100
http://bitbucket.org/pypy/pypy/changeset/8e75cc4b5fbc/

Log:	retraces ending with a virtual state matching a previously compiled
	trace

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -83,7 +83,10 @@
             if descr.original_jitcell_token is not original_jitcell_token:
                 assert descr.original_jitcell_token is not None
                 original_jitcell_token.record_jump_to(descr.original_jitcell_token)
-            descr.exported_state = None
+            # exported_state is clear by optimizeopt when the short preamble is
+            # constrcucted. if that did not happen the label should not show up
+            # in a trace that will be used
+            assert descr.exported_state is None 
             op._descr = None    # clear reference, mostly for tests
     # record this looptoken on the QuasiImmut used in the code
     if loop.quasi_immutable_deps is not None:
@@ -203,7 +206,8 @@
     part = create_empty_loop(metainterp)
     part.inputargs = inputargs[:]
     part.start_resumedescr = start_resumedescr
-    h_ops = history.operations    
+    h_ops = history.operations
+
     part.operations = [partial_trace.operations[-1]] + \
                       [h_ops[i].clone() for i in range(start, len(h_ops))] + \
                       [ResOperation(rop.JUMP, jumpargs, None, descr=loop_jitcell_token)]
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
@@ -89,14 +89,18 @@
         if not jumpop:
             return 
         if self.jump_to_already_compiled_trace(jumpop):
+            # Found a compiled trace to jump to
+            if self.did_import:
+
+                self.close_bridge(start_label)
+                self.finilize_short_preamble(start_label)
             return
 
-        # Failed to find a compiled trace to jump to, produce a label instead
         cell_token = jumpop.getdescr()
         assert isinstance(cell_token, JitCellToken)
         stop_label = ResOperation(rop.LABEL, jumpop.getarglist(), None, TargetToken(cell_token))
-        
-        if not self.did_peel_one: # Enforce the previous behaviour of always peeling  exactly one iteration (for now)
+
+        if not self.did_import: # Enforce the previous behaviour of always peeling  exactly one iteration (for now)
             self.optimizer.flush()
             KillHugeIntBounds(self.optimizer).apply()
 
@@ -109,7 +113,6 @@
 
             self.close_loop(jumpop)
             self.finilize_short_preamble(start_label)
-            start_label.getdescr().short_preamble = self.short
 
     def export_state(self, targetop):
         original_jump_args = targetop.getarglist()
@@ -156,7 +159,7 @@
                                                     inputarg_setup_ops, self.optimizer)
 
     def import_state(self, targetop):
-        self.did_peel_one = False
+        self.did_import = False
         if not targetop:
             # FIXME: Set up some sort of empty state with no virtuals?
             return
@@ -168,7 +171,7 @@
         if not exported_state:
             # FIXME: Set up some sort of empty state with no virtuals
             return
-        self.did_peel_one = True
+        self.did_import = True
         
         self.short = target_token.short_preamble
         self.short_seen = {}
@@ -216,7 +219,28 @@
         self.optimizer.flush()
         self.optimizer.emitting_dissabled = False
 
-    def close_loop(self, jumpop):        
+    def close_bridge(self, start_label):
+        inputargs = self.inputargs        
+        short_jumpargs = inputargs[:]
+        
+        newoperations = self.optimizer.get_newoperations()
+        self.boxes_created_this_iteration = {}
+        i = 0
+        while newoperations[i].getopnum() != rop.LABEL:
+            i += 1
+        while i < len(newoperations):
+            op = newoperations[i]
+            self.boxes_created_this_iteration[op.result] = True
+            args = op.getarglist()
+            if op.is_guard():
+                args = args + op.getfailargs()
+            for a in args:
+                self.import_box(a, inputargs, short_jumpargs, [])
+            i += 1
+            newoperations = self.optimizer.get_newoperations()
+        self.short.append(ResOperation(rop.JUMP, short_jumpargs, None, descr=start_label.getdescr()))
+        
+    def close_loop(self, jumpop):
         virtual_state = self.initial_virtual_state
         short_inputargs = self.short[0].getarglist()
         constant_inputargs = self.imported_state.constant_inputargs
@@ -334,6 +358,9 @@
         for op in short:
             if op.result:
                 op.result.forget_value()
+        target_token.short_preamble = self.short
+        target_token.exported_state = None
+
         
     def FIXME_old_stuff():
             preamble_optimizer = self.optimizer


More information about the pypy-commit mailing list