[pypy-svn] r69400 - in pypy/branch/shorter-guard-path/pypy/jit: backend backend/cli backend/llgraph backend/llsupport backend/test backend/x86 backend/x86/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Wed Nov 18 22:28:38 CET 2009


Author: arigo
Date: Wed Nov 18 22:28:37 2009
New Revision: 69400

Added:
   pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_model.py   (contents, props changed)
Modified:
   pypy/branch/shorter-guard-path/pypy/jit/backend/cli/method.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/cli/runner.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/llgraph/runner.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/llsupport/llmodel.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/model.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/test/runner_test.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_ll_random.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_random.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/x86/assembler.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/x86/runner.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_recompilation.py
   pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_runner.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/compile.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/history.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/logger.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_compile.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_logger.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_pyjitpl.py
   pypy/branch/shorter-guard-path/pypy/jit/metainterp/warmstate.py
Log:
(pedronis, arigo)
Refactoring refactoring.  Cancel a previous refactoring that moved
the numbering of the guard descrs to the front-end.  Instead, move
that counting to AbstractCPU.


Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/cli/method.py	Wed Nov 18 22:28:37 2009
@@ -268,9 +268,6 @@
         try:
             return self.cpu.failing_ops.index(op)
         except ValueError:
-            descr = op.descr
-            assert isinstance(descr, history.AbstractFailDescr)            
-            descr.get_index()
             self.cpu.failing_ops.append(op)
             return len(self.cpu.failing_ops)-1
 

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/cli/runner.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/cli/runner.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/cli/runner.py	Wed Nov 18 22:28:37 2009
@@ -135,9 +135,7 @@
         func = cliloop.funcbox.holder.GetFunc()
         func(self.get_inputargs())
         op = self.failing_ops[self.inputargs.get_failed_op()]
-        descr = op.descr
-        assert isinstance(descr, AbstractFailDescr)
-        return descr.get_index()
+        return op.descr
         
     def set_future_value_int(self, index, intvalue):
         self.get_inputargs().set_int(index, intvalue)

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/llgraph/runner.py	Wed Nov 18 22:28:37 2009
@@ -88,6 +88,7 @@
 
     def __init__(self, rtyper, stats=None, translate_support_code=False,
                  annmixlevel=None, gcdescr=None):
+        model.AbstractCPU.__init__(self)
         self.rtyper = rtyper
         self.translate_support_code = translate_support_code
         self.stats = stats or MiniStats()
@@ -167,7 +168,7 @@
             if op.is_guard():
                 faildescr = op.descr
                 assert isinstance(faildescr, history.AbstractFailDescr)
-                fail_index = faildescr.get_index()
+                fail_index = self.get_fail_descr_number(faildescr)
                 index = llimpl.compile_add_fail(c, fail_index)
                 faildescr._compiled_fail = c, index
                 for box in op.fail_args:
@@ -192,8 +193,7 @@
             llimpl.compile_add_jump_target(c, compiled_version)
         elif op.opnum == rop.FINISH:
             faildescr = op.descr
-            assert isinstance(faildescr, history.AbstractFailDescr)
-            index = faildescr.get_index()
+            index = self.get_fail_descr_number(faildescr)
             llimpl.compile_add_fail(c, index)
         else:
             assert False, "unknown operation"
@@ -210,7 +210,7 @@
         fail_index = llimpl.frame_execute(frame)
         # we hit a FAIL operation.
         self.latest_frame = frame
-        return fail_index
+        return self.get_fail_descr_from_number(fail_index)
 
     def set_future_value_int(self, index, intvalue):
         llimpl.set_future_value_int(index, intvalue)

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/llsupport/llmodel.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/llsupport/llmodel.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/llsupport/llmodel.py	Wed Nov 18 22:28:37 2009
@@ -20,6 +20,7 @@
     def __init__(self, rtyper, stats, translate_support_code=False,
                  gcdescr=None):
         from pypy.jit.backend.llsupport.gc import get_ll_description
+        AbstractCPU.__init__(self)
         self.rtyper = rtyper
         self.stats = stats
         self.translate_support_code = translate_support_code

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/model.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/model.py	Wed Nov 18 22:28:37 2009
@@ -1,6 +1,25 @@
+from pypy.jit.metainterp import history
+
+
 class AbstractCPU(object):
     supports_floats = False
 
+    def __init__(self):
+        self.fail_descr_list = []
+
+    def get_fail_descr_number(self, descr):
+        assert isinstance(descr, history.AbstractFailDescr)
+        n = descr.index
+        if n < 0:
+            lst = self.fail_descr_list
+            n = len(lst)
+            lst.append(descr)
+            descr.index = n
+        return n
+
+    def get_fail_descr_from_number(self, n):
+        return self.fail_descr_list[n]
+
     def set_class_sizes(self, class_sizes):
         self.class_sizes = class_sizes
 

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/test/runner_test.py	Wed Nov 18 22:28:37 2009
@@ -39,7 +39,7 @@
             else:
                 raise NotImplementedError(box)
         res = self.cpu.execute_token(looptoken)
-        if res == operations[-1].descr.index:
+        if res is operations[-1].descr:
             self.guard_failed = False
         else:
             self.guard_failed = True
@@ -102,7 +102,7 @@
         fail = self.cpu.execute_token(looptoken)
         res = self.cpu.get_latest_value_int(0)
         assert res == 3        
-        assert fail == 1
+        assert fail.identifier == 1
 
     def test_compile_loop(self):
         i0 = BoxInt()
@@ -121,7 +121,7 @@
         self.cpu.compile_loop(inputargs, operations, looptoken)
         self.cpu.set_future_value_int(0, 2)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 2
+        assert fail.identifier == 2
         res = self.cpu.get_latest_value_int(0)
         assert res == 10
 
@@ -179,7 +179,7 @@
 
         self.cpu.set_future_value_int(0, 2)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 2
+        assert fail.identifier == 2
         res = self.cpu.get_latest_value_int(0)
         assert res == 20
 
@@ -188,8 +188,6 @@
         class UntouchableFailDescr(AbstractFailDescr):
             def __setattr__(self, name, value):
                 py.test.fail("finish descrs should not be touched")
-            def get_index(self):
-                return 7
         faildescr = UntouchableFailDescr() # to check that is not touched
         looptoken = LoopToken()
         operations = [
@@ -198,7 +196,7 @@
         self.cpu.compile_loop([i0], operations, looptoken)
         self.cpu.set_future_value_int(0, 99)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 7
+        assert fail is faildescr
         res = self.cpu.get_latest_value_int(0)
         assert res == 99
 
@@ -208,7 +206,7 @@
             ]
         self.cpu.compile_loop([], operations, looptoken)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 7
+        assert fail is faildescr
         res = self.cpu.get_latest_value_int(0)
         assert res == 42
 
@@ -218,7 +216,7 @@
             ]
         self.cpu.compile_loop([], operations, looptoken)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 7
+        assert fail is faildescr
 
     def test_execute_operations_in_env(self):
         cpu = self.cpu
@@ -302,9 +300,9 @@
                 self.cpu.set_future_value_int(1, y)
                 fail = self.cpu.execute_token(looptoken)
                 if (z == boom) ^ reversed:
-                    assert fail == 1
+                    assert fail.identifier == 1
                 else:
-                    assert fail == 2
+                    assert fail.identifier == 2
                 if z != boom:
                     assert self.cpu.get_latest_value_int(0) == z
                 assert not self.cpu.get_exception()
@@ -777,7 +775,7 @@
                     assert 0
             #
             fail = self.cpu.execute_token(looptoken)
-            assert fail == 15
+            assert fail.identifier == 15
             #
             dstvalues = values[:]
             for _ in range(11):
@@ -829,7 +827,7 @@
         for i in range(len(fboxes)):
             self.cpu.set_future_value_float(i, 13.5 + 6.73 * i)
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 2
+        assert fail.identifier == 2
         res = self.cpu.get_latest_value_float(0)
         assert res == 8.5
         for i in range(1, len(fboxes)):
@@ -880,7 +878,7 @@
                 assert 0
         #
         fail = self.cpu.execute_token(looptoken)
-        assert fail == 1
+        assert fail.identifier == 1
 
 
 class LLtypeBackendTest(BaseBackendTest):

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_ll_random.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_ll_random.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_ll_random.py	Wed Nov 18 22:28:37 2009
@@ -464,7 +464,7 @@
         descr = builder.cpu.calldescrof(TP, TP.ARGS, TP.RESULT)
         self.put(builder, args, descr)
         op = ResOperation(rop.GUARD_NO_EXCEPTION, [], None,
-                          descr=builder.make_fail_descr())
+                          descr=BasicFailDescr())
         op.fail_args = fail_subset
         builder.loop.operations.append(op)
 
@@ -486,7 +486,7 @@
         _, vtableptr = builder.get_random_structure_type_and_vtable(r)
         exc_box = ConstAddr(llmemory.cast_ptr_to_adr(vtableptr), builder.cpu)
         op = ResOperation(rop.GUARD_EXCEPTION, [exc_box], BoxPtr(),
-                          descr=builder.make_fail_descr())
+                          descr=BasicFailDescr())
         op.fail_args = builder.subset_of_intvars(r)
         op._exc_box = None
         builder.should_fail_by = op
@@ -509,7 +509,7 @@
         assert builder.cpu.get_exception()
         builder.cpu.clear_exception()
         op = ResOperation(rop.GUARD_EXCEPTION, [exc_box], BoxPtr(),
-                          descr=builder.make_fail_descr())
+                          descr=BasicFailDescr())
         op.fail_args = fail_subset
         builder.loop.operations.append(op)
 
@@ -527,7 +527,7 @@
         assert builder.cpu.get_exception()
         builder.cpu.clear_exception()
         op = ResOperation(rop.GUARD_NO_EXCEPTION, [], BoxPtr(),
-                          descr=builder.make_fail_descr())
+                          descr=BasicFailDescr())
         op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc), builder.cpu)
         op.fail_args = builder.subset_of_intvars(r)
         builder.should_fail_by = op
@@ -553,7 +553,7 @@
                 break
         other_box = ConstAddr(llmemory.cast_ptr_to_adr(vtableptr), builder.cpu)
         op = ResOperation(rop.GUARD_EXCEPTION, [other_box], BoxPtr(),
-                          descr=builder.make_fail_descr())
+                          descr=BasicFailDescr())
         op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc), builder.cpu)
         op.fail_args = builder.subset_of_intvars(r)
         builder.should_fail_by = op

Added: pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_model.py
==============================================================================
--- (empty file)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_model.py	Wed Nov 18 22:28:37 2009
@@ -0,0 +1,21 @@
+from pypy.jit.metainterp.history import AbstractFailDescr
+from pypy.jit.backend.model import AbstractCPU
+
+
+def test_faildescr_numbering():
+    cpu = AbstractCPU()
+    fail_descr1 = AbstractFailDescr()
+    fail_descr2 = AbstractFailDescr()    
+
+    n1 = cpu.get_fail_descr_number(fail_descr1)
+    n2 = cpu.get_fail_descr_number(fail_descr2)
+    assert n1 != n2
+
+    fail_descr = cpu.get_fail_descr_from_number(n1)
+    assert fail_descr is fail_descr1
+    fail_descr = cpu.get_fail_descr_from_number(n2)
+    assert fail_descr is fail_descr2
+
+    # provides interning on its own
+    n1_1 = cpu.get_fail_descr_number(fail_descr1)
+    assert n1_1 == n1

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/test/test_random.py	Wed Nov 18 22:28:37 2009
@@ -18,8 +18,6 @@
         self.operations = subops
 
 class OperationBuilder(object):
-    failnumbering = 0
-    
     def __init__(self, cpu, loop, vars):
         self.cpu = cpu
         self.loop = loop
@@ -36,12 +34,6 @@
         self.counter = 0
         assert len(self.intvars) == len(dict.fromkeys(self.intvars))
 
-    @classmethod
-    def make_fail_descr(cls):
-        descr = BasicFailDescr(cls.failnumbering)
-        cls.failnumbering += 1
-        return descr
-        
     def fork(self, cpu, loop, vars):
         fork = self.__class__(cpu, loop, vars)
         fork.prebuilt_ptr_consts = self.prebuilt_ptr_consts
@@ -282,7 +274,7 @@
             builder.intvars[:] = original_intvars
         else:
             op = ResOperation(rop.GUARD_NO_OVERFLOW, [], None)
-        op.descr = builder.make_fail_descr()
+        op.descr = BasicFailDescr()
         op.fail_args = fail_subset
         builder.loop.operations.append(op)
 
@@ -343,7 +335,7 @@
     def produce_into(self, builder, r):
         op, passing = self.gen_guard(builder, r)
         builder.loop.operations.append(op)
-        op.descr = builder.make_fail_descr()
+        op.descr = BasicFailDescr()
         op.fail_args = builder.subset_of_intvars(r)
         if not passing:
             builder.should_fail_by = op
@@ -559,7 +551,7 @@
                 endvars.append(v)
         r.shuffle(endvars)
         loop.operations.append(ResOperation(rop.FINISH, endvars, None,
-                                            descr=BasicFailDescr(-2)))
+                                            descr=BasicFailDescr()))
         if builder.should_fail_by:
             self.should_fail_by = builder.should_fail_by
             self.guard_op = builder.guard_op
@@ -605,7 +597,7 @@
             else:
                 raise NotImplementedError(box)
         fail = cpu.execute_token(self.loop.token)
-        assert fail == self.should_fail_by.descr.index
+        assert fail is self.should_fail_by.descr
         for i, v in enumerate(self.get_fail_args()):
             if isinstance(v, (BoxFloat, ConstFloat)):
                 value = cpu.get_latest_value_float(i)
@@ -634,7 +626,7 @@
             else:
                 op = ResOperation(rop.GUARD_EXCEPTION, [guard_op._exc_box],
                                   BoxPtr())
-            op.descr = self.builder.make_fail_descr()
+            op.descr = BasicFailDescr()
             op.fail_args = []
             return op
 

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/x86/assembler.py	Wed Nov 18 22:28:37 2009
@@ -795,8 +795,7 @@
         # don't break the following code sequence!
         mc = mc._mc
         mc.LEA(esp, addr_add(imm(0), ebp, (-RET_BP + 2) * WORD))
-        assert isinstance(faildescr, AbstractFailDescr)
-        fail_index = faildescr.get_index()
+        fail_index = self.cpu.get_fail_descr_number(faildescr)
         mc.MOV(eax, imm(fail_index))
         mc.POP(edi)
         mc.POP(esi)

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/x86/runner.py	Wed Nov 18 22:28:37 2009
@@ -63,7 +63,7 @@
         addr = executable_token._x86_bootstrap_code
         func = rffi.cast(lltype.Ptr(self.BOOTSTRAP_TP), addr)
         fail_index = self._execute_call(func)
-        return fail_index
+        return self.get_fail_descr_from_number(fail_index)
 
     def _execute_call(self, func):
         # help flow objspace

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_recompilation.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_recompilation.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_recompilation.py	Wed Nov 18 22:28:37 2009
@@ -21,7 +21,7 @@
         bridge = self.attach_bridge(ops, loop, -2)
         self.cpu.set_future_value_int(0, 0)
         fail = self.run(loop)
-        assert fail == 2
+        assert fail.identifier == 2
         assert self.getint(0) == 21
     
     def test_compile_bridge_deeper(self):
@@ -52,7 +52,7 @@
         assert new > previous
         self.cpu.set_future_value_int(0, 0)
         fail = self.run(loop)
-        assert fail == 2
+        assert fail.identifier == 2
         assert self.getint(0) == 21
         assert self.getint(1) == 22
         assert self.getint(2) == 23
@@ -78,7 +78,7 @@
         bridge = self.attach_bridge(ops, other_loop, 0, looptoken=loop.token)
         self.cpu.set_future_value_int(0, 1)
         fail = self.run(other_loop)
-        assert fail == 1
+        assert fail.identifier == 1
 
     def test_bridge_jumps_to_self_deeper(self):
         loop = self.interpret('''

Modified: pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/backend/x86/test/test_runner.py	Wed Nov 18 22:28:37 2009
@@ -260,7 +260,7 @@
                         self.cpu.set_future_value_int(0, b.value)
                     else:
                         self.cpu.set_future_value_ref(0, b.value)
-                    r = self.cpu.execute_token(looptoken)
+                    self.cpu.execute_token(looptoken)
                     result = self.cpu.get_latest_value_int(0)
                     if guard == rop.GUARD_FALSE:
                         assert result == execute(self.cpu, op, None, b).value
@@ -306,7 +306,7 @@
                     self.cpu.compile_loop(inputargs, ops, looptoken)
                     for i, box in enumerate(inputargs):
                         self.cpu.set_future_value_int(i, box.value)
-                    r = self.cpu.execute_token(looptoken)
+                    self.cpu.execute_token(looptoken)
                     result = self.cpu.get_latest_value_int(0)
                     expected = execute(self.cpu, op, None, a, b).value
                     if guard == rop.GUARD_FALSE:

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/compile.py	Wed Nov 18 22:28:37 2009
@@ -113,7 +113,7 @@
     metainterp_sd.log("compiled new " + type)
 
 def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations):
-    n = faildescr.get_index()
+    n = metainterp_sd.cpu.get_fail_descr_number(faildescr)
     metainterp_sd.logger_ops.log_bridge(inputargs, operations, n)
     if not we_are_translated():
         show_loop(metainterp_sd)
@@ -133,14 +133,7 @@
 # ____________________________________________________________
 
 class _DoneWithThisFrameDescr(AbstractFailDescr):
-
-    def __init__(self, lst):
-        "NOT_RPYTHON"        
-        self.index = len(lst)
-        lst.append(self)
-
-    def get_index(self):
-        return self.index
+    pass
 
 class DoneWithThisFrameDescrVoid(_DoneWithThisFrameDescr):
     def handle_fail(self, metainterp_sd):
@@ -173,18 +166,6 @@
         raise metainterp_sd.ExitFrameWithExceptionRef(cpu, value)
 
 
-done_with_this_frame_descrs = []
-done_with_this_frame_descr_void = DoneWithThisFrameDescrVoid(
-                                           done_with_this_frame_descrs)
-done_with_this_frame_descr_int = DoneWithThisFrameDescrInt(
-                                           done_with_this_frame_descrs)
-done_with_this_frame_descr_ref = DoneWithThisFrameDescrRef(
-                                           done_with_this_frame_descrs)
-done_with_this_frame_descr_float = DoneWithThisFrameDescrFloat(
-                                           done_with_this_frame_descrs)
-exit_frame_with_exception_descr_ref = ExitFrameWithExceptionDescrRef(
-                                           done_with_this_frame_descrs)
-
 prebuiltNotSpecNode = NotSpecNode()
 
 class TerminatingLoopToken(LoopToken):
@@ -194,22 +175,30 @@
         self.specnodes = [prebuiltNotSpecNode]*nargs
         self.finishdescr = finishdescr
 
-# pseudo loop tokens to make the life of optimize.py easier
-loop_tokens_done_with_this_frame_int = [
-    TerminatingLoopToken(1, done_with_this_frame_descr_int)
-    ]
-loop_tokens_done_with_this_frame_ref = [
-    TerminatingLoopToken(1, done_with_this_frame_descr_ref)
-    ]
-loop_tokens_done_with_this_frame_float = [
-    TerminatingLoopToken(1, done_with_this_frame_descr_float)
-    ]
-loop_tokens_done_with_this_frame_void = [
-    TerminatingLoopToken(0, done_with_this_frame_descr_void)
-    ]
-loop_tokens_exit_frame_with_exception_ref = [
-    TerminatingLoopToken(1, exit_frame_with_exception_descr_ref)
-    ]
+def make_done_loop_tokens():
+    done_with_this_frame_descr_void = DoneWithThisFrameDescrVoid()
+    done_with_this_frame_descr_int = DoneWithThisFrameDescrInt()
+    done_with_this_frame_descr_ref = DoneWithThisFrameDescrRef()
+    done_with_this_frame_descr_float = DoneWithThisFrameDescrFloat()
+    exit_frame_with_exception_descr_ref = ExitFrameWithExceptionDescrRef()
+
+    # pseudo loop tokens to make the life of optimize.py easier
+    return {'loop_tokens_done_with_this_frame_int': [
+                TerminatingLoopToken(1, done_with_this_frame_descr_int)
+                ],
+            'loop_tokens_done_with_this_frame_ref': [
+                TerminatingLoopToken(1, done_with_this_frame_descr_ref)
+                ],
+            'loop_tokens_done_with_this_frame_float': [
+                TerminatingLoopToken(1, done_with_this_frame_descr_float)
+                ],
+            'loop_tokens_done_with_this_frame_void': [
+                TerminatingLoopToken(0, done_with_this_frame_descr_void)
+                ],
+            'loop_tokens_exit_frame_with_exception_ref': [
+                TerminatingLoopToken(1, exit_frame_with_exception_descr_ref)
+                ],
+            }
 
 class ResumeDescr(AbstractFailDescr):
     def __init__(self, original_greenkey):
@@ -222,13 +211,6 @@
     def __init__(self, metainterp_sd, original_greenkey):
         ResumeDescr.__init__(self, original_greenkey)
         self.metainterp_sd = metainterp_sd
-        self.index = -1
-
-    def get_index(self):
-        if self.index == -1:
-            globaldata = self.metainterp_sd.globaldata
-            self.index = globaldata.get_fail_descr_number(self)
-        return self.index
 
     def store_final_boxes(self, guard_op, boxes):
         guard_op.fail_args = boxes

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/history.py	Wed Nov 18 22:28:37 2009
@@ -122,21 +122,16 @@
         return '%r' % (self,)
 
 class AbstractFailDescr(AbstractDescr):
+    index = -1
 
-    def get_index(self):
-        raise NotImplementedError
     def handle_fail(self, metainterp_sd):
         raise NotImplementedError
     def compile_and_attach(self, metainterp, new_loop):
         raise NotImplementedError
 
 class BasicFailDescr(AbstractFailDescr):
-
-    def __init__(self, index=-1):
-        self.index = index
-
-    def get_index(self):
-        return self.index
+    def __init__(self, identifier=None):
+        self.identifier = identifier      # for testing
 
 class AbstractMethDescr(AbstractDescr):
     # the base class of the result of cpu.methdescrof()

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/logger.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/logger.py	Wed Nov 18 22:28:37 2009
@@ -88,8 +88,8 @@
             if op.descr is not None:
                 descr = op.descr
                 if is_guard and self.guard_number:
-                    assert isinstance(descr, AbstractFailDescr)
-                    r = "<Guard%d>" % descr.get_index()
+                    index = self.metainterp_sd.cpu.get_fail_descr_number(descr)
+                    r = "<Guard%d>" % index
                 else:
                     r = self.repr_of_descr(descr)
                 args += ', descr=' +  r

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/pyjitpl.py	Wed Nov 18 22:28:37 2009
@@ -1022,6 +1022,8 @@
         self._addr2name_keys = []
         self._addr2name_values = []
 
+        self.__dict__.update(compile.make_done_loop_tokens())
+
     def _freeze_(self):
         return True
 
@@ -1044,8 +1046,7 @@
         else:
             self.num_green_args = 0
             self.state = None
-        self.globaldata = MetaInterpGlobalData(
-                               self, compile.done_with_this_frame_descrs)
+        self.globaldata = MetaInterpGlobalData(self)
 
     def _setup_once(self):
         """Runtime setup needed by the various components of the JIT."""
@@ -1136,11 +1137,10 @@
 # ____________________________________________________________
 
 class MetaInterpGlobalData(object):
-    def __init__(self, staticdata, prebuilt_fail_descr_list):
+    def __init__(self, staticdata):
         self.initialized = False
         self.indirectcall_dict = None
         self.addr2name = None
-        self.fail_descr_list = prebuilt_fail_descr_list[:]
         self.loopnumbering = 0
         #
         state = staticdata.state
@@ -1164,16 +1164,6 @@
             cell.compiled_merge_points = []
         return cell.compiled_merge_points
 
-    def get_fail_descr_number(self, descr):
-        assert isinstance(descr, history.AbstractFailDescr)
-        lst = self.fail_descr_list
-        n = len(lst)
-        lst.append(descr)
-        return n
-
-    def get_fail_descr_from_number(self, n):
-        return self.fail_descr_list[n]
-
 # ____________________________________________________________
 
 class MetaInterp(object):
@@ -1622,16 +1612,16 @@
         if sd.result_type == 'void':
             assert exitbox is None
             exits = []
-            loop_tokens = compile.loop_tokens_done_with_this_frame_void
+            loop_tokens = sd.loop_tokens_done_with_this_frame_void
         elif sd.result_type == 'int':
             exits = [exitbox]
-            loop_tokens = compile.loop_tokens_done_with_this_frame_int
+            loop_tokens = sd.loop_tokens_done_with_this_frame_int
         elif sd.result_type == 'ref':
             exits = [exitbox]
-            loop_tokens = compile.loop_tokens_done_with_this_frame_ref
+            loop_tokens = sd.loop_tokens_done_with_this_frame_ref
         elif sd.result_type == 'float':
             exits = [exitbox]
-            loop_tokens = compile.loop_tokens_done_with_this_frame_float
+            loop_tokens = sd.loop_tokens_done_with_this_frame_float
         else:
             assert False
         self.history.record(rop.JUMP, exits, None)
@@ -1643,7 +1633,8 @@
         self.gen_store_back_in_virtualizable()
         # temporarily put a JUMP to a pseudo-loop
         self.history.record(rop.JUMP, [valuebox], None)
-        loop_tokens = compile.loop_tokens_exit_frame_with_exception_ref
+        sd = self.staticdata
+        loop_tokens = sd.loop_tokens_exit_frame_with_exception_ref
         target_loop_token = compile.compile_new_bridge(self, loop_tokens,
                                                        self.resumekey)
         assert target_loop_token is loop_tokens[0]

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_compile.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_compile.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_compile.py	Wed Nov 18 22:28:37 2009
@@ -103,22 +103,3 @@
     assert loop_tokens == [loop_token]
     assert len(cpu.seen) == 0
     assert staticdata.globaldata.loopnumbering == 2    
-
-def test_resumeguarddescr_get_index():
-    from pypy.jit.metainterp.pyjitpl import MetaInterpGlobalData
-
-    class FakeStaticData:
-        state = None
-        virtualizable_info = None
-    gd = MetaInterpGlobalData(FakeStaticData, [])
-    FakeStaticData.globaldata = gd
-
-    rgd = ResumeGuardDescr(FakeStaticData, ())
-
-    fail_index = rgd.get_index()
-    fail_index1 = rgd.get_index()
-
-    assert fail_index == fail_index1
-
-    assert gd.get_fail_descr_from_number(fail_index) is rgd
-

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_logger.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_logger.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_logger.py	Wed Nov 18 22:28:37 2009
@@ -6,6 +6,8 @@
 from StringIO import StringIO
 from pypy.jit.metainterp.test.test_optimizeopt import equaloplists
 from pypy.jit.metainterp.history import AbstractDescr, LoopToken, BasicFailDescr
+from pypy.jit.backend.model import AbstractCPU
+
 
 class Descr(AbstractDescr):
     pass
@@ -36,8 +38,8 @@
 
     def make_metainterp_sd(self):
         class FakeMetaInterpSd:
-            class cpu:
-                ts = self.ts
+            cpu = AbstractCPU()
+            cpu.ts = self.ts
             def get_name_from_address(self, addr):
                 return 'Name'
         return FakeMetaInterpSd()
@@ -113,7 +115,7 @@
         pure_parse(output)
         
     def test_guard(self):
-        namespace = {'fdescr': BasicFailDescr(4)}
+        namespace = {'fdescr': BasicFailDescr()}
         inp = '''
         [i0]
         guard_true(i0, descr=fdescr) [i0]
@@ -121,15 +123,14 @@
         loop = pure_parse(inp, namespace=namespace)
         logger = Logger(self.make_metainterp_sd(), guard_number=True)
         output = logger.log_loop(loop)
-        assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard4>) [i0]"
+        assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard0>) [i0]"
         pure_parse(output)
         
-        def boom():
-            raise Exception
-        namespace['fdescr'].get_index = boom
         logger = Logger(self.make_metainterp_sd(), guard_number=False)
         output = logger.log_loop(loop)
-        assert output.splitlines()[-1].startswith("guard_true(i0, descr=<")
+        lastline = output.splitlines()[-1]
+        assert lastline.startswith("guard_true(i0, descr=<")
+        assert not lastline.startswith("guard_true(i0, descr=<Guard")
 
     def test_class_name(self):
         from pypy.rpython.lltypesystem import lltype

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_pyjitpl.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_pyjitpl.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/test/test_pyjitpl.py	Wed Nov 18 22:28:37 2009
@@ -37,35 +37,6 @@
         if rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST:
             assert hasattr(pyjitpl.MIFrame, 'opimpl_' + opname.lower()), opname
 
-def test_faildescr_numbering():
-    class FakeStaticData:
-        state = None
-        virtualizable_info = None
-
-    fail_descr0 = AbstractFailDescr()
-    lst = [fail_descr0]
-    gd = pyjitpl.MetaInterpGlobalData(FakeStaticData, lst)
-    assert gd.fail_descr_list is not lst
-
-    fail_descr = gd.get_fail_descr_from_number(0)
-    assert fail_descr is fail_descr0
-
-    fail_descr1 = AbstractFailDescr()
-    fail_descr2 = AbstractFailDescr()    
-
-    n1 = gd.get_fail_descr_number(fail_descr1)
-    n2 = gd.get_fail_descr_number(fail_descr2)
-    assert n1 != n2
-
-    fail_descr = gd.get_fail_descr_from_number(n1)
-    assert fail_descr is fail_descr1
-    fail_descr = gd.get_fail_descr_from_number(n2)
-    assert fail_descr is fail_descr2
-
-    # doesn't provide interning on its own
-    n1_1 = gd.get_fail_descr_number(fail_descr1)
-    assert n1_1 != n1
-
 def test_portal_trace_positions():
     jitcode = codewriter.JitCode("f")
     jitcode.code = jitcode.constants = None

Modified: pypy/branch/shorter-guard-path/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/branch/shorter-guard-path/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/branch/shorter-guard-path/pypy/jit/metainterp/warmstate.py	Wed Nov 18 22:28:37 2009
@@ -244,10 +244,9 @@
             while True:     # until interrupted by an exception
                 metainterp_sd.profiler.start_running()
                 debug_start("jit-running")
-                fail_index = metainterp_sd.cpu.execute_token(loop_token)
+                fail_descr = metainterp_sd.cpu.execute_token(loop_token)
                 debug_stop("jit-running")
                 metainterp_sd.profiler.end_running()
-                fail_descr = globaldata.get_fail_descr_from_number(fail_index)
                 loop_token = fail_descr.handle_fail(metainterp_sd)
 
         maybe_compile_and_run._dont_inline_ = True



More information about the Pypy-commit mailing list