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:
FunctionPassManager
, for optimizations that work on single functions.ModulePassManager
, for optimizations that work on whole modules.
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 orPassManagerBuilder.populate()
to add optimization passes.-
add_constant_merge_pass
()¶
-
-
add_dead_arg_elimination_pass
()¶
-
-
add_function_attrs_pass
()¶
-
-
add_function_inlining_pass
(self)¶
-
-
add_global_dce_pass
()¶
-
-
add_global_optimizer_pass
()¶
-
-
add_ipsccp_pass
()¶
-
-
add_dead_code_elimination_pass
()¶
-
-
add_cfg_simplification_pass
()¶
-
-
add_gvn_pass
()¶
-
-
add_instruction_combining_pass
()¶
-
-
add_licm_pass
()¶
-
-
add_sccp_pass
()¶
-
-
add_sroa_pass
()¶ See scalarrepl pass documentation.
While the scalarrepl pass documentation describes the transformation performed by the pass added by this function, the pass corresponds to the
opt -sroa
command-line option and not toopt -scalarrepl
.
-
-
add_type_based_alias_analysis_pass
()¶
-
-
add_basic_alias_analysis_pass
()¶
-
-
class
llvmlite.binding.
ModulePassManager
¶ Create a new pass manager to run optimization passes on a module.
The
run
method is available: