| name | llvm-ir-and-passes |
| description | LLVM IR and passes skill for reading compiler IR. Use when analyzing LLVM IR, understanding SSA, pass pipeline order, or running opt on bitcode. Activates on queries about LLVM IR, SSA form, opt passes, llvm-dis, pass pipeline, or reading .ll files. |
LLVM IR and Passes
Purpose
Teach agents to read and reason about LLVM IR (SSA, types, terminators), navigate the standard pass pipeline, and use opt/llvm-dis for inspection. Complements skills/compilers/llvm (toolchain) and skills/compiler-internals/llvm-passes (writing plugins) — not merged.
When to Use
- Understanding what
-O2 changed in generated IR
- Triaging miscompiles between Clang versions
- Preparing to write a custom pass
- Teaching SSA and dominance without writing C++ passes yet
Workflow
1. LLVM IR structure
; Function in SSA form
define i32 @add(i32 %a, i32 %b) {
entry:
%sum = add i32 %a, %b
ret i32 %sum
}
Key concepts: basic blocks, PHI nodes at merges, typed values (i32, ptr, vectors).
2. Emit IR from Clang
clang -S -emit-llvm -O0 -o foo.ll foo.c
clang -c -emit-llvm -O2 -o foo.bc foo.c
llvm-dis foo.bc -o foo.ll
3. Standard optimization pipeline (New PM)
Clang -O2 roughly runs:
SimplifyCFG → InstCombine → GVN → LICM → LoopVectorize → ...
Inspect with:
opt -passes='default<O2>' -S foo.ll -o foo-opt.ll
opt -passes='default<O2>' -print-passes foo.ll 2>&1 | head