[pypy-commit] pypy better-jit-hooks: finish refactoring - move on_compile/on_compile hooks to jitportal, probably

fijal noreply at buildbot.pypy.org
Thu Jan 5 21:50:53 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: better-jit-hooks
Changeset: r51044:74cc4b1b667e
Date: 2012-01-05 22:50 +0200
http://bitbucket.org/pypy/pypy/changeset/74cc4b1b667e/

Log:	finish refactoring - move on_compile/on_compile hooks to jitportal,
	probably breaks pypy

diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -141,6 +141,7 @@
         self._compile_loop_or_bridge(c, inputargs, operations, clt)
         old, oldindex = faildescr._compiled_fail
         llimpl.compile_redirect_fail(old, oldindex, c)
+        return None, 0, 0
 
     def compile_loop(self, inputargs, operations, jitcell_token,
                      log=True, name=''):
@@ -155,6 +156,7 @@
         clt.compiled_version = c
         jitcell_token.compiled_loop_token = clt
         self._compile_loop_or_bridge(c, inputargs, operations, clt)
+        return None, 0, 0
 
     def free_loop_and_bridges(self, compiled_loop_token):
         for c in compiled_loop_token.loop_and_bridges:
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
@@ -296,8 +296,7 @@
         patch_new_loop_to_load_virtualizable_fields(loop, jitdriver_sd)
 
     original_jitcell_token = loop.original_jitcell_token
-    jitdriver_sd.on_compile(metainterp_sd.logger_ops, original_jitcell_token,
-                            loop.operations, type, greenkey)
+    portal = metainterp_sd.warmrunnerdesc.portal
     loopname = jitdriver_sd.warmstate.get_location_str(greenkey)
     globaldata = metainterp_sd.globaldata
     original_jitcell_token.number = n = globaldata.loopnumbering
@@ -311,11 +310,16 @@
     metainterp_sd.profiler.start_backend()
     debug_start("jit-backend")
     try:
-        ops_offset = metainterp_sd.cpu.compile_loop(loop.inputargs, operations,
-                                                    original_jitcell_token, name=loopname)
+        tp = metainterp_sd.cpu.compile_loop(loop.inputargs, operations,
+                                            original_jitcell_token,
+                                            name=loopname)
+        ops_offset, asmstart, asmlen = tp
     finally:
         debug_stop("jit-backend")
-    metainterp_sd.profiler.end_backend()
+    metainterp_sd.profiler.end_backend() 
+    portal.on_compile(jitdriver_sd.jitdriver, metainterp_sd.logger_ops,
+                      original_jitcell_token, loop.operations, type, greenkey,
+                      asmstart, asmlen)
     metainterp_sd.stats.add_new_loop(loop)
     if not we_are_translated():
         metainterp_sd.stats.compiled()
@@ -332,8 +336,7 @@
 def send_bridge_to_backend(jitdriver_sd, metainterp_sd, faildescr, inputargs,
                            operations, original_loop_token):
     n = metainterp_sd.cpu.get_fail_descr_number(faildescr)
-    jitdriver_sd.on_compile_bridge(metainterp_sd.logger_ops,
-                                   original_loop_token, operations, n)
+    portal = metainterp_sd.warmrunnerdesc.portal
     if not we_are_translated():
         show_procedures(metainterp_sd)
         seen = dict.fromkeys(inputargs)
@@ -342,11 +345,15 @@
     operations = get_deep_immutable_oplist(operations)
     debug_start("jit-backend")
     try:
-        ops_offset = metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations,
-                                                      original_loop_token)
+        tp = metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations,
+                                              original_loop_token)
+        ops_offset, asmstart, asmlen = tp
     finally:
         debug_stop("jit-backend")
     metainterp_sd.profiler.end_backend()
+    portal.on_compile_bridge(jitdriver_sd.jitdriver, metainterp_sd.logger_ops,
+                             original_loop_token, operations, n, asmstart,
+                             asmlen)
     if not we_are_translated():
         metainterp_sd.stats.compiled()
     metainterp_sd.log("compiled new bridge")
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -117,7 +117,7 @@
 
     def optimize_loop(self, ops, optops, call_pure_results=None):
         loop = self.parse(ops)
-        token = JitCellToken() 
+        token = JitCellToken()
         loop.operations = [ResOperation(rop.LABEL, loop.inputargs, None, descr=TargetToken(token))] + \
                           loop.operations
         if loop.operations[-1].getopnum() == rop.JUMP:
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
@@ -56,8 +56,6 @@
         greenfield_info = None
         result_type = result_kind
         portal_runner_ptr = "???"
-        on_compile = lambda *args: None
-        on_compile_bridge = lambda *args: None
 
     stats = history.Stats()
     cpu = CPUClass(rtyper, stats, None, False)
diff --git a/pypy/jit/metainterp/test/test_compile.py b/pypy/jit/metainterp/test/test_compile.py
--- a/pypy/jit/metainterp/test/test_compile.py
+++ b/pypy/jit/metainterp/test/test_compile.py
@@ -53,8 +53,6 @@
     call_pure_results = {}
     class jitdriver_sd:
         warmstate = FakeState()
-        on_compile = staticmethod(lambda *args: None)
-        on_compile_bridge = staticmethod(lambda *args: None)
         virtualizable_info = None
 
 def test_compile_loop():
diff --git a/pypy/jit/metainterp/test/test_jitdriver.py b/pypy/jit/metainterp/test/test_jitdriver.py
--- a/pypy/jit/metainterp/test/test_jitdriver.py
+++ b/pypy/jit/metainterp/test/test_jitdriver.py
@@ -10,57 +10,6 @@
 def getloc2(g):
     return "in jitdriver2, with g=%d" % g
 
-class JitDriverTests(object):
-    def test_on_compile(self):
-        called = {}
-        
-        class MyJitDriver(JitDriver):
-            def on_compile(self, logger, looptoken, operations, type, n, m):
-                called[(m, n, type)] = looptoken
-
-        driver = MyJitDriver(greens = ['n', 'm'], reds = ['i'])
-
-        def loop(n, m):
-            i = 0
-            while i < n + m:
-                driver.can_enter_jit(n=n, m=m, i=i)
-                driver.jit_merge_point(n=n, m=m, i=i)
-                i += 1
-
-        self.meta_interp(loop, [1, 4])
-        assert sorted(called.keys()) == [(4, 1, "loop")]
-        self.meta_interp(loop, [2, 4])
-        assert sorted(called.keys()) == [(4, 1, "loop"),
-                                         (4, 2, "loop")]
-
-    def test_on_compile_bridge(self):
-        called = {}
-        
-        class MyJitDriver(JitDriver):
-            def on_compile(self, logger, looptoken, operations, type, n, m):
-                called[(m, n, type)] = loop
-            def on_compile_bridge(self, logger, orig_token, operations, n):
-                assert 'bridge' not in called
-                called['bridge'] = orig_token
-
-        driver = MyJitDriver(greens = ['n', 'm'], reds = ['i'])
-
-        def loop(n, m):
-            i = 0
-            while i < n + m:
-                driver.can_enter_jit(n=n, m=m, i=i)
-                driver.jit_merge_point(n=n, m=m, i=i)
-                if i >= 4:
-                    i += 2
-                i += 1
-
-        self.meta_interp(loop, [1, 10])
-        assert sorted(called.keys()) == ['bridge', (10, 1, "loop")]
-
-
-class TestLLtypeSingle(JitDriverTests, LLJitMixin):
-    pass
-
 class MultipleJitDriversTests(object):
 
     def test_simple(self):
diff --git a/pypy/jit/metainterp/test/test_jitportal.py b/pypy/jit/metainterp/test/test_jitportal.py
--- a/pypy/jit/metainterp/test/test_jitportal.py
+++ b/pypy/jit/metainterp/test/test_jitportal.py
@@ -37,3 +37,60 @@
         res = self.meta_interp(f, [100, 7], policy=JitPolicy(portal))
         assert res == 721
         assert reasons == [ABORT_FORCE_QUASIIMMUT] * 2
+
+    def test_on_compile(self):
+        called = {}
+        
+        class MyJitPortal(JitPortal):
+            def on_compile(self, jitdriver, logger, looptoken, operations,
+                           type, greenkey, asmaddr, asmlen):
+                assert asmaddr == 0
+                assert asmlen == 0
+                called[(greenkey[1].getint(), greenkey[0].getint(), type)] = looptoken
+
+        portal = MyJitPortal()
+
+        driver = JitDriver(greens = ['n', 'm'], reds = ['i'])
+
+        def loop(n, m):
+            i = 0
+            while i < n + m:
+                driver.can_enter_jit(n=n, m=m, i=i)
+                driver.jit_merge_point(n=n, m=m, i=i)
+                i += 1
+
+        self.meta_interp(loop, [1, 4], policy=JitPolicy(portal))
+        assert sorted(called.keys()) == [(4, 1, "loop")]
+        self.meta_interp(loop, [2, 4], policy=JitPolicy(portal))
+        assert sorted(called.keys()) == [(4, 1, "loop"),
+                                         (4, 2, "loop")]
+
+    def test_on_compile_bridge(self):
+        called = {}
+        
+        class MyJitPortal(JitPortal):
+            def on_compile(self, jitdriver, logger, looptoken, operations,
+                           type, greenkey, asmaddr, asmlen):
+                assert asmaddr == 0
+                assert asmlen == 0
+                called[(greenkey[1].getint(), greenkey[0].getint(), type)] = looptoken
+
+            def on_compile_bridge(self, jitdriver, logger, orig_token,
+                                  operations, n, asmstart, asmlen):
+                assert 'bridge' not in called
+                called['bridge'] = orig_token
+
+        driver = JitDriver(greens = ['n', 'm'], reds = ['i'])
+
+        def loop(n, m):
+            i = 0
+            while i < n + m:
+                driver.can_enter_jit(n=n, m=m, i=i)
+                driver.jit_merge_point(n=n, m=m, i=i)
+                if i >= 4:
+                    i += 2
+                i += 1
+
+        self.meta_interp(loop, [1, 10], policy=JitPolicy(MyJitPortal()))
+        assert sorted(called.keys()) == ['bridge', (10, 1, "loop")]
+
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -741,8 +741,8 @@
         greenkey where it started, reason is a string why it got aborted
         """
 
-    def on_compile(self, jitdriver, logger, looptoken, operations, greenkey,
-                   asmaddr, asmlen):
+    def on_compile(self, jitdriver, logger, looptoken, operations, type,
+                   greenkey, asmaddr, asmlen):
         """ A hook called when loop is compiled. Overwrite
         for your own jitdriver if you want to do something special, like
         call applevel code.
@@ -751,6 +751,7 @@
         logger - an instance of jit.metainterp.logger.LogOperations
         asmaddr - (int) raw address of assembler block
         asmlen - assembler block length
+        type - either 'loop' or 'entry bridge'
         """
 
     def on_compile_bridge(self, jitdriver, logger, orig_looptoken, operations,


More information about the pypy-commit mailing list