PassManagerBuilder vs. TargetPassConfig

Hi,

clang uses PassManagerBuilder via EmitAssemblyHelper::CreatePasses() to create a collection of passes.

llvm (MCJIT) uses TargetPassConfig via addPassesToGenerateCode for the same purpose.

There seems to some duplication and many differences between PassManagerBuilder and TargetPassConfig, some aren’t clear at all.

Two small examples:

  1. PassManagerBuilder adds createScalarReplAggregatesPass but TargetPassConfig does not.

  2. TargetPassConfig adds createLoopStrengthReducePass right after the initial analysis but TargetPassConfig does not.

I would expect that the optimization passes would be identical based on optimization level only but they are quite different between PassManagerBuilder and TargetPassConfig.

Yaron

I'm not aware of any reason these two should differ. I suspect this is simply a case of copied code which has devolved over time.

Philip

Hi,

Turns out that EmitAssemblyHelper adds the TargetPassConfig passes on top of other passes coming from PMBuilder.
That seems to lead to strange results. For instance, TM->addAnalysisPasses(PM) is called twice for the same PassManager, first from EmitAssemblyHelper::AddEmitPasses() then from addPassesToGenerateCode.

SROA is done twice, once from PassManagerBuilder::populateModulePassManager() and then from PassManagerBuilder::populateFunctionPassManager().

There are other duplications between the three pass collections which may be slowing down optimization.

OTOH MCJIT does not use the second set of optimizations coming form PMBuilder and not TargetPassConfig.

Below is the full structure output from clang++ -mllvm -debug-pass=Structure -O2
The passes following ###### are coming from TargetPassConfig and identical to what you get for MCJIT.

Does this pass structure makes sense?

Yaron

Pass Arguments: -datalayout -notti -basictti -x86tti -targetlibinfo -no-aa -tbaa -scoped-noalias -basicaa -verify -add-discriminators -simplifycfg -domtree -sroa -early-cse -lower-expect
Data Layout
No target information
Target independent code generator’s TTI
X86 Target Transform Info
Target Library Information
No Alias Analysis (always returns ‘may’ alias)
Type-Based Alias Analysis
Scoped NoAlias Alias Analysis
Basic Alias Analysis (stateless AA impl)
FunctionPass Manager
Module Verifier
Add DWARF path discriminators
Simplify the CFG
Dominator Tree Construction
SROA
Early CSE
Lower ‘expect’ Intrinsics
Pass Arguments: -datalayout -notti -basictti -x86tti -targetlibinfo -no-aa -tbaa -scoped-noalias -basicaa -verify-di -ipsccp -globalopt -deadargelim -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -inline -functionattrs -sroa -domtree -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -loop-unswitch -instcombine -scalar-evolution -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -mldst-motion -domtree -memdep -gvn -memdep -memcpyopt -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -loops -scalar-evolution -slp-vectorizer -adce -simplifycfg -instcombine -barrier -domtree -loops -loop-simplify -lcssa -branch-prob -block-freq -scalar-evolution -loop-vectorize -instcombine -simplifycfg -domtree -loops -loop-simplify -lcssa -scalar-evolution -loop-unroll -strip-dead-prototypes -globaldce -constmerge
Data Layout
No target information
Target independent code generator’s TTI
X86 Target Transform Info
Target Library Information
No Alias Analysis (always returns ‘may’ alias)
Type-Based Alias Analysis
Scoped NoAlias Alias Analysis
Basic Alias Analysis (stateless AA impl)
ModulePass Manager
Debug Info Verifier
Interprocedural Sparse Conditional Constant Propagation
Global Variable Optimizer
Dead Argument Elimination
FunctionPass Manager
Combine redundant instructions
Simplify the CFG
CallGraph Construction
Call Graph SCC Pass Manager
Remove unused exception handling info
Inline Cost Analysis
Function Integration/Inlining
Deduce function attributes
FunctionPass Manager
SROA
Dominator Tree Construction
Early CSE
Lazy Value Information Analysis
Jump Threading
Value Propagation
Simplify the CFG
Combine redundant instructions
Tail Call Elimination
Simplify the CFG
Reassociate expressions
Dominator Tree Construction
Natural Loop Information
Canonicalize natural loops
Loop-Closed SSA Form Pass
Loop Pass Manager
Rotate Loops
Loop Invariant Code Motion
Unswitch loops
Combine redundant instructions
Scalar Evolution Analysis
Loop-Closed SSA Form Pass
Loop Pass Manager
Induction Variable Simplification
Recognize loop idioms
Delete dead loops
Unroll loops
Memory Dependence Analysis
MergedLoadStoreMotion
Dominator Tree Construction
Memory Dependence Analysis
Global Value Numbering
Memory Dependence Analysis
MemCpy Optimization
Sparse Conditional Constant Propagation
Combine redundant instructions
Lazy Value Information Analysis
Jump Threading
Value Propagation
Dominator Tree Construction
Memory Dependence Analysis
Dead Store Elimination
Natural Loop Information
Scalar Evolution Analysis
SLP Vectorizer
Aggressive Dead Code Elimination
Simplify the CFG
Combine redundant instructions
A No-Op Barrier Pass
FunctionPass Manager
Dominator Tree Construction
Natural Loop Information
Canonicalize natural loops
Loop-Closed SSA Form Pass
Branch Probability Analysis
Block Frequency Analysis
Scalar Evolution Analysis
Loop Vectorization
Combine redundant instructions
Simplify the CFG
Dominator Tree Construction
Natural Loop Information
Canonicalize natural loops
Loop-Closed SSA Form Pass
Scalar Evolution Analysis
Loop Pass Manager
Unroll loops
Strip Unused Function Prototypes
Dead Global Elimination
Merge Duplicate Global Constants