[pypy-commit] pypy better-jit-hooks: add extra return values from assemble_loop/assemble_bridge

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


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: better-jit-hooks
Changeset: r51043:62b1ef8e5cd7
Date: 2012-01-05 22:41 +0200
http://bitbucket.org/pypy/pypy/changeset/62b1ef8e5cd7/

Log:	add extra return values from assemble_loop/assemble_bridge

diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -17,6 +17,7 @@
 from pypy.rpython.llinterp import LLException
 from pypy.jit.codewriter import heaptracker, longlong
 from pypy.rlib.rarithmetic import intmask
+from pypy.jit.backend.detect_cpu import autodetect_main_model_and_size
 
 def boxfloat(x):
     return BoxFloat(longlong.getfloatstorage(x))
@@ -2974,6 +2975,53 @@
         res = self.cpu.get_latest_value_int(0)
         assert res == -10
 
+    def test_compile_asmlen(self):
+        from pypy.jit.backend.x86.tool.viewcode import machine_code_dump
+        import ctypes
+        ops = """
+        [i0]
+        label(i0, descr=1)
+        i1 = int_add(i0, i0)
+        guard_true(i1, descr=faildesr) [i1]
+        jump(i1, descr=1)
+        """
+        faildescr = BasicFailDescr(2)
+        loop = parse(ops, self.cpu, namespace=locals())
+        faildescr = loop.operations[-2].getdescr()
+        jumpdescr = loop.operations[-1].getdescr()
+        bridge_ops = """
+        [i0]
+        jump(i0, descr=jumpdescr)
+        """
+        bridge = parse(bridge_ops, self.cpu, namespace=locals())
+        looptoken = JitCellToken()
+        self.cpu.assembler.set_debug(False)
+        _, asm, asmlen = self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+        _, basm, basmlen = self.cpu.compile_bridge(faildescr, bridge.inputargs,
+                                                   bridge.operations,
+                                                   looptoken)
+        self.cpu.assembler.set_debug(True) # always on untranslated
+        assert asmlen != 0
+        cpuname = autodetect_main_model_and_size()
+        if 'x86' in cpuname:
+            # XXX we have to check the precise assembler, otherwise
+            # we don't quite know if borders are correct
+            def checkops(mc, startline, ops):
+                for i in range(startline, len(mc)):
+                    assert mc[i].split("\t")[-1].startswith(ops[i - startline])
+            
+            data = ctypes.string_at(asm, asmlen)
+            mc = list(machine_code_dump(data, asm, cpuname))
+            assert len(mc) == 5
+            checkops(mc, 1, ['add', 'test', 'je', 'jmp'])
+            data = ctypes.string_at(basm, basmlen)
+            mc = list(machine_code_dump(data, basm, cpuname))
+            assert len(mc) == 4
+            checkops(mc, 1, ['lea', 'mov', 'jmp'])
+        else:
+            raise Exception("Implement this test for your CPU")
+
+
     def test_compile_bridge_with_target(self):
         # This test creates a loopy piece of code in a bridge, and builds another
         # unrelated loop that ends in a jump directly to this loopy bit of code.
diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -411,6 +411,7 @@
         '''adds the following attributes to looptoken:
                _x86_function_addr   (address of the generated func, as an int)
                _x86_loop_code       (debug: addr of the start of the ResOps)
+               _x86_fullsize        (debug: full size including failure)
                _x86_debug_checksum
         '''
         # XXX this function is too longish and contains some code
@@ -476,7 +477,8 @@
             name = "Loop # %s: %s" % (looptoken.number, loopname)
             self.cpu.profile_agent.native_code_written(name,
                                                        rawstart, full_size)
-        return ops_offset
+        return (ops_offset, rawstart + looppos,
+                size_excluding_failure_stuff - looppos)
 
     def assemble_bridge(self, faildescr, inputargs, operations,
                         original_loop_token, log):
@@ -503,6 +505,7 @@
                     [loc.assembler() for loc in faildescr._x86_debug_faillocs])
         regalloc = RegAlloc(self, self.cpu.translate_support_code)
         fail_depths = faildescr._x86_current_depths
+        startpos = self.mc.get_relative_pos()
         operations = regalloc.prepare_bridge(fail_depths, inputargs, arglocs,
                                              operations,
                                              self.current_clt.allgcrefs)
@@ -537,7 +540,7 @@
             name = "Bridge # %s" % (descr_number,)
             self.cpu.profile_agent.native_code_written(name,
                                                        rawstart, fullsize)
-        return ops_offset
+        return ops_offset, startpos + rawstart, codeendpos - startpos
 
     def write_pending_failure_recoveries(self):
         # for each pending guard, generate the code of the recovery stub
diff --git a/pypy/jit/backend/x86/test/test_runner.py b/pypy/jit/backend/x86/test/test_runner.py
--- a/pypy/jit/backend/x86/test/test_runner.py
+++ b/pypy/jit/backend/x86/test/test_runner.py
@@ -416,7 +416,7 @@
             ]
         inputargs = [i0]
         debug._log = dlog = debug.DebugLog()
-        ops_offset = self.cpu.compile_loop(inputargs, operations, looptoken)
+        ops_offset = self.cpu.compile_loop(inputargs, operations, looptoken)[0]
         debug._log = None
         #
         assert ops_offset is looptoken._x86_ops_offset


More information about the pypy-commit mailing list