def generic_visit(self, node): if isinstance(node, ast.expr) and node in self.constant_expressions: fake_node = ast.Expression(node) code = compile(ast.gast_to_ast(fake_node), '<constant folding>', 'eval') try: value = eval(code, self.env) new_node = to_ast(value) if not ASTMatcher(node).match(new_node): self.update = True return new_node except DamnTooLongPattern as e: print("W: ", e, " Assume no update happened.") except ConversionError as e: print('error in constant folding: ', e) raise except ToNotEval: pass except AttributeError as e: # this may miss a few optimization logger.info('During constant folding, bailing out due to: ' + e.args[0]) except NameError as e: # FIXME dispatched function are not processed by constant # folding if "__dispatch__" in e.args[0]: return Transformation.generic_visit(self, node) # this may miss a few optimization logger.info('During constant folding, bailing out due to: ' + e.args[0]) except Exception as e: raise PythranSyntaxError(str(e), node) return Transformation.generic_visit(self, node)
def generic_visit(self, node): if node in self.constant_expressions: try: fake_node = ast.Expression(node.value if isinstance(node, ast.Index) else node) code = compile(fake_node, "<constant folding>", "eval") value = eval(code, self.env) new_node = self.to_ast(value) if isinstance(node, ast.Index) and not isinstance(new_node, ast.Index): new_node = ast.Index(new_node) return new_node except ConstantFolding.ConversionError as e: print ast.dump(node) print "error in constant folding: ", e raise except ConstantFolding.ToNotEval: return Transformation.generic_visit(self, node) except AttributeError as e: # FIXME union_ function is not handle by constant folding if "union_" in e.args[0]: return Transformation.generic_visit(self, node) raise except NameError as e: # FIXME dispatched function are not processed by constant # folding if "__dispatch__" in e.args[0]: return Transformation.generic_visit(self, node) raise else: return Transformation.generic_visit(self, node)
def __init__(self, pm, name, ctx, lambdas, imports, global_decls): Transformation.__init__(self) self.passmanager = pm self.ctx = ctx self.prefix = name self.lambda_functions = lambdas self.imports = imports self.global_declarations = global_decls
def __init__(self, pm, name, ctx, lambda_functions, imports): Transformation.__init__(self) self.passmanager = pm self.ctx = ctx self.prefix = name self.lambda_functions = lambda_functions self.imports = imports self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
def generic_visit(self, node): if node in self.constant_expressions: try: fake_node = ast.Expression( node.value if isinstance(node, ast.Index) else node) code = compile(fake_node, '<constant folding>', 'eval') value = eval(code, self.env) new_node = self.to_ast(value) if (isinstance(node, ast.Index) and not isinstance(new_node, ast.Index)): new_node = ast.Index(new_node) return new_node except Exception: # as e: #print ast.dump(node) #print 'error in constant folding: ', e return Transformation.generic_visit(self, node) else: return Transformation.generic_visit(self, node)
def generic_visit(self, node): if node in self.constant_expressions: try: fake_node = ast.Expression( node.value if isinstance(node, ast.Index) else node) code = compile(fake_node, '<constant folding>', 'eval') value = eval(code, self.env) new_node = to_ast(value) if(isinstance(node, ast.Index) and not isinstance(new_node, ast.Index)): new_node = ast.Index(new_node) try: if not ASTMatcher(node).search(new_node): self.update = True except DamnTooLongPattern as e: print "W: ", e, " Assume no update happened." return new_node except ConversionError as e: print ast.dump(node) print 'error in constant folding: ', e raise except ToNotEval: return Transformation.generic_visit(self, node) except AttributeError as e: # FIXME union_ function is not handle by constant folding if "union_" in e.args[0]: return Transformation.generic_visit(self, node) elif "pythran" in e.args[0]: # FIXME: Can be fix giving a Python implementation for # these functions. return Transformation.generic_visit(self, node) raise except NameError as e: # FIXME dispatched function are not processed by constant # folding if "__dispatch__" in e.args[0]: return Transformation.generic_visit(self, node) raise else: return Transformation.generic_visit(self, node)
def generic_visit(self, node): if node in self.constant_expressions: try: fake_node = ast.Expression( node.value if isinstance(node, ast.Index) else node) code = compile(fake_node, '<constant folding>', 'eval') value = eval(code, self.env) new_node = to_ast(value) if (isinstance(node, ast.Index) and not isinstance(new_node, ast.Index)): new_node = ast.Index(new_node) try: if not ASTMatcher(node).search(new_node): self.update = True except DamnTooLongPattern as e: print "W: ", e, " Assume no update happened." return new_node except ConversionError as e: print ast.dump(node) print 'error in constant folding: ', e raise except ToNotEval: return Transformation.generic_visit(self, node) except AttributeError as e: # FIXME union_ function is not handle by constant folding if "union_" in e.args[0]: return Transformation.generic_visit(self, node) elif "pythran" in e.args[0]: # FIXME: Can be fix giving a Python implementation for # these functions. return Transformation.generic_visit(self, node) raise except NameError as e: # FIXME dispatched function are not processed by constant # folding if "__dispatch__" in e.args[0]: return Transformation.generic_visit(self, node) raise else: return Transformation.generic_visit(self, node)
def __init__(self): self.count = 0 Transformation.__init__(self)
def __init__(self): Transformation.__init__(self, NormalizeTuples, OptimizableComprehension)
def __init__(self): Transformation.__init__(self, OptimizableComprehension)
def __init__(self): """ Basic initialiser. """ Transformation.__init__(self) self.imports = set() self.symbols = dict()
def __init__(self): Transformation.__init__(self)
def __init__(self): Transformation.__init__(self, Identifiers)
def __init__(self): Transformation.__init__(self, RangeValues)
def __init__(self): """ Gather required information. """ Transformation.__init__(self, PotentialIterator, Aliases)
def __init__(self): Transformation.__init__(self, NormalizeTuples, PotentialIterator)
def __init__(self): Transformation.__init__(self, PotentialIterator, Aliases)
def __init__(self): Transformation.__init__(self) self.imports = set() self.symbols = dict()
def __init__(self, pm, ctx, global_declarations): Transformation.__init__(self) self.ctx = ctx self.passmanager = pm self.global_declarations = global_declarations self.identifiers = set(self.global_declarations.keys())
def __init__(self): Transformation.__init__(self) # Remap self.visit_XXXX() to self.attach_data() generic method for s in GatherOMPData.statements: setattr(self, "visit_" + s, self.attach_data) self.current = list()
def __init__(self, pm, ctx, global_declarations): Transformation.__init__(self) self.ctx = ctx self.passmanager = pm self.global_declarations = global_declarations
def __init__(self): self.renamings = dict() Transformation.__init__(self, Identifiers)
def __init__(self, pm, ctx): Transformation.__init__(self) self.ctx = ctx self.passmanager = pm self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
def __init__(self): Transformation.__init__(self, UseDefChains, Ancestors, Aliases, RangeValues, Identifiers) self.loops_mod = dict()
def visit_Call(self, node): if isinstance(node.func, ast.Attribute): return self.generic_visit(node) else: return Transformation.generic_visit(self, node)
def __init__(self): Transformation.__init__(self, UseDefChain, Ancestors, Aliases, RangeValues, Identifiers) self.loops_mod = dict()
def __init__(self): Transformation.__init__(self, Globals) self.imports = {'__builtin__': '__builtin__'} self.to_import = set()
def __init__(self): Transformation.__init__(self, Globals, Ancestors) self.imports = {'builtins': 'builtins'} self.to_import = set()
def __init__(self): Transformation.__init__(self, TypeDependencies, OrderedGlobalDeclarations)
def __init__(self): Transformation.__init__(self, Locals, Globals)
def __init__(self): Transformation.__init__(self, PotentialIterator)
def __init__(self): Transformation.__init__(self, Aliases, ConstantExpressions, PureExpressions)
def __init__(self): Transformation.__init__(self, ConstantExpressions)
def __init__(self): Transformation.__init__(self, Globals) self.imports = set() self.to_import = set()
def __init__(self): """Gather required information.""" Transformation.__init__(self, PotentialIterator, Aliases) self.use_itertools = False
def __init__(self): Transformation.__init__(self, Aliases, PureExpressions)