def transform(self): '''To apply loop transformations on the annotated code''' # parse the code to get the AST stmts = parser.getParser(self.line_no).parse(self.module_body_code) if isinstance(stmts[0], ast.TransformStmt) and stmts[0].stmt is None: # transform the enclosed annot_body_code annotated_stmts = parser.getParser(self.line_no).parse( self.annot_body_code) if len(annotated_stmts) == 1: annotated_stmt = annotated_stmts[0] else: annotated_stmt = ast.CompStmt(annotated_stmts[0]) stmts[0].stmt = annotated_stmt # apply transformations t = transformation.Transformation(self.perf_params, self.verbose, self.language, self.tinfo) transformed_stmts = t.transform(stmts) # generate code for the transformed ASTs indent = ' ' * self.indent_size extra_indent = ' ' cgen = codegen.CodeGen(self.language) transformed_code = '\n' for s in transformed_stmts: transformed_code += cgen.generate(s, indent, extra_indent) # return the transformed code return transformed_code
def show_code(ast, symtab): print "\n------------------- code ---------------------" try: c = codegen.CodeGen() c.process(ast, symtab) c.construct() except: print "Codegen did not gen the code." if verbose: traceback.print_exc()
def transform(self): '''To apply an SpMV transformation on the annotated code''' # parse the orio.module.body code args = parser.Parser().parse(self.module_body_code, self.line_no) # generate the input argument information ainfo = arg_info.ArgInfoGen().generate(args, self.perf_params) # generate the optimized code optimized_code = codegen.CodeGen(ainfo).generate() # return the optimized code return optimized_code
def transform(self): '''To apply a memory-alignment transformation on the annotated code''' # parse the annotation orio.module.code to get the variables to be checked vars = parser.getParser(self.line_no).parse(self.module_body_code) # perform a semantic check for v in vars: v.semantCheck() # generate the alignment optimization code indent = ' ' * self.indent_size transformed_code = codegen.CodeGen(vars, self.annot_body_code, indent, self.language).generate() # return the transformed code return transformed_code
def transform(self): '''To apply loop transformations on the annotated code''' # parse the code to get the AST stmts = parser.getParser(self.line_no).parse(self.module_body_code) if isinstance(stmts[0], ast.TransformStmt) and stmts[0].stmt is None: # transform the enclosed annot_body_code annotated_stmts = parser.getParser(self.line_no).parse( self.annot_body_code) if len(annotated_stmts) == 1: annotated_stmt = annotated_stmts[0] else: annotated_stmt = ast.CompStmt(annotated_stmts[0]) stmts[0].stmt = annotated_stmt # apply transformations t = transformation.Transformation(self.perf_params, self.verbose, self.language, self.tinfo) transformed_stmts = t.transform(stmts) # generate code for the transformed ASTs indent = ' ' * self.indent_size extra_indent = ' ' cgen = codegen.CodeGen(self.language) transformed_code = '\n' for s in transformed_stmts: transformed_code += cgen.generate(s, indent, extra_indent) # Example on applying another visitor, e.g., for analysis #exampleVisitor = astvisitors.ExampleVisitor() #exampleVisitor.visit(transformed_stmts) # Count operations visitor opsVisitor = astvisitors.CountingVisitor() opsVisitor.visit(transformed_stmts) debug(str(opsVisitor), level=3) # CFG if True: try: from orio.module.loop.cfg import CFGGraph cfg = CFGGraph(transformed_stmts) except Exception, e: err('[module.loop.loop] cannot construct CFG: ', e)
def transform(self): '''To apply loop transformations on the annotated code''' # parse the code to get the AST stmts = parser.getParser(self.line_no).parse(self.module_body_code) # apply transformations t = transformator.Transformator(self.perf_params, self.verbose) transformed_stmts = t.transform(stmts) # generate code for the transformed ASTs indent = ' ' * self.indent_size extra_indent = ' ' cgen = codegen.CodeGen() transformed_code = '' for s in transformed_stmts: transformed_code += cgen.generate(s, indent, extra_indent) # return the transformed code return transformed_code
def __repr__(self): '''Return a string representation for this AST object''' return codegen.CodeGen().generate(self)