Commits

Alex Gaynor committed e2ecbb5

general cleanup of random stuff in backendopt

  • Participants
  • Parent commits da703a5

Comments (0)

Files changed (13)

File pypy/translator/backendopt/canraise.py

-from pypy.translator.simplify import get_graph
-from pypy.rpython.lltypesystem.lloperation import llop, LL_OPERATIONS
-from pypy.rpython.lltypesystem import lltype
+import py
+
+from pypy.rpython.lltypesystem.lloperation import LL_OPERATIONS
+from pypy.tool.ansi_print import ansi_log
 from pypy.translator.backendopt import graphanalyze
 from pypy.translator.simplify import get_funcobj
 
-import py
-from pypy.tool.ansi_print import ansi_log
-log = py.log.Producer("canraise") 
-py.log.setconsumer("canraise", ansi_log) 
+log = py.log.Producer("canraise")
+py.log.setconsumer("canraise", ansi_log)
+
 
 class RaiseAnalyzer(graphanalyze.BoolGraphAnalyzer):
     def analyze_simple_operation(self, op, graphinfo):

File pypy/translator/backendopt/constfold.py

-from pypy.objspace.flow.model import Constant, Variable, SpaceOperation
-from pypy.objspace.flow.model import c_last_exception
-from pypy.objspace.flow.model import mkentrymap
-from pypy.translator.backendopt.support import log
-from pypy.translator.simplify import eliminate_empty_blocks
+from pypy.objspace.flow.model import (Constant, Variable, SpaceOperation,
+    c_last_exception, mkentrymap)
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.translator.unsimplify import insert_empty_block, split_block
-from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rpython.lltypesystem import lltype
 
 
 def fold_op_list(operations, constants, exit_early=False, exc_catch=False):
                     pass
                 except (KeyboardInterrupt, SystemExit):
                     raise
-                except Exception, e:
+                except Exception:
                     pass   # turn off reporting these as warnings: useless
                     #log.WARNING('constant-folding %r:' % (spaceop,))
                     #log.WARNING('  %s: %s' % (e.__class__.__name__, e))
 def constant_fold_block(block):
     constants = {}
     block.operations = fold_op_list(block.operations, constants,
-                           exc_catch = block.exitswitch == c_last_exception)
+                           exc_catch=block.exitswitch == c_last_exception)
     if constants:
         if block.exitswitch in constants:
             switch = constants[block.exitswitch].value
         if same_as:
             constant_fold_block(block)
     return count
-                
+
 def constant_fold_graph(graph):
     # first fold inside the blocks
     for block in graph.iterblocks():
                     constants[v2] = v1
             if constants:
                 prepare_constant_fold_link(link, constants, splitblocks)
-        if  splitblocks:
+        if splitblocks:
             rewire_links(splitblocks, graph)
         if not diffused and not splitblocks:
             break # finished

File pypy/translator/backendopt/escape.py

-from pypy.objspace.flow.model import Variable, Constant
+from pypy.objspace.flow.model import Variable
 from pypy.rpython.lltypesystem import lltype
 from pypy.translator.simplify import get_graph
-from pypy.rpython.rmodel import inputconst
-from pypy.translator.backendopt import support
 from pypy.tool.uid import uid
 
+
 class CreationPoint(object):
     def __init__(self, creation_method, TYPE, op=None):
         self.escapes = False
 
     def seen_graphs(self):
         return self.functionargs.keys()
-    
+
     def getstate(self, var_or_const):
         if not isonheap(var_or_const):
             return None
             varstate = VarState(crep)
         self.varstates[var_or_const] = varstate
         return varstate
-            
+
     def getstates(self, varorconstlist):
         return [self.getstate(var) for var in varorconstlist]
-    
+
     def setstate(self, var, state):
         self.varstates[var] = state
-    
+
     def get_creationpoint(self, var, method="?", op=None):
         if var in self.creationpoints:
             return self.creationpoints[var]
         crep = CreationPoint(method, var.concretetype, op)
         self.creationpoints[var] = crep
         return crep
-    
+
     def schedule_function(self, graph):
         startblock = graph.startblock
         if graph in self.functionargs:
             return
         self.curr_block = block
         self.curr_graph = graph
-        
+
         for op in block.operations:
             self.flow_operation(op)
         for exit in block.exits:
 
     def flow_operation(self, op):
         args = self.getstates(op.args)
-        opimpl = getattr(self, 'op_'+op.opname, None)
+        opimpl = getattr(self, 'op_' + op.opname, None)
         if opimpl is not None:
             res = opimpl(op, *args)
             if res is not NotImplemented:
                 self.setstate(op.result, res)
                 return
-            
+
         if isonheap(op.result) or filter(None, args):
             for arg in args:
                 if arg is not None:
                     self.escapes(arg)
-        
+
     def complete(self):
         while self.scheduled:
             block, graph = self.scheduled.popitem()
 
     def op_cast_pointer(self, op, state):
         return state
-    
+
     def op_setfield(self, op, objstate, fieldname, valuestate):
         if valuestate is not None:
             # be pessimistic for now:
     def op_getarrayitem(self, op, objstate, indexstate):
         if isonheap(op.result):
             return VarState(self.get_creationpoint(op.result, "getarrayitem", op))
-    
+
     def op_getfield(self, op, objstate, fieldname):
         if isonheap(op.result):
             # assume that getfield creates a new value
     seen = {}
     return [graph for graph in adi.seen_graphs()
         if is_malloc_like(adi, graph, seen)]
-
-
-

File pypy/translator/backendopt/finalizer.py

     ok_operations = ['ptr_nonzero', 'ptr_eq', 'ptr_ne', 'free', 'same_as',
                      'direct_ptradd', 'force_cast', 'track_alloc_stop',
                      'raw_free']
-    
+
     def analyze_light_finalizer(self, graph):
         result = self.analyze_direct_call(graph)
         if (result is self.top_result() and
             getattr(graph.func, '_must_be_light_finalizer_', False)):
             raise FinalizerError(FinalizerError.__doc__, graph)
         return result
-    
+
     def analyze_simple_operation(self, op, graphinfo):
         if op.opname in self.ok_operations:
             return self.bottom_result()
             TP = op.result.concretetype
             if not isinstance(TP, lltype.Ptr) or TP.TO._gckind == 'raw':
                 # primitive type
-                return self.bottom_result()            
+                return self.bottom_result()
         return self.top_result()

File pypy/translator/backendopt/merge_if_blocks.py

-from pypy.objspace.flow.model import Block, Constant, Variable
-from pypy.objspace.flow.model import checkgraph, mkentrymap
+from pypy.objspace.flow.model import Constant, Variable, checkgraph, mkentrymap
 from pypy.translator.backendopt.support import log
 
 log = log.mergeifblocks
         return varmap[var_or_const]
     firstblock, case = chain[0]
     firstblock.operations = firstblock.operations[:-1]
-    firstblock.exitswitch = checkvar 
+    firstblock.exitswitch = checkvar
     values = {}
     links = []
     default = chain[-1][0].exits[0]

File pypy/translator/backendopt/raisingop2direct_call.py

 from pypy.translator.backendopt.support import log, all_operations, annotate
 import pypy.rpython.raisingops.raisingops
+
+
 log = log.raisingop2directcall
 
 def is_raisingop(op):
     if graphs is None:
         graphs = translator.graphs
 
-
     log('starting')
     seen = {}
     for op in all_operations(graphs):
         translator.rtyper.specialize_more_blocks()
 
     #rename some operations (that were introduced in the newly specialized graphs)
-    #so this transformation becomes idempotent... 
+    #so this transformation becomes idempotent...
     #for op in all_operations(graphs):
     #   if op.opname in special_operations:
     #       log('renamed %s to %s_' % (op.opname, op.opname))
-    #       op.opname += '_' 
+    #       op.opname += '_'
 
     #selfdiagnostics... assert that there are no more raisingops
     for op in all_operations(graphs):

File pypy/translator/backendopt/removeassert.py

 from pypy.objspace.flow.model import Constant, checkgraph, c_last_exception
+from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rtyper import LowLevelOpList, inputconst
+from pypy.translator.backendopt.support import log
 from pypy.translator.simplify import eliminate_empty_blocks, join_blocks
-#from pypy.translator.simplify import transform_dead_op_vars
-from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.lltypesystem import rclass
-from pypy.translator.backendopt.support import log
 
 
 def remove_asserts(translator, graphs):
             if translator.config.translation.verbose:
                 log.removeassert("removed %d asserts in %s" % (count, graph.name))
             checkgraph(graph)
-            #transform_dead_op_vars(graph, translator)
     total_count = tuple(total_count)
     if total_count[0] == 0:
         if total_count[1] == 0:
             newops = LowLevelOpList()
             if link.exitcase:
                 v = newops.genop('bool_not', [block.exitswitch],
-                                 resulttype = lltype.Bool)
+                                 resulttype=lltype.Bool)
             else:
                 v = block.exitswitch
             msg = "assertion failed in %s" % (graph.name,)

File pypy/translator/backendopt/removenoops.py

-from pypy.objspace.flow.model import Block, Variable, Constant
-from pypy.rpython.lltypesystem.lltype import Void
+from pypy.objspace.flow.model import Variable, Constant
 from pypy.translator.backendopt.support import log
 from pypy.translator import simplify
-from pypy import conftest
+
 
 def remove_unaryops(graph, opnames):
     """Removes unary low-level ops with a name appearing in the opnames list.
                 simplify.replace_exitswitch_by_constant(block, op_arg)
         block.operations[index] = None
         touched_blocks.add(block)
-        
+
     # remove all operations
     for block in touched_blocks:
         if block.operations:

File pypy/translator/backendopt/ssa.py

-from pypy.objspace.flow.model import Variable, mkentrymap, Block
+from pypy.objspace.flow.model import Variable, mkentrymap
 from pypy.tool.algo.unionfind import UnionFind
 
 class DataFlowFamilyBuilder:

File pypy/translator/backendopt/storesink.py

                 del cache[k]
 
     added_some_same_as = False
-    
+
     for block in graph.iterblocks():
         newops = []
         cache = {}

File pypy/translator/backendopt/support.py

 import py
+
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.rmodel import inputconst
+from pypy.tool.ansi_print import ansi_log
 from pypy.translator.simplify import get_graph
-from pypy.rpython.rmodel import inputconst 
-from pypy.tool.ansi_print import ansi_log
-from pypy.annotation.model import s_ImpossibleValue
-from pypy.translator.unsimplify import split_block, copyvar, insert_empty_block
-from pypy.objspace.flow.model import Constant, Variable, SpaceOperation, c_last_exception
-from pypy.rpython.lltypesystem import lltype
 
 
 log = py.log.Producer("backendopt")
 
 def graph_operations(graph):
     for block in graph.iterblocks():
-        for op in block.operations: 
+        for op in block.operations:
             yield op
 
 def all_operations(graphs):
     for graph in graphs:
         for block in graph.iterblocks():
-            for op in block.operations: 
+            for op in block.operations:
                 yield op
 
 def annotate(translator, func, result, args):
     args   = [arg.concretetype for arg in args]
     graph  = translator.rtyper.annotate_helper(func, args)
     fptr   = lltype.functionptr(lltype.FuncType(args, result.concretetype), func.func_name, graph=graph)
-    c      = inputconst(lltype.typeOf(fptr), fptr) 
+    c      = inputconst(lltype.typeOf(fptr), fptr)
     return c
 
 def var_needsgc(var):

File pypy/translator/backendopt/tailrecursion.py

             len(block.operations) > 0 and
             block.operations[-1].opname == 'direct_call' and
             block.operations[-1].result == link.args[0]):
-            call = get_graph(block.operations[-1].args[0], translator)
             print "getgraph", graph
             if graph is graph:
                 _remove_tail_call(translator, graph, block)

File pypy/translator/backendopt/test/test_tailrecursion.py

-from pypy.objspace.flow.model import Block, Link, Variable, Constant
+from pypy.rpython.llinterp import LLInterpreter
 from pypy.translator.backendopt.tailrecursion import remove_tail_calls_to_self
 from pypy.translator.translator import TranslationContext, graphof
-from pypy.rpython.llinterp import LLInterpreter
-from pypy.translator.test.snippet import is_perfect_number
+
 
 def test_recursive_gcd():
     def gcd(a, b):
     t.buildannotator().build_types(gcd, [int, int])
     t.buildrtyper().specialize()
     gcd_graph = graphof(t, gcd)
-    remove_tail_calls_to_self(t, gcd_graph )
+    remove_tail_calls_to_self(t, gcd_graph)
     lli = LLInterpreter(t.rtyper)
     res = lli.eval_graph(gcd_graph, (15, 25))
     assert res == 5