[pypy-svn] r21141 - in pypy/dist/pypy: jit objspace/flow rpython translator translator/backendopt translator/c translator/js translator/llvm translator/llvm/backendopt

arigo at codespeak.net arigo at codespeak.net
Tue Dec 13 17:50:55 CET 2005


Author: arigo
Date: Tue Dec 13 17:50:51 2005
New Revision: 21141

Modified:
   pypy/dist/pypy/jit/llabstractinterp.py
   pypy/dist/pypy/objspace/flow/flowcontext.py
   pypy/dist/pypy/objspace/flow/model.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/backendopt/inline.py
   pypy/dist/pypy/translator/backendopt/propagate.py
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/geninterplevel.py
   pypy/dist/pypy/translator/js/funcnode.py
   pypy/dist/pypy/translator/llvm/backendopt/exception.py
   pypy/dist/pypy/translator/llvm/funcnode.py
   pypy/dist/pypy/translator/simplify.py
   pypy/dist/pypy/translator/transform.py
   pypy/dist/pypy/translator/unsimplify.py
Log:
Replaced the many calls 'Constant(last_exception)' with a prebuilt
'c_last_exception'.


Modified: pypy/dist/pypy/jit/llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/llabstractinterp.py	(original)
+++ pypy/dist/pypy/jit/llabstractinterp.py	Tue Dec 13 17:50:51 2005
@@ -1,7 +1,7 @@
 import operator
 from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
 from pypy.objspace.flow.model import Block, Link, FunctionGraph
-from pypy.objspace.flow.model import checkgraph, last_exception
+from pypy.objspace.flow.model import checkgraph, c_last_exception
 from pypy.rpython.lltypesystem import lltype
 from pypy.translator.simplify import eliminate_empty_blocks, join_blocks
 
@@ -654,7 +654,7 @@
             # later completion
             if origblock.exitswitch is None:
                 links = origblock.exits
-            elif origblock.exitswitch == Constant(last_exception):
+            elif origblock.exitswitch == c_last_exception:
                 XXX
             else:
                 a = builder.bindings[origblock.exitswitch]

Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py	Tue Dec 13 17:50:51 2005
@@ -233,7 +233,7 @@
             else:
                 yield 'last_exception', Variable('last_exception')
                 yield 'last_exc_value', Variable('last_exc_value')
-        outcome = self.guessbool(Constant(last_exception),
+        outcome = self.guessbool(c_last_exception,
                                  cases = [None] + list(classes),
                                  replace_last_variable_except_in_first_case = replace_exc_values)
         if outcome is None:

Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/dist/pypy/objspace/flow/model.py	Tue Dec 13 17:50:51 2005
@@ -357,6 +357,7 @@
         return self.__name__
 
 last_exception = Atom('last_exception')
+c_last_exception = Constant(last_exception)
 # if Block().exitswitch == Constant(last_exception), it means that we are
 # interested in catching the exception that the *last operation* of the
 # block could raise.  The exitcases of the links are None for no exception
@@ -504,7 +505,7 @@
                     assert len(block.exits) <= 1
                     if block.exits:
                         assert block.exits[0].exitcase is None
-                elif block.exitswitch == Constant(last_exception):
+                elif block.exitswitch == c_last_exception:
                     assert len(block.operations) >= 1
                     # check if an exception catch is done on a reasonable
                     # operation

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Tue Dec 13 17:50:51 2005
@@ -1,4 +1,4 @@
-from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, last_exception
+from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, c_last_exception
 from pypy.rpython.rarithmetic import intmask, r_uint, ovfcheck, r_longlong
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.memory import lladdress
@@ -163,7 +163,7 @@
             is None, values is the concrete return value.
         """
         self.curr_block = block
-        catch_exception = block.exitswitch == Constant(last_exception)
+        catch_exception = block.exitswitch == c_last_exception
         e = None
 
         try:

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Tue Dec 13 17:50:51 2005
@@ -17,7 +17,7 @@
 from pypy.annotation.pairtype import pair
 from pypy.annotation import model as annmodel
 from pypy.objspace.flow.model import Variable, Constant
-from pypy.objspace.flow.model import SpaceOperation, last_exception
+from pypy.objspace.flow.model import SpaceOperation, c_last_exception
 from pypy.rpython.lltypesystem.lltype import \
      Signed, Unsigned, Float, Char, Bool, Void, \
      LowLevelType, Ptr, ContainerType, \
@@ -302,7 +302,7 @@
         if (pos is not None and pos != len(newops)-1):
             # this is for the case where the llop that raises the exceptions
             # is not the last one in the list.
-            assert block.exitswitch == Constant(last_exception)
+            assert block.exitswitch == c_last_exception
             noexclink = block.exits[0]
             assert noexclink.exitcase is None
             if pos == "removed":
@@ -342,7 +342,7 @@
                 if isinstance(block.exitswitch, Variable):
                     r_case = self.bindingrepr(block.exitswitch)
                 else:
-                    assert block.exitswitch == Constant(last_exception)
+                    assert block.exitswitch == c_last_exception
                     r_case = rclass.get_type_repr(self)
                 link.llexitcase = r_case.convert_const(link.exitcase)
             else:
@@ -408,7 +408,7 @@
             for op in block.operations[:-1]:
                 yield HighLevelOp(self, op, [], llops)
             # look for exception links for the last operation
-            if block.exitswitch == Constant(last_exception):
+            if block.exitswitch == c_last_exception:
                 exclinks = block.exits[1:]
             else:
                 exclinks = []

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Tue Dec 13 17:50:51 2005
@@ -7,7 +7,7 @@
 from pypy.annotation.bookkeeper import Bookkeeper
 from pypy.objspace.flow.model import Variable, Constant
 from pypy.objspace.flow.model import FunctionGraph
-from pypy.objspace.flow.model import last_exception, checkgraph
+from pypy.objspace.flow.model import c_last_exception, checkgraph
 import py
 log = py.log.Producer("annrpython") 
 py.log.setconsumer("annrpython", ansi_log) 
@@ -190,7 +190,6 @@
         elif isinstance(arg, Constant):
             #if arg.value is undefined_value:   # undefined local variables
             #    return annmodel.SomeImpossibleValue()
-            assert not arg.value is last_exception
             return self.bookkeeper.immutablevalue(arg.value)
         else:
             raise TypeError, 'Variable or Constant expected, got %r' % (arg,)
@@ -434,7 +433,7 @@
                 self.why_not_annotated[block] = sys.exc_info()
 
             if (e.op is block.operations[-1] and
-                block.exitswitch == Constant(last_exception)):
+                block.exitswitch == c_last_exception):
                 # this is the case where the last operation of the block will
                 # always raise an exception which is immediately caught by
                 # an exception handler.  We then only follow the exceptional
@@ -471,7 +470,7 @@
 
         # filter out those exceptions which cannot
         # occour for this specific, typed operation.
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             op = block.operations[-1]
             if op.opname in annmodel.BINARY_OPERATIONS:
                 arg1 = self.binding(op.args[0])

Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py	(original)
+++ pypy/dist/pypy/translator/backendopt/inline.py	Tue Dec 13 17:50:51 2005
@@ -3,7 +3,7 @@
 from pypy.translator.simplify import remove_identical_vars
 from pypy.translator.unsimplify import copyvar, split_block
 from pypy.objspace.flow.model import Variable, Constant, Block, Link
-from pypy.objspace.flow.model import SpaceOperation, last_exception
+from pypy.objspace.flow.model import SpaceOperation, c_last_exception
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem.lltype import Bool, typeOf, Void
@@ -79,7 +79,7 @@
     op = block.operations[index_operation]
     graph_to_inline = op.args[0].value._obj.graph
     exception_guarded = False
-    if (block.exitswitch == Constant(last_exception) and
+    if (block.exitswitch == c_last_exception and
         index_operation == len(block.operations) - 1):
         exception_guarded = True
         if len(collect_called_functions(graph_to_inline)) != 0:

Modified: pypy/dist/pypy/translator/backendopt/propagate.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/propagate.py	(original)
+++ pypy/dist/pypy/translator/backendopt/propagate.py	Tue Dec 13 17:50:51 2005
@@ -1,4 +1,4 @@
-from pypy.objspace.flow.model import Block, Variable, Constant, last_exception
+from pypy.objspace.flow.model import Block, Variable, Constant, c_last_exception
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
 from pypy.objspace.flow.model import SpaceOperation
 from pypy.rpython.lltypesystem.lltype import Bool
@@ -63,7 +63,7 @@
             return
         if len(block.exits) != 2:
             return
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             return
         if (block.exits[0].args == block.exits[1].args and
             block.exits[0].target is block.exits[1].target):
@@ -172,7 +172,7 @@
                 called_graph = get_graph(op.args[0], translator)
                 if (called_graph is not None and
                     simplify.has_no_side_effects(translator, called_graph) and
-                    (block.exitswitch != Constant(last_exception) or 
+                    (block.exitswitch != c_last_exception or 
                      i != len(block.operations) - 1)):
                     args = [arg.value for arg in op.args[1:]]
                     countingframe = CountingLLFrame(called_graph, args, lli)

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Tue Dec 13 17:50:51 2005
@@ -3,7 +3,7 @@
 from pypy.translator.c.support import cdecl, ErrorValue
 from pypy.translator.c.support import llvalue_from_constant, gen_assignments
 from pypy.objspace.flow.model import Variable, Constant, Block
-from pypy.objspace.flow.model import traverse, last_exception
+from pypy.objspace.flow.model import traverse, c_last_exception
 from pypy.rpython.lltypesystem.lltype import \
      Ptr, PyObject, Void, Bool, pyobjectptr, Struct, Array
 
@@ -270,7 +270,7 @@
                 for op in gen_link(block.exits[0]):
                     yield op
                 yield ''
-            elif block.exitswitch == Constant(last_exception):
+            elif block.exitswitch == c_last_exception:
                 # block catching the exceptions raised by its last operation
                 # we handle the non-exceptional case first
                 link = block.exits[0]

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Tue Dec 13 17:50:51 2005
@@ -48,7 +48,7 @@
 import cPickle as pickle, __builtin__
 from copy_reg import _HEAPTYPE
 from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
-from pypy.objspace.flow.model import last_exception, checkgraph
+from pypy.objspace.flow.model import c_last_exception, checkgraph
 from pypy.interpreter.pycode import CO_VARARGS, CO_VARKEYWORDS
 from types import FunctionType, CodeType, ModuleType
 from pypy.interpreter.error import OperationError
@@ -1264,7 +1264,7 @@
         yield "    while True:"
                 
         def render_block(block):
-            catch_exception = block.exitswitch == Constant(last_exception)
+            catch_exception = block.exitswitch == c_last_exception
             regular_op = len(block.operations) - catch_exception
             # render all but maybe the last op
             for op in block.operations[:regular_op]:

Modified: pypy/dist/pypy/translator/js/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/funcnode.py	(original)
+++ pypy/dist/pypy/translator/js/funcnode.py	Tue Dec 13 17:50:51 2005
@@ -1,7 +1,7 @@
 import py
 import sys
 from pypy.objspace.flow.model import Block, Constant, Variable, Link
-from pypy.objspace.flow.model import flatten, mkentrymap, traverse, last_exception
+from pypy.objspace.flow.model import flatten, mkentrymap, traverse, c_last_exception
 from pypy.rpython.lltypesystem import lltype
 from pypy.translator.js.node import Node
 from pypy.translator.js.opwriter import OpWriter
@@ -30,7 +30,7 @@
                 for op in block.operations:
                     map(self.db.prepare_arg, op.args)
                     self.db.prepare_arg(op.result)
-                    if block.exitswitch != Constant(last_exception):
+                    if block.exitswitch != c_last_exception:
                         continue
                     for link in block.exits[1:]:
                         self.db.prepare_constant(lltype.typeOf(link.llexitcase),
@@ -75,7 +75,7 @@
         self.write_block_branches(codewriter, block)
 
     def write_block_branches(self, codewriter, block):
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             return
         if len(block.exits) == 1:
             codewriter.br_uncond(self.blockindex[block.exits[0].target], block.exits[0])
@@ -87,7 +87,7 @@
 
     def write_block_operations(self, codewriter, block):
         opwriter = OpWriter(self.db, codewriter, self, block)
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             last_op_index = len(block.operations) - 1
         else:
             last_op_index = None

Modified: pypy/dist/pypy/translator/llvm/backendopt/exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/backendopt/exception.py	(original)
+++ pypy/dist/pypy/translator/llvm/backendopt/exception.py	Tue Dec 13 17:50:51 2005
@@ -1,6 +1,6 @@
 from pypy.translator.unsimplify import split_block
 from pypy.objspace.flow.model import Block, Constant, Variable, Link, \
-        last_exception, flatten, SpaceOperation
+        c_last_exception, flatten, SpaceOperation
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem.lltype import Bool
 
@@ -20,7 +20,7 @@
     blocks = [x for x in flatten(graph) if isinstance(x, Block)]
     for block in blocks:
         last_operation = len(block.operations)-1
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             last_operation -= 1
         for i in range(last_operation, -1, -1):
             op = block.operations[i]

Modified: pypy/dist/pypy/translator/llvm/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/funcnode.py	Tue Dec 13 17:50:51 2005
@@ -1,5 +1,5 @@
 from pypy.objspace.flow.model import Block, Constant, Link
-from pypy.objspace.flow.model import flatten, mkentrymap, traverse, last_exception
+from pypy.objspace.flow.model import flatten, mkentrymap, traverse, c_last_exception
 from pypy.rpython.lltypesystem import lltype
 from pypy.translator.llvm.node import LLVMNode, ConstantLLVMNode
 from pypy.translator.llvm.opwriter import OpWriter
@@ -59,7 +59,7 @@
                 for op in block.operations:
                     map(self.db.prepare_arg, op.args)
                     self.db.prepare_arg(op.result)
-                    if block.exitswitch != Constant(last_exception):
+                    if block.exitswitch != c_last_exception:
                         continue
                     for link in block.exits[1:]:
                         self.db.prepare_constant(lltype.typeOf(link.llexitcase),
@@ -154,7 +154,7 @@
             blocknames = [self.block_to_name[link.prevblock]
                               for link in entrylinks]
             for i, link in enumerate(entrylinks):   #XXX refactor into a transformation
-                if link.prevblock.exitswitch == Constant(last_exception) and \
+                if link.prevblock.exitswitch == c_last_exception and \
                    link.prevblock.exits[0].target != block:
                     blocknames[i] += '_exception_found_branchto_' + self.block_to_name[block]
             data.append( (arg, type_, names, blocknames) )
@@ -167,7 +167,7 @@
 
     def write_block_branches(self, codewriter, block):
         #assert len(block.exits) <= 2    #more exits are possible (esp. in combination with exceptions)
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             #codewriter.comment('FuncNode(ConstantLLVMNode) *last_exception* write_block_branches @%s@' % str(block.exits))
             return
         if len(block.exits) == 1:
@@ -179,7 +179,7 @@
 
     def write_block_operations(self, codewriter, block):
         opwriter = OpWriter(self.db, codewriter, self, block)
-        if block.exitswitch == Constant(last_exception):
+        if block.exitswitch == c_last_exception:
             last_op_index = len(block.operations) - 1
         else:
             last_op_index = None

Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py	(original)
+++ pypy/dist/pypy/translator/simplify.py	Tue Dec 13 17:50:51 2005
@@ -7,7 +7,7 @@
 
 from pypy.objspace.flow.model import SpaceOperation
 from pypy.objspace.flow.model import Variable, Constant, Block, Link
-from pypy.objspace.flow.model import last_exception
+from pypy.objspace.flow.model import c_last_exception
 from pypy.objspace.flow.model import checkgraph, traverse, mkentrymap
 
 def get_graph(arg, translator):
@@ -42,7 +42,7 @@
         if isinstance(link, Link):
             while not link.target.operations:
                 if (len(link.target.exits) != 1 and
-                    link.target.exitswitch != Constant(last_exception)):
+                    link.target.exitswitch != c_last_exception):
                     break
                 assert link.target is not link.prevblock, (
                     "the graph contains an empty infinite loop")
@@ -190,7 +190,7 @@
     chain of is_/issubtype tests. We collapse them all into
     the block's single list of exits.
     """
-    clastexc = Constant(last_exception)
+    clastexc = c_last_exception
     renaming = {}
     def rename(v):
         return renaming.get(v, v)
@@ -251,7 +251,7 @@
 def remove_dead_exceptions(graph):
     """Exceptions can be removed if they are unreachable"""
 
-    clastexc = Constant(last_exception)
+    clastexc = c_last_exception
 
     def issubclassofmember(cls, seq):
         for member in seq:
@@ -331,7 +331,7 @@
                 # can we remove this exit without breaking the graph?
                 if len(block.exits) < 2:
                     break
-                if block.exitswitch == Constant(last_exception):
+                if block.exitswitch == c_last_exception:
                     if exit.exitcase is None:
                         break
                     if len(block.exits) == 2:
@@ -434,7 +434,7 @@
     def canremove(op, block):
         if op.opname not in CanRemove:
             return False
-        if block.exitswitch != Constant(last_exception):
+        if block.exitswitch != c_last_exception:
             return True
         # cannot remove the exc-raising operation
         return op is not block.operations[-1]
@@ -544,7 +544,7 @@
                         graph = get_graph(op.args[0], translator)
                         if (graph is not None and
                             has_no_side_effects(translator, graph) and
-                            (block.exitswitch != Constant(last_exception) or
+                            (block.exitswitch != c_last_exception or
                              i != len(block.operations)- 1)):
                             del block.operations[i]
         # look for output variables never used

Modified: pypy/dist/pypy/translator/transform.py
==============================================================================
--- pypy/dist/pypy/translator/transform.py	(original)
+++ pypy/dist/pypy/translator/transform.py	Tue Dec 13 17:50:51 2005
@@ -10,7 +10,7 @@
 import types
 from pypy.objspace.flow.model import SpaceOperation
 from pypy.objspace.flow.model import Variable, Constant, Link
-from pypy.objspace.flow.model import last_exception, checkgraph
+from pypy.objspace.flow.model import c_last_exception, checkgraph
 from pypy.annotation import model as annmodel
 from pypy.rpython.rstack import stack_check
 
@@ -98,7 +98,7 @@
                 if not block.exits:
                     # oups! cannot reach the end of this block
                     cutoff_alwaysraising_block(self, block)
-                elif block.exitswitch == Constant(last_exception):
+                elif block.exitswitch == c_last_exception:
                     # exceptional exit
                     if block.exits[0].exitcase is not None:
                         # killed the non-exceptional path!

Modified: pypy/dist/pypy/translator/unsimplify.py
==============================================================================
--- pypy/dist/pypy/translator/unsimplify.py	(original)
+++ pypy/dist/pypy/translator/unsimplify.py	Tue Dec 13 17:50:51 2005
@@ -38,7 +38,7 @@
 def split_block(translator, graph, block, index):
     """split a block in two, inserting a proper link between the new blocks"""
     assert 0 <= index <= len(block.operations)
-    if block.exitswitch == Constant(last_exception):
+    if block.exitswitch == c_last_exception:
         assert index < len(block.operations)
     #varmap is the map between names in the new and the old block
     #but only for variables that are produced in the old block and needed in



More information about the Pypy-commit mailing list