Order of LLVM Transform passes?

Hello,

I am writing an LLVM Transform pass whose behavior may need to change depending on whether a different pass is run before or after it. How can I find out which Transform passes are run in which order when I run opt?

Further, I assume that Analysis passes are always run prior to Transform passes - is this correct? Thanks!

Regards,
Shishir Jessu

Hello,

I am writing an LLVM Transform pass whose behavior may need to change depending on whether a different pass is run before or after it. How can I find out which Transform passes are run in which order when I run opt?

If you run “opt -print-after-all …”, it will dump the IR after each pass. If you grep the output by “*** IR Dump”, it should show the order (but note the order may change.)

Further, I assume that Analysis passes are always run prior to Transform passes - is this correct? Thanks!

The analyses that a pass depends on will be run prior to it, right before the pass if the previous pass invalidates them, or some time earlier if they are preserved by the preceding passes.

I am writing an LLVM Transform pass whose behavior may need to change depending on whether a different pass is run before or after it. How can I find out which Transform passes are run in which order when I run opt?

$ opt -debug-pass=Arguments -O3 ....

Will print the sequence of passes at the chosen level (legacy pass manager):

Pass Arguments: -tti -tbaa -scoped-noalias -assumption-cache-tracker
-targetlibinfo -verify -ee-instrument -simplifycfg -domtree -sroa
-early-cse -lower-expect
Pass Arguments: -targetlibinfo -tti -tbaa -scoped-noalias
-assumption-cache-tracker -profile-summary-info -forceattrs
-inferattrs -attributor -domtree -callsite-splitting -ipsccp
-called-value-propagation -globalopt -domtree -mem2reg -deadargelim
-domtree -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -instcombine -simplifycfg -basiccg -globals-aa
-prune-eh -inline -attributor-cgscc -openmpopt -functionattrs
-argpromotion -domtree -sroa -basicaa -aa -memoryssa -early-cse-memssa
-speculative-execution -aa -lazy-value-info -jump-threading
-correlated-propagation -simplifycfg -domtree -aggressive-instcombine
-basicaa -aa -loops -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -instcombine -libcalls-shrinkwrap -loops
-branch-prob -block-freq -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -pgo-memop-opt -basicaa -aa -loops
-lazy-branch-prob -lazy-block-freq -opt-remark-emitter -tailcallelim
-simplifycfg -reassociate -domtree -loops -loop-simplify
-lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-rotate
-memoryssa -licm -loop-unswitch -simplifycfg -domtree -basicaa -aa
-loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter
-instcombine -loop-simplify -lcssa-verification -lcssa
-scalar-evolution -indvars -loop-idiom -loop-deletion -loop-unroll
-mldst-motion -phi-values -aa -memdep -lazy-branch-prob
-lazy-block-freq -opt-remark-emitter -gvn -phi-values -basicaa -aa
-memdep -memcpyopt -sccp -demanded-bits -bdce -aa -lazy-branch-prob
-lazy-block-freq -opt-remark-emitter -instcombine -lazy-value-info
-jump-threading -correlated-propagation -basicaa -aa -phi-values
-memdep -dse -aa -memoryssa -loops -loop-simplify -lcssa-verification
-lcssa -scalar-evolution -licm -postdomtree -adce -simplifycfg
-domtree -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -instcombine -barrier -elim-avail-extern -basiccg
-rpo-functionattrs -globalopt -globaldce -basiccg -globals-aa -domtree
-float2int -lower-constant-intrinsics -domtree -loops -loop-simplify
-lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-rotate
-loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter
-loop-distribute -branch-prob -block-freq -scalar-evolution -basicaa
-aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -inject-tli-mappings -loop-vectorize
-loop-simplify -scalar-evolution -aa -loop-accesses -lazy-branch-prob
-lazy-block-freq -loop-load-elim -vector-combine -basicaa -aa
-lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine
-simplifycfg -domtree -loops -scalar-evolution -basicaa -aa
-demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter
-slp-vectorizer -vector-combine -aa -opt-remark-emitter -instcombine
-loop-simplify -lcssa-verification -lcssa -scalar-evolution
-loop-unroll -lazy-branch-prob -lazy-block-freq -opt-remark-emitter
-instcombine -memoryssa -loop-simplify -lcssa-verification -lcssa
-scalar-evolution -licm -lazy-branch-prob -lazy-block-freq
-opt-remark-emitter -transform-warning -alignment-from-assumptions
-strip-dead-prototypes -globaldce -constmerge -domtree -loops
-branch-prob -block-freq -loop-simplify -lcssa-verification -lcssa
-basicaa -aa -scalar-evolution -block-freq -loop-sink
-lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instsimplify
-div-rem-pairs -simplifycfg -verify
Pass Arguments: -domtree
Pass Arguments: -targetlibinfo -domtree -loops -branch-prob -block-freq
Pass Arguments: -targetlibinfo -domtree -loops -branch-prob -block-freq

With in the pass, it it difficult to determine whether another pass
changed a function. In Polly, we attach an attribute to the function
"polly-optimized" to which a cleanup-pass can react to.

Further, I assume that Analysis passes are always run prior to Transform passes - is this correct? Thanks!

Yes, in the legacy pass manager (getAnalysisUsage tell the pass
manager which analyses to run; not that some analyses are lazy and
only determine the properties when asked for it)

No in the new pass manager. Analyses run when calling getAnalysis.

Michael