[pypy-svn] r65484 - in pypy/branch/pyjitpl5-experiments/pypy/jit: backend backend/cli backend/x86 metainterp

antocuni at codespeak.net antocuni at codespeak.net
Thu May 28 23:15:13 CEST 2009


Author: antocuni
Date: Thu May 28 23:15:13 2009
New Revision: 65484

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/support.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/assembler.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/compile.py
Log:
add support for loop logging to the cli backend


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	Thu May 28 23:15:13 2009
@@ -1,5 +1,6 @@
 import py
 from pypy.tool.pairtype import extendabletype
+from pypy.rlib.objectmodel import compute_unique_id
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator.cli import dotnet
 from pypy.translator.cli.dotnet import CLR
@@ -8,6 +9,7 @@
 from pypy.jit.metainterp.history import (AbstractValue, Const, ConstInt,
                                          ConstObj)
 from pypy.jit.metainterp.resoperation import rop, opname
+from pypy.jit.backend.support import AbstractLogger
 from pypy.jit.backend.cli import runner
 from pypy.jit.backend.cli.methodfactory import get_method_wrapper
 
@@ -19,6 +21,16 @@
 
 cVoid = ootype.nullruntimeclass
 
+class CliLogger(AbstractLogger):
+    is_oo = True
+
+    def repr_of_descr(self, descr):
+        from pypy.jit.backend.cli.runner import DescrWithKey
+        if isinstance(descr, DescrWithKey):
+            return descr.short_repr()
+        return AbstractLogger.repr_of_descr(self, descr)
+    
+logger = CliLogger()
 
 class __extend__(AbstractValue):
     __metaclass__ = extendabletype
@@ -139,6 +151,11 @@
         else:
             self.av_OverflowError = None
             self.av_ZeroDivisionError = None
+
+        # ----
+        logger.create_log()
+        logger.eventually_log_operations(loop.inputargs, loop.operations, None,
+                                         compute_unique_id(loop))
         # ----
         self.emit_load_inputargs()
         self.emit_preamble()

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py	Thu May 28 23:15:13 2009
@@ -230,6 +230,9 @@
     def sort_key(self):
         return self.key
 
+    def short_repr(self):
+        return ''
+
 
 def get_class_for_type(T):
     if T is ootype.Void:
@@ -288,6 +291,7 @@
         self.getarraylength = getarraylength
         self.instanceof = instanceof
         self.ooclass = get_class_for_type(TYPE)
+        self.typename = TYPE._short_name()
 
     def get_clitype(self):
         return dotnet.class2type(self.ooclass)
@@ -299,6 +303,9 @@
         clitype = self.get_clitype()
         return clitype.GetConstructor(dotnet.new_array(System.Type, 0))
 
+    def short_repr(self):
+        return self.typename
+
 class StaticMethDescr(DescrWithKey):
 
     callfunc = None
@@ -425,6 +432,8 @@
         clitype = self.get_self_clitype()
         return clitype.GetField(self.fieldname+'')
 
+    def short_repr(self):
+        return "'%s'" % self.fieldname
 
 CPU = CliCPU
 

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/support.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/support.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/support.py	Thu May 28 23:15:13 2009
@@ -2,34 +2,18 @@
 from pypy.rlib.objectmodel import compute_unique_id
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import Const, ConstInt, Box, ConstPtr, BoxPtr,\
-     BoxInt, ConstAddr
+     BoxInt, ConstAddr, BoxObj, ConstObj
 
-def repr_of_arg(memo, arg):
-    try:
-        mv = memo[arg]
-    except KeyError:
-        mv = len(memo)
-        memo[arg] = mv
-    if isinstance(arg, ConstInt):
-        return "ci(%d,%d)" % (mv, arg.value)
-    elif isinstance(arg, ConstPtr):
-        return "cp(%d,%d)" % (mv, arg.get_())
-    elif isinstance(arg, BoxInt):
-        return "bi(%d,%d)" % (mv, arg.value)
-    elif isinstance(arg, BoxPtr):
-        return "bp(%d,%d)" % (mv, arg.get_())
-    elif isinstance(arg, ConstAddr):
-        return "ca(%d,%d)" % (mv, arg.get_())
-    else:
-        #raise NotImplementedError
-        return "?%r" % (arg,)
-
-class Logger(object):
+class AbstractLogger(object):
 
+    # is_oo = ...   ## need to be set by concrete classes
+    
     def __init__(self):
         self._log_fd = -1
 
     def create_log(self):
+        if self._log_fd != -1:
+            return self._log_fd
         s = os.environ.get('PYPYJITLOG')
         if not s:
             return -1
@@ -42,9 +26,33 @@
             return -1
         return self._log_fd
 
-    def repr_for_descr(self, descr):
+    def repr_of_descr(self, descr):
         return ''
 
+    def repr_of_arg(self, memo, arg):
+        try:
+            mv = memo[arg]
+        except KeyError:
+            mv = len(memo)
+            memo[arg] = mv
+        if isinstance(arg, ConstInt):
+            return "ci(%d,%d)" % (mv, arg.value)
+        elif isinstance(arg, BoxInt):
+            return "bi(%d,%d)" % (mv, arg.value)
+        elif not self.is_oo and isinstance(arg, ConstPtr):
+            return "cp(%d,%d)" % (mv, arg.get_())
+        elif not self.is_oo and isinstance(arg, BoxPtr):
+            return "bp(%d,%d)" % (mv, arg.get_())
+        elif not self.is_oo and isinstance(arg, ConstAddr):
+            return "ca(%d,%d)" % (mv, arg.get_())
+        elif self.is_oo and isinstance(arg, ConstObj):
+            return "co(%d,%d)" % (mv, arg.get_())
+        elif self.is_oo and isinstance(arg, BoxObj):
+            return "bo(%d,%d)" % (mv, arg.get_())
+        else:
+            #raise NotImplementedError
+            return "?%r" % (arg,)
+
     def eventually_log_operations(self, inputargs, operations, memo=None,
                                   myid=0):
         if self._log_fd == -1:
@@ -54,20 +62,20 @@
         if inputargs is None:
             os.write(self._log_fd, "BEGIN(%s)\n" % myid)
         else:
-            args = ",".join([repr_of_arg(memo, arg) for arg in inputargs])
+            args = ",".join([self.repr_of_arg(memo, arg) for arg in inputargs])
             os.write(self._log_fd, "LOOP %s\n" % args)
         for i in range(len(operations)):
             op = operations[i]
-            args = ",".join([repr_of_arg(memo, arg) for arg in op.args])
+            args = ",".join([self.repr_of_arg(memo, arg) for arg in op.args])
             if op.descr is not None:
-                descr = self.repr_for_descr(op.descr)
+                descr = self.repr_of_descr(op.descr)
                 os.write(self._log_fd, "%d:%s %s[%s]\n" % (i, op.getopname(),
                                                            args, descr))
             else:
                 os.write(self._log_fd, "%d:%s %s\n" % (i, op.getopname(), args))
             if op.result is not None:
-                os.write(self._log_fd, "  => %s\n" % repr_of_arg(memo,
-                                                                 op.result))
+                os.write(self._log_fd, "  => %s\n" % self.repr_of_arg(memo,
+                                                                      op.result))
             if op.is_guard():
                 self.eventually_log_operations(None, op.suboperations, memo)
         if operations[-1].opnum == rop.JUMP:
@@ -91,7 +99,7 @@
         reprs = []
         for j in range(len(gf.guard_op.liveboxes)):
             valuebox = gf.cpu.getvaluebox(gf.frame, gf.guard_op, j)
-            reprs.append(repr_of_arg(memo, valuebox))
+            reprs.append(self.repr_of_arg(memo, valuebox))
         jmp = gf.guard_op._jmp_from
         os.write(self._log_fd, "%d %d %s\n" % (guard_index, jmp,
                                                ",".join(reprs)))
@@ -102,6 +110,6 @@
             return
         return # XXX
         memo = {}
-        args_s = ','.join([repr_of_arg(memo, box) for box in valueboxes])
+        args_s = ','.join([self.repr_of_arg(memo, box) for box in valueboxes])
         os.write(self._log_fd, "CALL\n")
         os.write(self._log_fd, "%s %s\n" % (name, args_s))

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/assembler.py	Thu May 28 23:15:13 2009
@@ -13,21 +13,23 @@
 from pypy.jit.backend.x86 import codebuf
 from pypy.jit.backend.x86.ri386 import *
 from pypy.jit.metainterp.resoperation import rop
-from pypy.jit.backend.support import Logger
+from pypy.jit.backend.support import AbstractLogger
 
 # our calling convention - we pass three first args as edx, ecx and eax
 # and the rest stays on the stack
 
 MAX_FAIL_BOXES = 1000
 
-class x86Logger(Logger):
+class x86Logger(AbstractLogger):
 
-    def repr_for_descr(self, descr):
+    is_oo = False
+
+    def repr_of_descr(self, descr):
         from pypy.jit.backend.x86.runner import ConstDescr3
         if isinstance(descr, ConstDescr3):
-            return (str(op.descr.v0) + "," + str(op.descr.v1) +
-                    "," + str(op.descr.flag2))
-        return Logger.repr_for_descr(descr)
+            return (str(descr.v0) + "," + str(descr.v1) +
+                    "," + str(descr.flag2))
+        return AbstractLogger.repr_of_descr(self, descr)
 
 
 class MachineCodeBlockWrapper(object):

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/compile.py	Thu May 28 23:15:13 2009
@@ -272,7 +272,7 @@
             if isinstance(box, BoxInt):
                 srcvalue = cpu.get_latest_value_int(i)
                 box.changevalue_int(srcvalue)
-            elif isinstance(box, BoxPtr):
+            elif not cpu.is_oo and isinstance(box, BoxPtr):
                 srcvalue = cpu.get_latest_value_ptr(i)
                 box.changevalue_ptr(srcvalue)
             elif cpu.is_oo and isinstance(box, BoxObj):
@@ -290,7 +290,7 @@
             dstbox = fail_op.args[i]
             if isinstance(dstbox, BoxInt):
                 dstbox.changevalue_int(srcbox.getint())
-            elif isinstance(dstbox, BoxPtr):
+            elif not metainterp_sd.cpu.is_oo and isinstance(dstbox, BoxPtr):
                 dstbox.changevalue_ptr(srcbox.getptr_base())
             elif isinstance(dstbox, Const):
                 pass



More information about the Pypy-commit mailing list