[pypy-svn] r68541 - in pypy/trunk/pypy/jit/metainterp: . test

pedronis at codespeak.net pedronis at codespeak.net
Fri Oct 16 18:16:05 CEST 2009


Author: pedronis
Date: Fri Oct 16 18:16:03 2009
New Revision: 68541

Modified:
   pypy/trunk/pypy/jit/metainterp/compile.py
   pypy/trunk/pypy/jit/metainterp/history.py
   pypy/trunk/pypy/jit/metainterp/logger.py
   pypy/trunk/pypy/jit/metainterp/pyjitpl.py
   pypy/trunk/pypy/jit/metainterp/test/test_compile.py
   pypy/trunk/pypy/jit/metainterp/test/test_logger.py
Log:
log more information to follow the flow of things in the optimized ops logs



Modified: pypy/trunk/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/compile.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/compile.py	Fri Oct 16 18:16:03 2009
@@ -53,10 +53,10 @@
         loop.operations = history.operations[start:]
     else:
         loop.operations = history.operations
+    metainterp_sd = metainterp.staticdata
     loop_token = make_loop_token(len(loop.inputargs))
     loop.token = loop_token
     loop.operations[-1].descr = loop_token     # patch the target of the JUMP
-    metainterp_sd = metainterp.staticdata
     try:
         old_loop_token = metainterp_sd.state.optimize_loop(
             metainterp_sd, old_loop_tokens, loop)
@@ -83,7 +83,12 @@
         old_loop_tokens.append(loop_token)
 
 def send_loop_to_backend(metainterp_sd, loop, type):
-    metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations)
+    globaldata = metainterp_sd.globaldata
+    loop_token = loop.token
+    loop_token.number = n = globaldata.loopnumbering
+    globaldata.loopnumbering += 1
+
+    metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n, type)
     metainterp_sd.profiler.start_backend()
     if not we_are_translated():
         show_loop(metainterp_sd, loop)
@@ -99,7 +104,8 @@
     metainterp_sd.log("compiled new " + type)
 
 def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations):
-    metainterp_sd.logger_ops.log_loop(inputargs, operations)
+    n = faildescr.get_index()
+    metainterp_sd.logger_ops.log_bridge(inputargs, operations, n)
     metainterp_sd.profiler.start_backend()
     if not we_are_translated():
         show_loop(metainterp_sd)

Modified: pypy/trunk/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/history.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/history.py	Fri Oct 16 18:16:03 2009
@@ -680,6 +680,12 @@
     # specnodes = ...
     # and more data specified by the backend when the loop is compiled
 
+    def __init__(self, number=0):
+        self.number = number
+
+    def repr_of_descr(self):
+        return '<Loop%d>' % self.number
+
 class TreeLoop(object):
     inputargs = None
     operations = None

Modified: pypy/trunk/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/logger.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/logger.py	Fri Oct 16 18:16:03 2009
@@ -2,14 +2,15 @@
 from pypy.rlib.objectmodel import compute_unique_id
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import Const, ConstInt, Box, \
-     BoxInt, ConstAddr, ConstFloat, BoxFloat
+     BoxInt, ConstAddr, ConstFloat, BoxFloat, AbstractFailDescr
 from pypy.rlib.streamio import open_file_as_stream
 
 class Logger(object):
 
-    def __init__(self, ts):
+    def __init__(self, ts, guard_number=False):
         self.log_stream = None
         self.ts = ts
+        self.guard_number=guard_number
 
     def create_log(self, extension='.ops'):
         if self.log_stream is not None:
@@ -25,8 +26,23 @@
             return None
         return self.log_stream
 
-    def log_loop(self, inputargs, operations):
-        self.log_operations(inputargs, operations, {})
+    def log_loop(self, inputargs, operations, number=0, type=None):
+        if self.log_stream is None:
+            return
+        if type is not None:
+            self.log_stream.write("# Loop%d (%s), %d ops\n" % (number,
+                                                              type,
+                                                              len(operations)))
+        self._log_operations(inputargs, operations, {})
+
+    def log_bridge(self, inputargs, operations, number=-1):
+        if self.log_stream is None:
+            return
+        if number != -1:
+            self.log_stream.write("# bridge out of Guard%d, %d ops\n" % (number,
+                                                               len(operations)))
+        self._log_operations(inputargs, operations, {})
+        
 
     def repr_of_descr(self, descr):
         return descr.repr_of_descr()
@@ -54,31 +70,35 @@
         else:
             return '?'
 
-    def log_operations(self, inputargs, operations, memo, indent=0):
-        if self.log_stream is None:
-            return
-        pre = " " * indent
+    def _log_operations(self, inputargs, operations, memo):
         if inputargs is not None:
             args = ", ".join([self.repr_of_arg(memo, arg) for arg in inputargs])
-            self.log_stream.write(pre + '[' + args + ']\n')
+            self.log_stream.write('[' + args + ']\n')
         for i in range(len(operations)):
             op = operations[i]
             if op.opnum == rop.DEBUG_MERGE_POINT:
                 loc = op.args[0]._get_str()
-                self.log_stream.write(pre + "debug_merge_point('%s')\n" % (loc,))
+                self.log_stream.write("debug_merge_point('%s')\n" % (loc,))
                 continue
             args = ", ".join([self.repr_of_arg(memo, arg) for arg in op.args])
             if op.result is not None:
                 res = self.repr_of_arg(memo, op.result) + " = "
             else:
                 res = ""
+            is_guard = op.is_guard()
             if op.descr is not None:
-                args += ', descr=' + self.repr_of_descr(op.descr)
-            if op.is_guard() and op.fail_args is not None:
+                descr = op.descr
+                if is_guard and self.guard_number:
+                    assert isinstance(descr, AbstractFailDescr)
+                    r = "<Guard%d>" % descr.get_index()
+                else:
+                    r = self.repr_of_descr(descr)
+                args += ', descr=' +  r
+            if is_guard and op.fail_args is not None:
                 fail_args = ' [' + ", ".join([self.repr_of_arg(memo, arg)
                                               for arg in op.fail_args]) + ']'
             else:
                 fail_args = ''
-            self.log_stream.write(pre + res + op.getopname() +
+            self.log_stream.write(res + op.getopname() +
                                   '(' + args + ')' + fail_args + '\n')
         self.log_stream.flush()

Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py	Fri Oct 16 18:16:03 2009
@@ -970,7 +970,7 @@
         self.stats = stats
         self.options = options
         self.logger_noopt = Logger(cpu.ts)
-        self.logger_ops = Logger(cpu.ts)
+        self.logger_ops = Logger(cpu.ts, guard_number=True)
 
         RESULT = portal_graph.getreturnvar().concretetype
         self.result_type = history.getkind(RESULT)
@@ -1093,6 +1093,7 @@
         self.initialized = False
         self.indirectcall_dict = None
         self.fail_descr_list = prebuilt_fail_descr_list[:]
+        self.loopnumbering = 0
         #
         state = staticdata.state
         if state is not None:

Modified: pypy/trunk/pypy/jit/metainterp/test/test_compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_compile.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_compile.py	Fri Oct 16 18:16:03 2009
@@ -34,14 +34,18 @@
         self.seen.append((inputargs, operations, token))
 
 class FakeLogger:
-    def log_loop(self, inputargs, operations):
+    def log_loop(self, inputargs, operations, number=0, type=None):
         pass
 
 class FakeState:
     optimize_loop = staticmethod(optimize.optimize_loop)
     debug_level = 0
 
+class FakeGlobalData():
+    loopnumbering = 0
+
 class FakeMetaInterpStaticData:
+    
     logger_noopt = FakeLogger()
     logger_ops = FakeLogger()
 
@@ -58,6 +62,8 @@
     cpu = FakeCPU()
     staticdata = FakeMetaInterpStaticData()
     staticdata.cpu = cpu
+    staticdata.globaldata = FakeGlobalData()
+    staticdata.globaldata.loopnumbering = 1
     #
     loop = parse('''
     [p1]
@@ -78,6 +84,8 @@
     loop_tokens = []
     loop_token = compile_new_loop(metainterp, loop_tokens, [], 0)
     assert loop_tokens == [loop_token]
+    assert loop_token.number == 1
+    assert staticdata.globaldata.loopnumbering == 2
     #
     assert len(cpu.seen) == 1
     assert cpu.seen[0][2] == loop_token
@@ -94,6 +102,7 @@
     assert loop_token_2 is loop_token
     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

Modified: pypy/trunk/pypy/jit/metainterp/test/test_logger.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_logger.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_logger.py	Fri Oct 16 18:16:03 2009
@@ -4,7 +4,7 @@
 from pypy.jit.metainterp.typesystem import llhelper
 from StringIO import StringIO
 from pypy.jit.metainterp.test.test_optimizeopt import equaloplists
-from pypy.jit.metainterp.history import AbstractDescr
+from pypy.jit.metainterp.history import AbstractDescr, LoopToken, BasicFailDescr
 
 class Descr(AbstractDescr):
     pass
@@ -20,7 +20,7 @@
         for k, v in self.namespace.items():
             if v == descr:
                 return k
-        return "???"
+        return descr.repr_of_descr()
 
 class TestLogger(object):
     ts = llhelper
@@ -81,5 +81,51 @@
         f1 = float_add(3.5, f0)
         '''
         loop, oloop = self.reparse(inp)
-        equaloplists(loop.operations, oloop.operations)       
+        equaloplists(loop.operations, oloop.operations)
 
+    def test_jump(self):
+        namespace = {'target': LoopToken(3)}
+        inp = '''
+        [i0]
+        jump(i0, descr=target)
+        '''
+        loop = pure_parse(inp, namespace=namespace)
+        logger = Logger(self.ts)
+        output = logger.log_loop(loop)
+        assert output.splitlines()[-1] == "jump(i0, descr=<Loop3>)"
+        pure_parse(output)
+        
+    def test_guard(self):
+        namespace = {'fdescr': BasicFailDescr(4)}
+        inp = '''
+        [i0]
+        guard_true(i0, descr=fdescr) [i0]
+        '''
+        loop = pure_parse(inp, namespace=namespace)
+        logger = Logger(self.ts, guard_number=True)
+        output = logger.log_loop(loop)
+        assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard4>) [i0]"
+        pure_parse(output)
+        
+        def boom():
+            raise Exception
+        namespace['fdescr'].get_index = boom
+        logger = Logger(self.ts, guard_number=False)
+        output = logger.log_loop(loop)
+        assert output.splitlines()[-1].startswith("guard_true(i0, descr=<")
+
+    def test_intro_loop(self):
+        bare_logger = logger.Logger(self.ts)
+        bare_logger.log_stream = StringIO()
+        bare_logger.log_loop([], [], 1, "foo")
+        output = bare_logger.log_stream.getvalue()
+        assert output.splitlines()[0] == "# Loop1 (foo), 0 ops"
+        pure_parse(output)
+
+    def test_intro_bridge(self):
+        bare_logger = logger.Logger(self.ts)
+        bare_logger.log_stream = StringIO()
+        bare_logger.log_bridge([], [], 3)
+        output = bare_logger.log_stream.getvalue()
+        assert output.splitlines()[0] == "# bridge out of Guard3, 0 ops"        
+        pure_parse(output)



More information about the Pypy-commit mailing list