Commits

Hakan Ardo committed ad56d1e

invariants now removed from bridges

  • Participants
  • Parent commits a8b5a0a
  • Branches jit-fromstart

Comments (0)

Files changed (7)

pypy/jit/metainterp/compile.py

             }
 
 class ResumeDescr(AbstractFailDescr):
-    pass
+    def inline_short_preamble(self):
+        return True
 
 class ResumeGuardDescr(ResumeDescr):
     _counter = 0        # if < 0, there is one counter per value;
         return res
 
 class ResumeAtPositionDescr(ResumeGuardDescr):
+    def inline_short_preamble(self):
+        return False
+
     def _clone_if_mutable(self):
         res = ResumeAtPositionDescr()
         self.copy_all_attrbutes_into(res)
     new_loop.operations = [op.clone() for op in metainterp.history.operations]
     metainterp_sd = metainterp.staticdata
     state = metainterp.jitdriver_sd.warmstate
-    if isinstance(resumekey, ResumeAtPositionDescr):
-        inline_short_preamble = False
-    else:
-        inline_short_preamble = True
     try:
         target_loop_token = state.optimize_bridge(metainterp_sd,
                                                   old_loop_tokens,
-                                                  new_loop, inline_short_preamble)
+                                                  new_loop, resumekey)
     except InvalidLoop:
         # XXX I am fairly convinced that optimize_bridge cannot actually raise
         # InvalidLoop

pypy/jit/metainterp/optimize.py

 
 # ____________________________________________________________
 
-def optimize_bridge(metainterp_sd, old_loop_tokens, bridge, inline_short_preamble=True):
+def optimize_bridge(metainterp_sd, old_loop_tokens, bridge, resumekey):
     debug_start("jit-optimize")
     try:
-        return _optimize_bridge(metainterp_sd, old_loop_tokens, bridge, inline_short_preamble)
+        return _optimize_bridge(metainterp_sd, old_loop_tokens, bridge, resumekey)
     finally:
         debug_stop("jit-optimize")
 
-def _optimize_bridge(metainterp_sd, old_loop_tokens, bridge, inline_short_preamble):
+def _optimize_bridge(metainterp_sd, old_loop_tokens, bridge, resumekey):
     cpu = metainterp_sd.cpu
     metainterp_sd.logger_noopt.log_loop(bridge.inputargs, bridge.operations)
     if old_loop_tokens:
         old_loop_token = old_loop_tokens[0]
         bridge.operations[-1].setdescr(old_loop_token)   # patch jump target
-        optimize_bridge_1(metainterp_sd, bridge, inline_short_preamble)
+        optimize_bridge_1(metainterp_sd, bridge, resumekey)
         return old_loop_tokens[0]
         #return bridge.operations[-1].getdescr()
     return None

pypy/jit/metainterp/optimizeopt/__init__.py

 from pypy.jit.metainterp.optimizeopt.string import OptString
 from pypy.jit.metainterp.optimizeopt.unroll import optimize_unroll, OptInlineShortPreamble
 
-def optimize_loop_1(metainterp_sd, loop, unroll=True, inline_short_preamble=True):
+def optimize_loop_1(metainterp_sd, loop, unroll=True, resumekey=None):
     """Optimize loop.operations to remove internal overheadish operations. 
     """
+    if resumekey:
+        inline_short_preamble =  resumekey.inline_short_preamble()
+    else:
+        inline_short_preamble = True
+    
     opt_str = OptString()
     optimizations = [OptIntBounds(),
                      OptRewrite(),
         optimize_unroll(metainterp_sd, loop, optimizations)
     else:
         optimizer = Optimizer(metainterp_sd, loop, optimizations)
+        if resumekey:
+            optimizer.initialize_state_from_guard_failure(resumekey)
         optimizer.propagate_all_forward()
 
-def optimize_bridge_1(metainterp_sd, bridge, inline_short_preamble=True):
+def optimize_bridge_1(metainterp_sd, bridge, resumekey=None):
     """The same, but for a bridge. """
-    optimize_loop_1(metainterp_sd, bridge, False, inline_short_preamble)
+    optimize_loop_1(metainterp_sd, bridge, False, resumekey)

pypy/jit/metainterp/optimizeopt/optimizer.py

         self.posponedop = None
         self.exception_might_have_happened = False
         self.newoperations = []
-        self.inputargs = []
+        self.extraargs = []
 
         self.set_optimizations(optimizations)
 
             
         self.optimizations  = optimizations 
 
+    def initialize_state_from_guard_failure(self, resumedescr):
+        if resumedescr.parent_short_preamble:
+            myboxes = []
+            preamble_boxes = []
+            jumpop = resumedescr.parent_short_preamble.operations[-1]
+            jumpargs = jumpop.getarglist()
+            for i in range(len(self.loop.inputargs)):
+                box = self.loop.inputargs[i]
+                idx = resumedescr.start_indexes[i]
+                if idx > -1:
+                    myboxes.append(box)
+                    preamble_boxes.append(jumpargs[idx])
+            from pypy.jit.metainterp.optimizeopt.unroll import Inliner
+            inliner = Inliner(preamble_boxes, myboxes)
+            print
+            print
+            for op in resumedescr.parent_short_preamble.operations[:-1]:
+                newop = inliner.inline_op(op, inline_result=True)
+                print newop
+                self.first_optimization.propagate_forward(newop)
+                # FIMXE: only ops with boxes in myboxes
+        
     def force_at_end_of_preamble(self):
         self.resumedata_memo = resume.ResumeDataLoopMemo(self.metainterp_sd)
         for o in self.optimizations:
         descr = op.getdescr()
         assert isinstance(descr, compile.ResumeGuardDescr)
         modifier = resume.ResumeDataVirtualAdder(descr, self.resumedata_memo)
-        newboxes = modifier.finish(self.values, self.pendingfields, self.inputargs)
+        newboxes = modifier.finish(self.values, self.pendingfields, self.extraargs)
         # FIXME: Do we realy want to append all inputargs?
         if len(newboxes) > self.metainterp_sd.options.failargs_limit: # XXX be careful here
             compile.giveup()

pypy/jit/metainterp/optimizeopt/unroll.py

         self.snapshot_map = {None: None}
 
     def inline_op(self, newop, ignore_result=False, clone=True,
-                  ignore_failargs=False):
+                  ignore_failargs=False, inline_result=False):
         if clone:
             newop = newop.clone()
         args = newop.getarglist()
 
         if newop.result and not ignore_result:
             old_result = newop.result
-            newop.result = newop.result.clonebox()
+            if inline_result:
+                newop.result = self.inline_arg(old_result)
+            else:
+                newop.result = newop.result.clonebox()
             self.argmap[old_result] = newop.result
 
         descr = newop.getdescr()
         for v in self.optimizer.values.values():
             v.last_guard_index = -1 # FIXME: Are there any more indexes stored?
 
-        self.optimizer.inputargs = inputargs = []
+        self.optimizer.extraargs = inputargs = []
         seen_inputargs = {}
         for arg in jump_args:
             boxes = []

pypy/jit/metainterp/pyjitpl.py

         self.virtualref_boxes = []
         self.initialize_withgreenfields(original_boxes)
         self.initialize_virtualizable(original_boxes)
-
+        
     def initialize_state_from_guard_failure(self, resumedescr):
         # guard failure: rebuild a complete MIFrame stack
         self.in_recursion = -1 # always one portal around

pypy/jit/metainterp/test/test_basic.py

         self.check_loops({'int_add': 2, 'int_lt': 1,
                           'int_sub': 2, 'guard_false': 1,
                           'jump': 2,
-                          'int_gt': 1, 'guard_true': 1, 'int_mul': 1})
+                          'int_gt': 1, 'guard_true': 1})
 
 
     def test_loop_invariant_mul_bridge_maintaining2(self):