Changeset 2208


Ignore:
Timestamp:
Jun 4, 2012, 8:46:03 PM (7 years ago)
Author:
cameron
Message:

pablo.Advance(pablo.Advane(x)) ==> pablo.Advance(x, 2) optimizer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r2206 r2208  
    5252    self.generic_visit(e)
    5353    return ast.Assign([e.target], ast.BinOp(e.target, e.op, e.value))
     54#
     55# pablo.Advance(pablo.Advance(x, n)) => pablo.Advance(x, n+1)
     56#
     57class AdvanceCombiner(ast.NodeTransformer):
     58  def xfrm(self, t):
     59    return self.generic_visit(t)
     60  def visit_if(self, ifNode):
     61    return IfNode
     62  def visit_While(self, whileNode):
     63    return whileNode
     64  def visit_Call(self, callnode):
     65    self.generic_visit(callnode)
     66    if not isinstance(callnode.args[0], ast.Call): return callnode
     67    if is_BuiltIn_Call(callnode,'Advance', 1):
     68        if is_BuiltIn_Call(callnode.args[0],'Advance', 1):
     69          callnode.args = [callnode.args[0].args[0], ast.Num(2)]
     70        elif is_BuiltIn_Call(callnode.args[0], 'Advance', 2):
     71          if isinstance(callnode.args[0].args[1], ast.Num):
     72            callnode.args = [callnode.args[0].args[0], ast.Num(callnode.args[0].args[1].n + 1)]
     73          else:
     74            callnode.args = [callnode.args[0].args[0], ast.BinOp(callnode.args[0].args[1], ast.Add(), ast.Num(1))]
     75    return callnode
    5476
    5577
     
    811833                StringMatchCompiler().xfrm(node)
    812834                AssertCompiler().xfrm(node)
     835                AdvanceCombiner().xfrm(node)
    813836                AugAssignRemoval().xfrm(node)
    814837                Bitwise_to_SIMD().xfrm(node)
     
    884907    StringMatchCompiler().xfrm(self.main_node)
    885908    AugAssignRemoval().xfrm(self.main_node)
     909    AdvanceCombiner().xfrm(self.main_node)
    886910    Bitwise_to_SIMD().xfrm(self.main_node)
    887911    Bitwise_to_SIMD().xfrm(self.main_node)
Note: See TracChangeset for help on using the changeset viewer.