Optimization
This section documents the optimization libraries under lib/Optimization/.
They complement the transformation utilities in Transforms and
provide both standalone passes and reusable integration helpers.
Headers: include/Optimization/
Implementation: lib/Optimization/
Subdirectories
Pipeline/exposes a small API for running LLVM’s default O0-O3 pipelines.Scalar/contains LLVM-style scalar passes such as aggressive inlining, dead-store elimination, GVN, and LICM.IPO/contains interprocedural optimizations built on SeaDsa ShadowMem and Lotus MemorySSA instrumentation.PartialEvaluation/contains the LLPE specialization and partial evaluation subsystem.Prefetch/contains the profile-guided software prefetching pass.
ModuleOptimizer
Files: include/Optimization/Pipeline/ModuleOptimizer.h,
lib/Optimization/Pipeline/ModuleOptimizer.cpp
llvm_utils::optimiseModule runs LLVM’s default per-module optimization
pipeline using llvm::PassBuilder and an llvm::OptimizationLevel.
#include <Optimization/Pipeline/ModuleOptimizer.h>
llvm::Module *M = ...;
llvm_utils::optimiseModule(M, llvm::OptimizationLevel::O2);
Use it when a tool wants standard LLVM cleanup before running Lotus analyses or custom optimization passes.
Scalar passes
lib/Optimization/Scalar/ currently builds CanaryOptimizationScalar from
four passes:
AggressiveInliner(legacy pass nameainline)DSE/createDeadStoreEliminationPass()GVN/createGVNPass()LICM/createLICMPass()
See Scalar Optimizations for the pass-level details and available entry points.
Interprocedural MemorySSA optimizations
lib/Optimization/IPO/ contains four legacy ModulePass implementations
that operate on ShadowMem-instrumented IR:
IPDeadStoreEliminationremoves stores and some global initializers whose ShadowMem def-use chains never reach an observable load.IPRedundantLoadEliminationremoves repeated loads within a block when the pointer and TLVar are unchanged.IPStoreSinkingmoves stores closer to their first observable use within a basic block.IPStoreToLoadForwardingreplaces loads with a unique reaching store value found by traversing MemorySSA edges across calls and phis.
See Interprocedural MemorySSA Optimizations for prerequisites, pass names, and behavior.
Partial evaluation
lib/Optimization/PartialEvaluation/ contains the historical LLPE engine,
ported to LLVM 14.x and built as CanaryPE. It provides the llpe-analysis
and llpe legacy passes plus supporting infrastructure for specialization,
symbolic reasoning, and committed IR rewriting.
See PE for the main components and integration notes.
Software prefetching
lib/Optimization/Prefetch/ implements the SWPrefetchingLLVMPass legacy
function pass for profile-guided software prefetching of indirect memory
accesses.
See SWPrefetching (Software Prefetching) for its distance providers, options, and workflow.
Integration pattern
Typical consumers of this subtree use one of these patterns:
Run
llvm_utils::optimiseModuleto apply a standard LLVM cleanup pipeline.Add selected scalar or interprocedural legacy passes to a pass manager.
Run Lotus analyses, verification, or checker pipelines on the optimized IR.