7.10. Notes on Custom Pipelines

Warning

The custom pipeline feature is for expert use only. Modifying the compiler behavior can invalidate internal assumptions in the numba source code.

For library developers looking for a way to extend or modify the compiler behavior, you can do so by defining a custom compiler pipeline by inheriting from numba.compiler.BasePipeline. The default numba pipeline is defined as numba.compiler.Pipeline, implementing the .define_pipelines() method, which adds the nopython-mode, object-mode and interpreted-mode pipelines. These three pipelines are defined in BasePipeline by the methods .define_nopython_pipeline, .define_objectmode_pipeline and .define_interpreted_pipeline, respectively..

To use a custom subclass of BasePipeline, supply it as the pipeline_class keyword argument to the @jit and @generated_jit decorators. By doing so, the effect of the custom pipeline is limited to the function being decorated.

Below are the common methods available to implementors of the BasePipeline class:

class numba.compiler.BasePipeline(typingctx, targetctx, library, args, return_type, flags, locals)

Stores and manages states for the compiler pipeline

add_cleanup_stage(pm)

Add the clean-up stage to remove intermediate results.

add_lowering_stage(pm)

Add the lowering (code-generation) stage for nopython-mode

add_optimization_stage(pm)

Add optimization stages.

add_pre_typing_stage(pm)

Add any stages that go before type-inference. The current stages contain type-agnostic rewrite passes.

add_preprocessing_stage(pm)

Add the preprocessing stage that analyzes the bytecode to prepare the Numba IR.

add_typing_stage(pm)

Add the type-inference stage necessary for nopython mode.

define_interpreted_pipeline(pm, name='interp')

Add the interpreted-mode (fallback) pipeline to the pipeline manager

define_nopython_pipeline(pm, name='nopython')

Add the nopython-mode pipeline to the pipeline manager

define_objectmode_pipeline(pm, name='object')

Add the object-mode pipeline to the pipeline manager