def transform(self): """To apply a polyhedral-syntactic transformation on the annotated code""" # remove all existing annotations annot_re = r"/\*@((.|\n)*?)@\*/" self.annot_body_code = re.sub(annot_re, "", self.annot_body_code) # insert polysyn tags self.annot_body_code = self.__insertPolysynTags(self.annot_body_code) # parse the orio.module.body code assigns = parser.Parser().parse(self.module_body_code, self.line_no) # extract transformation information from the specified assignments tinfo = transf_info.TransfInfoGen().generate(assigns, self.perf_params) # perform polyhedral transformations ptrans = poly_transformation.PolyTransformation( Globals().verbose, tinfo.parallel, tinfo.tiles) pluto_code = ptrans.transform(self.annot_body_code) # use a profiling tool (i.e. gprof) to get hotspots information prof = profiler.Profiler( Globals().verbose, tinfo.profiling_code, tinfo.compile_cmd, tinfo.compile_opts, ) hotspots_info = prof.getHotspotsInfo(pluto_code) # parse the Pluto code to extract hotspot loops pluto_code = cloop_parser.CLoopParser().getHotspotLoopNests( pluto_code, hotspots_info) # expand all macro-defined statements pluto_code = macro_expander.MacroExpander().replaceStatements( pluto_code) # perform syntactic transformations strans = syn_transformation.SynTransformation( Globals().verbose, tinfo.permut, tinfo.unroll_factors, tinfo.scalar_replace, tinfo.vectorize, tinfo.rect_regtile, ) transformed_code = strans.transform(pluto_code) # return the transformed code return transformed_code
def include_macro(*files): source = include(*[file.value for file in files]) sexp = parser.Parser(source).parse() expanded = macro_expander.MacroExpander(BUILTIN_MACROS, USER_DEFINED_MACROS).macro_expand(sexp) return bach_ast.Do(expanded.code)