Loading...
Loading...
LLVM IR and pass pipeline skill. Use when working directly with LLVM Intermediate Representation (IR), running opt passes, generating IR with llc, inspecting or writing LLVM IR for custom passes, or understanding how the LLVM backend lowers IR to assembly. Activates on queries about LLVM IR, opt, llc, llvm-dis, LLVM passes, IR transformations, or building LLVM-based tools.
npx skill4agent add mohitmishra786/low-level-dev-skills llvmoptllc# Emit textual IR (.ll)
clang -O0 -emit-llvm -S src.c -o src.ll
# Emit bitcode (.bc)
clang -O2 -emit-llvm -c src.c -o src.bc
# Disassemble bitcode to text
llvm-dis src.bc -o src.llopt# Apply a specific pass
opt -passes='mem2reg,instcombine,simplifycfg' src.ll -S -o out.ll
# Standard optimisation pipelines
opt -passes='default<O2>' src.ll -S -o out.ll
opt -passes='default<O3>' src.ll -S -o out.ll
# List available passes
opt --print-passes 2>&1 | less
# Print IR before and after a pass
opt -passes='instcombine' --print-before=instcombine --print-after=instcombine src.ll -S -o out.ll 2>&1 | lessllc# Compile IR to object file
llc -filetype=obj src.ll -o src.o
# Compile to assembly
llc -filetype=asm -masm-syntax=intel src.ll -o src.s
# Target a specific CPU
llc -mcpu=skylake -mattr=+avx2 src.ll -o src.s
# Show available targets
llc --version| Construct | Meaning |
|---|---|
| Stack allocation (pre-SSA; |
| Memory access |
| Pointer arithmetic / field access |
| SSA φ-node: merges values from predecessor blocks |
| Function call ( |
| Integer/float comparison |
| Branch (conditional or unconditional) |
| Return |
| Reinterpret bits (no-op in codegen) |
| Pointer↔integer (avoid where possible) |
| Pass | Effect |
|---|---|
| Promote alloca to SSA registers |
| Instruction combining / peephole |
| CFG cleanup, dead block removal |
| Auto-vectorisation |
| Superword-level parallelism (straight-line vectorisation) |
| Function inlining |
| Global value numbering (common subexpression elimination) |
| Loop-invariant code motion |
| Loop unrolling |
| Promote pointer args to values |
| Scalar Replacement of Aggregates |
# Why was a loop not vectorised?
clang -O2 -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize src.c
# Dump pass pipeline
clang -O2 -mllvm -debug-pass=Structure src.c -o /dev/null 2>&1 | less
# Print IR after each pass (very verbose)
opt -passes='default<O2>' -print-after-all src.ll -S 2>&1 | less| Tool | Purpose |
|---|---|
| Bitcode → textual IR |
| Textual IR → bitcode |
| Link multiple bitcode files |
| Standalone LTO |
| Symbols in bitcode/object |
| Disassemble objects |
| Merge/show PGO profiles |
| Coverage reporting |
| Machine code analyser (throughput/latency) |
skills/binaries/binutilsskills/compilers/clangskills/binaries/linkers-ltoskills/profilers/linux-perfllvm-mca