[pypy-commit] pypy jit-usable_retrace_2: Generalize a bit harder by killing intbounds and constants at end of bridges forcing retracing.

hakanardo noreply at buildbot.pypy.org
Tue Jan 3 12:16:05 CET 2012


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-usable_retrace_2
Changeset: r50984:96d5bc2c492d
Date: 2012-01-03 11:33 +0100
http://bitbucket.org/pypy/pypy/changeset/96d5bc2c492d/

Log:	Generalize a bit harder by killing intbounds and constants at end of
	bridges forcing retracing.

diff --git a/pypy/jit/metainterp/optimizeopt/generalize.py b/pypy/jit/metainterp/optimizeopt/generalize.py
--- a/pypy/jit/metainterp/optimizeopt/generalize.py
+++ b/pypy/jit/metainterp/optimizeopt/generalize.py
@@ -5,15 +5,20 @@
         self.optimizer = optimizer
 
     def apply(self):
-        raise NotImplementedError
+        for v in self.optimizer.values.values():
+            self._apply(v)
 
 class KillHugeIntBounds(GeneralizationStrategy):
-    def apply(self):
-        for v in self.optimizer.values.values():
-            if v.is_constant():
-                continue
+    def _apply(self, v):
+        if not v.is_constant():
             if v.intbound.lower < MININT/2:
                 v.intbound.lower = MININT
             if v.intbound.upper > MAXINT/2:
                 v.intbound.upper = MAXINT
           
+class KillIntBounds(GeneralizationStrategy):
+    def _apply(self, v):
+        if not v.is_constant():
+            v.intbound.lower = MININT
+            v.intbound.upper = MAXINT
+        
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
@@ -125,6 +125,12 @@
         return self.box
 
     def force_at_end_of_preamble(self, already_forced, optforce):
+        if optforce.optimizer.kill_consts_at_end_of_preamble and self.is_constant():
+            constbox = self.box
+            box = constbox.clonebox()
+            op = ResOperation(rop.SAME_AS, [constbox], box)
+            optforce.optimizer._newoperations.append(op)
+            return OptValue(box)
         return self
 
     def get_args_for_fail(self, modifier):
@@ -352,6 +358,7 @@
         self.optimizer = self
         self.optpure = None
         self.optearlyforce = None
+        self.kill_consts_at_end_of_preamble = False
         if loop is not None:
             self.call_pure_results = loop.call_pure_results
 
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
@@ -5,7 +5,7 @@
 from pypy.jit.metainterp.jitexc import JitException
 from pypy.jit.metainterp.optimize import InvalidLoop
 from pypy.jit.metainterp.optimizeopt.optimizer import *
-from pypy.jit.metainterp.optimizeopt.generalize import KillHugeIntBounds
+from pypy.jit.metainterp.optimizeopt.generalize import KillHugeIntBounds, KillIntBounds
 from pypy.jit.metainterp.inliner import Inliner
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.resume import Snapshot
@@ -137,12 +137,21 @@
             self.close_bridge(start_label)
 
         self.optimizer.flush()
-        KillHugeIntBounds(self.optimizer).apply()
 
+        self.generalize_state(start_label, stop_label)
         loop.operations = self.optimizer.get_newoperations()
         self.export_state(stop_label)
         loop.operations.append(stop_label)
 
+    def generalize_state(self, start_label, stop_label):
+        if self.jump_to_start_label(start_label, stop_label):
+            # At the end of the preamble, don't generalize much
+            KillHugeIntBounds(self.optimizer).apply()
+        else:
+            # At the end of a bridge about to force a retrcae
+            KillIntBounds(self.optimizer).apply()
+            self.optimizer.kill_consts_at_end_of_preamble = True
+
     def jump_to_start_label(self, start_label, stop_label):
         if not start_label or not stop_label:
             return False
@@ -170,14 +179,16 @@
         assert self.optimizer.loop.resume_at_jump_descr
         resume_at_jump_descr = self.optimizer.loop.resume_at_jump_descr.clone_if_mutable()
         assert isinstance(resume_at_jump_descr, ResumeGuardDescr)
-        resume_at_jump_descr.rd_snapshot = self.fix_snapshot(jump_args, resume_at_jump_descr.rd_snapshot)
+        resume_at_jump_descr.rd_snapshot = self.fix_snapshot(jump_args,
+                                                   resume_at_jump_descr.rd_snapshot)
 
         modifier = VirtualStateAdder(self.optimizer)
         virtual_state = modifier.get_virtual_state(jump_args)
             
         values = [self.getvalue(arg) for arg in jump_args]
         inputargs = virtual_state.make_inputargs(values, self.optimizer)
-        short_inputargs = virtual_state.make_inputargs(values, self.optimizer, keyboxes=True)
+        short_inputargs = virtual_state.make_inputargs(values, self.optimizer,
+                                                       keyboxes=True)
 
 
         if self.boxes_created_this_iteration is not None:
diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -172,7 +172,8 @@
 
     def check_target_token_count(self, count):
         tokens = get_stats().get_all_jitcell_tokens()
-        n = sum ([len(t.target_tokens) for t in tokens])
+        n = sum ([len(t.target_tokens) for t in tokens
+                  if t.target_tokens])
         assert n == count
 
     def check_enter_count(self, count):
diff --git a/pypy/jit/metainterp/test/test_virtual.py b/pypy/jit/metainterp/test/test_virtual.py
--- a/pypy/jit/metainterp/test/test_virtual.py
+++ b/pypy/jit/metainterp/test/test_virtual.py
@@ -902,7 +902,8 @@
         assert res == f(10)
         self.check_aborted_count(0)
         self.check_target_token_count(3)
-        self.check_resops(int_mul=2)
+        self.check_trace_count(3)
+        self.check_resops(int_mul=3)
 
     def test_nested_loops_bridge(self):
         class Int(object):


More information about the pypy-commit mailing list