[pypy-svn] r41804 - in pypy/dist/pypy: config interpreter objspace/std

mwh at codespeak.net mwh at codespeak.net
Mon Apr 2 15:13:39 CEST 2007


Author: mwh
Date: Mon Apr  2 15:13:37 2007
New Revision: 41804

Modified:
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/objspace/std/objspace.py
Log:
add some code to dump out the types verious simple bytecodes receive, the idea
being to inspire optimized bytecodes.


Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Mon Apr  2 15:13:37 2007
@@ -1,4 +1,4 @@
-import autopath
+]import autopath
 import py, os
 import sys
 from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption
@@ -234,6 +234,11 @@
                    "specify whether the default metaclass should be classobj",
                    default=False, cmdline="--oldstyle"),
 
+        BoolOption("logspaceoptypes",
+                   "a instrumentation option: before exit, print the types seen by "
+                   "certain simpler bytecodes",
+                   default=False),
+
         BoolOption("allopts",
                    "enable all thought-to-be-working optimizations",
                    default=False,

Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon Apr  2 15:13:37 2007
@@ -225,6 +225,9 @@
             report()
         if self.config.objspace.logbytecodes:
             self.reportbytecodecounts()
+        if self.config.objspace.std.logspaceoptypes:
+            for s in self.FrameClass._space_op_types:
+                print s
     
     def reportbytecodecounts(self):
         os.write(2, "Starting bytecode report.\n")

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Mon Apr  2 15:13:37 2007
@@ -26,6 +26,7 @@
         w_1 = f.popvalue()
         w_result = operation(w_1)
         f.pushvalue(w_result)
+    opimpl.unaryop = operationname
 
     return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
 
@@ -37,6 +38,7 @@
         w_1 = f.popvalue()
         w_result = operation(w_1, w_2)
         f.pushvalue(w_result)
+    opimpl.binop = operationname
 
     return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
 

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Mon Apr  2 15:13:37 2007
@@ -132,6 +132,41 @@
                     f.dropvalues(nargs)
                 f.pushvalue(w_result)
 
+            if self.config.objspace.std.logspaceoptypes:
+                _space_op_types = []
+                for name, func in pyframe.PyFrame.__dict__.iteritems():
+                    if hasattr(func, 'binop'):
+                        operationname = func.binop
+                        def make_opimpl(operationname):
+                            def opimpl(f, *ignored):
+                                operation = getattr(f.space, operationname)
+                                w_2 = f.popvalue()
+                                w_1 = f.popvalue()
+                                if we_are_translated():
+                                    s = operationname + ' ' + str(w_1) + ' ' + str(w_2)
+                                else:
+                                    s = operationname + ' ' + w_1.__class__.__name__ + ' ' + w_2.__class__.__name__
+                                f._space_op_types.append(s)
+                                w_result = operation(w_1, w_2)
+                                f.pushvalue(w_result)
+                            return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
+                        locals()[name] = make_opimpl(operationname)
+                    elif hasattr(func, 'unaryop'):
+                        operationname = func.unaryop
+                        def make_opimpl(operationname):
+                            def opimpl(f, *ignored):
+                                operation = getattr(f.space, operationname)
+                                w_1 = f.popvalue()
+                                if we_are_translated():
+                                    s = operationname + ' ' + str(w_1)
+                                else:
+                                    s = operationname + ' ' + w_1.__class__.__name__
+                                f._space_op_types.append(s)
+                                w_result = operation(w_1)
+                                f.pushvalue(w_result)
+                            return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
+                        locals()[name] = make_opimpl(operationname)
+
         self.FrameClass = StdObjSpaceFrame
 
         # XXX store the dict class on the space to access it in various places



More information about the Pypy-commit mailing list