Optimization passes

LLVM gives you the opportunity to fine-tune optimization passes. Optimization passes are managed by a pass manager. There are 2 kinds of pass managers:

To instantiate either of these pass managers, you first need to create and configure a PassManagerBuilder.

class llvmlite.binding.PassManagerBuilder

Create a new pass manager builder. This object centralizes optimization settings.

The populate method is available:

populate(pm)

Populate the pass manager pm with the optimization passes configured in this pass manager builder.

The following writable attributes are available:

  • disable_unroll_loops

    If True, disable loop unrolling.

  • inlining_threshold

    The integer threshold for inlining one function into another. The higher the number, the more likely that inlining will occur. This attribute is write-only.

  • loop_vectorize

    If True, allow vectorizing loops.

  • opt_level

    The general optimization level, as an integer between 0 and 3.

  • size_level

    Whether and how much to optimize for size, as an integer between 0 and 2.

  • slp_vectorize

    If True, enable the SLP vectorizer, which uses a different algorithm than the loop vectorizer. Both may be enabled at the same time.

class llvmlite.binding.PassManager

The base class for pass managers. Use individual add_* methods or PassManagerBuilder.populate() to add optimization passes.

class llvmlite.binding.ModulePassManager

Create a new pass manager to run optimization passes on a module.

The run method is available:

run(module)

Run optimization passes on the module, a ModuleRef instance.

Returns True if the optimizations made any modification to the module. Otherwise returns False.

class llvmlite.binding.FunctionPassManager(module)

Create a new pass manager to run optimization passes on a function of the given module, a ModuleRef instance.

The following methods are available:

  • finalize()

    Run all the finalizers of the optimization passes.

  • initialize()

    Run all the initializers of the optimization passes.

  • run(function)

    Run optimization passes on function, a ValueRef instance.

    Returns True if the optimizations made any modification to the module. Otherwise returns False.