def define_nopython_lowering_pipeline(state, name='nopython_lowering'): pm = PassManager(name) # legalise pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") # lower pm.add_pass(NoPythonBackend, "nopython mode backend") pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics") pm.finalize() return pm
def define_cuda_lowering_pipeline(self, state): pm = PassManager('cuda_lowering') # legalise pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") # lower pm.add_pass(NativeLowering, "native lowering") pm.add_pass(CUDABackend, "cuda backend") pm.finalize() return pm
def define_pipelines(self): dpb = DefaultPassBuilder pm = PassManager('cuda') untyped_passes = dpb.define_untyped_pipeline(self.state) pm.passes.extend(untyped_passes.passes) typed_passes = dpb.define_typed_pipeline(self.state) pm.passes.extend(typed_passes.passes) lowering_passes = self.define_cuda_lowering_pipeline(self.state) pm.passes.extend(lowering_passes.passes) pm.finalize() return [pm]
def define_nopython_pipeline(state, name='nopython'): """Returns an nopython mode pipeline based PassManager """ # compose pipeline from untyped, typed and lowering parts dpb = DefaultPassBuilder pm = PassManager(name) untyped_passes = dpb.define_untyped_pipeline(state) pm.passes.extend(untyped_passes.passes) typed_passes = dpb.define_typed_pipeline(state) pm.passes.extend(typed_passes.passes) lowering_passes = dpb.define_nopython_lowering_pipeline(state) pm.passes.extend(lowering_passes.passes) pm.finalize() return pm
def define_interpreted_pipeline(state, name="interpreted"): """Returns an interpreted mode pipeline based PassManager """ pm = PassManager(name) pm.add_pass(CompileInterpMode, "compiling with interpreter mode") pm.finalize() return pm
def define_objectmode_pipeline(state, name='object'): """Returns an object-mode pipeline based PassManager """ pm = PassManager(name) if state.func_ir is None: pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") else: # Reaches here if it's a fallback from nopython mode. # Strip the phi nodes. pm.add_pass(PreLowerStripPhis, "remove phis nodes") pm.add_pass(IRProcessing, "processing IR") if utils.PYVERSION >= (3, 7): # The following passes are needed to adjust for looplifting pm.add_pass(CanonicalizeLoopEntry, "canonicalize loop entry") pm.add_pass(CanonicalizeLoopExit, "canonicalize loop exit") pm.add_pass(ObjectModeFrontEnd, "object mode frontend") pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures") # convert any remaining closures into functions pm.add_pass(MakeFunctionToJitFunction, "convert make_function into JIT functions") pm.add_pass(AnnotateTypes, "annotate types") pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") pm.add_pass(ObjectModeBackEnd, "object mode backend") pm.finalize() return pm
def define_untyped_pipeline(state, name='untyped'): """Returns an untyped part of the nopython pipeline""" pm = PassManager(name) if state.func_ir is None: pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(WithLifting, "Handle with contexts") # pre typing if not state.flags.no_rewrites: pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants") pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(GenericRewrites, "nopython rewrites") pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures") # convert any remaining closures into functions pm.add_pass(MakeFunctionToJitFunction, "convert make_function into JIT functions") # inline functions that have been determined as inlinable and rerun # branch pruning, this needs to be run after closures are inlined as # the IR repr of a closure masks call sites if an inlinable is called # inside a closure pm.add_pass(InlineInlinables, "inline inlinable functions") if not state.flags.no_rewrites: pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(FindLiterallyCalls, "find literally calls") pm.add_pass(LiteralUnroll, "handles literal_unroll") if state.flags.enable_ssa: pm.add_pass(ReconstructSSA, "ssa") pm.finalize() return pm
def define_typed_pipeline(state, name="typed"): """Returns the typed part of the nopython pipeline""" pm = PassManager(name) # typing pm.add_pass(NopythonTypeInference, "nopython frontend") pm.add_pass(AnnotateTypes, "annotate types") # strip phis pm.add_pass(PreLowerStripPhis, "remove phis nodes") # optimisation pm.add_pass(InlineOverloads, "inline overloaded functions") if state.flags.auto_parallel.enabled: pm.add_pass(PreParforPass, "Preprocessing for parfors") if not state.flags.no_rewrites: pm.add_pass(NopythonRewrites, "nopython rewrites") if state.flags.auto_parallel.enabled: pm.add_pass(ParforPass, "convert to parfors") pm.finalize() return pm
def define_pipelines(self): name = 'test parfor aliasing' pm = PassManager(name) pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(WithLifting, "Handle with contexts") # pre typing if not self.state.flags.no_rewrites: pm.add_pass(GenericRewrites, "nopython rewrites") pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants") pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures") # typing pm.add_pass(NopythonTypeInference, "nopython frontend") pm.add_pass(AnnotateTypes, "annotate types") # lower pm.add_pass(NoPythonBackend, "nopython mode backend") pm.finalize() return [pm]
def define_pipelines(self): name = 'bad_DCE_pipeline' pm = PassManager(name) pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") # remove dead before type inference so that the Arg node is # removed and the location of the arg cannot be found pm.add_pass(DeadCodeElimination, "DCE") # typing pm.add_pass(NopythonTypeInference, "nopython frontend") pm.add_pass(NativeLowering, "native lowering") pm.add_pass(NoPythonBackend, "nopython mode backend") pm.finalize() return [pm]
def define_pipelines(self): pm = PassManager("testing pm") pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(RemoveVarInScope, "_remove_var_in_scope") pm.add_pass(ReconstructSSA, "ssa") pm.add_pass(FailPass, "_fail") pm.finalize() return [pm]
def define_nopython_pipeline(state, name='nopython'): """Returns an nopython mode pipeline based PassManager """ pm = PassManager(name) if state.func_ir is None: pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(WithLifting, "Handle with contexts") # pre typing if not state.flags.no_rewrites: pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants") pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(GenericRewrites, "nopython rewrites") pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures") # convert any remaining closures into functions pm.add_pass(MakeFunctionToJitFunction, "convert make_function into JIT functions") # inline functions that have been determined as inlinable and rerun # branch pruning, this needs to be run after closures are inlined as # the IR repr of a closure masks call sites if an inlinable is called # inside a closure pm.add_pass(InlineInlinables, "inline inlinable functions") if not state.flags.no_rewrites: pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(FindLiterallyCalls, "find literally calls") pm.add_pass(LiteralUnroll, "handles literal_unroll") # typing pm.add_pass(NopythonTypeInference, "nopython frontend") pm.add_pass(AnnotateTypes, "annotate types") # optimisation pm.add_pass(InlineOverloads, "inline overloaded functions") if state.flags.auto_parallel.enabled: pm.add_pass(PreParforPass, "Preprocessing for parfors") if not state.flags.no_rewrites: pm.add_pass(NopythonRewrites, "nopython rewrites") if state.flags.auto_parallel.enabled: pm.add_pass(ParforPass, "convert to parfors") # legalise pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") # lower pm.add_pass(NoPythonBackend, "nopython mode backend") pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics") pm.finalize() return pm
def run_pass(self, state): # run as subpipeline from numba.core.compiler_machinery import PassManager pm = PassManager("subpipeline") pm.add_pass(PartialTypeInference, "performs partial type inference") pm.finalize() pm.run(state) mutated = False func_ir = state.func_ir for block in func_ir.blocks.values(): for assign in block.find_insts(ir.Assign): binop = assign.value if not (isinstance(binop, ir.Expr) and binop.op == 'binop'): continue if self.is_dtype_comparison(func_ir, binop): var = func_ir.get_assignee(binop) typ = state.typemap.get(var.name, None) if isinstance(typ, types.BooleanLiteral): loc = binop.loc rhs = ir.Const(typ.literal_value, loc) new_assign = ir.Assign(rhs, var, loc) # replace instruction block.insert_after(new_assign, assign) block.remove(assign) mutated = True if mutated: pm = PassManager("subpipeline") # rewrite consts / dead branch pruning pm.add_pass(DeadCodeElimination, "dead code elimination") pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants") pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.finalize() pm.run(state) return mutated
def define_nopython_lowering_pipeline(state, name='nopython_lowering'): pm = PassManager(name) # legalise pm.add_pass(NoPythonSupportedFeatureValidation, "ensure features that are in use are in a valid form") pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") # Annotate only once legalized pm.add_pass(AnnotateTypes, "annotate types") # lower pm.add_pass(NativeLowering, "native lowering") pm.add_pass(NoPythonBackend, "nopython mode backend") pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics") pm.finalize() return pm
def compile_to_ir(self, func, DCE=False): """ Compile and return IR """ func_id = bytecode.FunctionIdentity.from_function(func) self.state.func_id = func_id ExtractByteCode().run_pass(self.state) state = self.state name = "DCE_testing" pm = PassManager(name) pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(NopythonTypeInference, "nopython frontend") if DCE is True: pm.add_pass(DeadCodeElimination, "DCE after typing") pm.finalize() pm.run(state) return state.func_ir
def gen_pipeline(state, test_pass): name = 'inline_test' pm = PassManager(name) pm.add_pass(TranslateByteCode, "analyzing bytecode") pm.add_pass(FixupArgs, "fix up args") pm.add_pass(IRProcessing, "processing IR") pm.add_pass(WithLifting, "Handle with contexts") # pre typing if not state.flags.no_rewrites: pm.add_pass(GenericRewrites, "nopython rewrites") pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants") pm.add_pass(DeadBranchPrune, "dead branch pruning") pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures") # typing pm.add_pass(NopythonTypeInference, "nopython frontend") pm.add_pass(AnnotateTypes, "annotate types") if state.flags.auto_parallel.enabled: pm.add_pass(PreParforPass, "Preprocessing for parfors") if not state.flags.no_rewrites: pm.add_pass(NopythonRewrites, "nopython rewrites") if state.flags.auto_parallel.enabled: pm.add_pass(ParforPass, "convert to parfors") pm.add_pass(test_pass, "inline test") # legalise pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") pm.add_pass(PreserveIR, "preserve IR") # lower pm.add_pass(NoPythonBackend, "nopython mode backend") pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics") return pm
def define_nopython_pipeline(state, name="dppy_nopython"): """Returns an nopython mode pipeline based PassManager""" pm = PassManager(name) DPPYPassBuilder.default_numba_nopython_pipeline(state, pm) # Intel GPU/CPU specific optimizations pm.add_pass(DPPYPreParforPass, "Preprocessing for parfors") if not state.flags.no_rewrites: pm.add_pass(NopythonRewrites, "nopython rewrites") pm.add_pass(DPPYParforPass, "convert to parfors") # legalise pm.add_pass( NoPythonSupportedFeatureValidation, "ensure features that are in use are in a valid form", ) pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering") # lower pm.add_pass(SpirvFriendlyLowering, "SPIRV-friendly lowering pass") pm.add_pass(DPPYNoPythonBackend, "nopython mode backend") pm.add_pass(DPPYDumpParforDiagnostics, "dump parfor diagnostics") pm.finalize() return pm