LLVM Transformation Passes
本节就会对于 LLVM Transformation Passes 中的每一个详细解释了。对于每一个 pass,我们主要从三块进行解释: 0. 背景知识。类似 prerequisite;只有一部分 pass 需要,很多 pass 都是可以直接理解的。所有的背景知识都可以在 Compiler Optimization Basics 中找到。 1. 文字解释(Description)。就是通过文字描述,僵硬的解释一下。 2. 代码样例(Code Example)。一般来说我们会用 LLVM IR 来写一下,transform 前 code 长啥样和 transform 后 code 长啥样。如果用 C 更直观的话我们就用 C 来解释了。
因为 Pass 比较多,所以 我把 Reference 集中写在这里了。 代码样例中的例子来源于,直接写 code 然后编译,个人和 ChatGPT 疯狂的交互(然后再读 LLVM 文档 double check) [1], LLVM 的官方文档 [2],还有 Cornell CS:6120 [3]。 好的,那么我们现在就可以开始了。
-adce: Aggressive Dead Code Elimination-always-inline: Inliner for always_inline Functions-argpromotion: Promote ‘by reference’ Arguments to Scalars-bb-vectorize: Basic Block Vectorization-block-placement: Profile Guided Basic Block Placement-break-crit-edges: Break Critical Edges in CFG-constmerge: Merge Duplicate Global Constants-dce: Dead Code Elimination-deadargelim: Dead Argument Elimination-die: Dead Instruction Elimination-dse: Dead Store Elimination-function-attrs: Deduce Function Attributes-globaldce: Dead Global Elimination-globalopt: Global Variable Optimizer-gvn: Global Value Numbering-indvars: Canonicalize Induction Variables-inline: Function Integration/Inlining-partial-inliner: Partial Inliner-instcombine: Combine Redundant Instructions-aggressive-instcombine: Combine Expression Patterns-internalize: Internalize Global Symbols-sccp: Sparse Conditional Constant Propagation-ipsccp: Interprocedural Sparse Conditional Constant Propagation-jump-threading: Jump Threading-licm: Loop Invariant Code Motion-loop-deletion: Delete Dead Loops-loop-extract: Extract Loops into New Functions-loop-reduce: Loop Strength Reduction-loop-rotate: Rotate Loops-loop-simplify: Canonicalize Natural Loops-loop-unroll: Unroll Loops-loop-unroll-and-jam: Unroll and Jam Loops-loop-unswitch: Unswitch Loops-lcssa: Loop-Closed SSA Form Pass-loweratomic: Lower Atomic Intrinsics to Non-Atomic Form-lowerinvoke: Lower Invokes to Calls, for Unwindless Code Generators-lowerswitch: Lower SwitchInsts to Branches-mem2reg: Promote Memory to Registers-mergefunc: Merge Functions-mergereturn: Unify Function Exit Nodes-prune-eh: Remove Unused Exception Handling Info-reassociate: Reassociate Expressions-reg2mem: Demote All Values to Stack Slots-sroa: Scalar Replacement of Aggregates-simplifycfg: Simplify the CFG-sink: Code Sinking-strip-dead-prototypes: Strip Unused Function Prototypes-strip: Strip All Symbols from a Module-tailcallelim: Tail Call Elimination