llvm-ir-and-passes — Claude Code skill: what it does, how to install
llvm-ir-and-passes teaches the agent to read LLVM IR, understand SSA form, and navigate optimization passes. Useful when tracing what -O2 changed or preparing to write a custom pass.
MIT 384 installs ★ 298 updated 2026-06-27
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a claude-codeWhat llvm-ir-and-passes does
The agent learns LLVM IR structure: basic blocks, PHI nodes at merge points, typed values like i32 or ptr. The skill covers the standard optimization pipeline (SimplifyCFG, InstCombine, GVN, LICM) and commands to run passes via opt. It includes examples for emitting IR from source (clang -S -emit-llvm), disassembling bitcode (llvm-dis), and comparing code before and after transformations.
You need clang and opt of matching versions. Different LLVM major versions produce incompatible IR. The skill complements skills/compilers/llvm (toolchain overview) and skills/compiler-internals/llvm-passes (plugin development).
What it helps with
- trace what
-O2did to a function - understand SSA form and dominator trees without writing C++ passes
- find the root cause of a miscompile between Clang versions
- inspect the optimization pipeline before writing a custom pass
- compare IR before and after specific transformations
Example prompts for the agent
- Explain this PHI node and which pass likely created it
- Show the dominator tree for
foo.ll - Run
optwith the-O2pipeline and compare the result to the original IR
How to install llvm-ir-and-passes
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a claude-code2Manually: put the files in place
~/.claude/skills/llvm-ir-and-passes/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/llvm-ir-and-passes/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a codex2Manually: put the files in place
.agents/skills/llvm-ir-and-passes/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a cursor2Manually: put the files in place
.cursor/skills/llvm-ir-and-passes/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mohitmishra786/low-level-dev-skills skills/compiler-internals/llvm-ir-and-passes2Manually: put the files in place
.github/skills/llvm-ir-and-passes/SKILL.md1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a gemini-cli2Platform CLI
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/compiler-internals/llvm-ir-and-passesManually: put the files in place
.devin/skills/llvm-ir-and-passes/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about llvm-ir-and-passes
How to install llvm-ir-and-passes in Claude Code?
Run npx skills add mohitmishra786/low-level-dev-skills --skill llvm-ir-and-passes -a claude-code. The skill will appear in ~/.claude/skills/llvm-ir-and-passes/SKILL.md.
What does llvm-ir-and-passes do?
Teaches the agent to read LLVM IR, work with SSA form, understand optimization pass order, and use opt for inspection and transformations.
What does llvm-ir-and-passes require?
You need clang and opt of matching LLVM major versions. Different versions produce incompatible IR.
Source text
SKILL.md · MIT
---
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
```llvm
; 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
```bash
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:
```bash
opt -passes='default<O2>' -S foo.ll -o foo-opt.ll
opt -passes='default<O2>' -print-passes foo.ll 2>&1 | head
```
### 4. Useful analysis passes
| Pass | Shows |
|------|-------|
| `-passes=print<domtree>` | Dominator tree |
| `-passes=print<loops>` | Loop nests |
| `-passes=print-alias-sets` | Alias sets |
```bash
opt -passes='print<domtree>' -disable-output foo.ll
```
### 5. Reading PHI and UB
```llvm
merge:
%v = phi i32 [ %a, %then ], [ %b, %else ]
```
`undef` and `poison` in IR model LLVM poison semantics — distinct from C UB but related.
### 6. Compare before/after
```bash
opt -passes='instcombine,simplifycfg' -S foo.ll -o - | diff -u foo.ll -
```
### 7. Agent usage
```
/llvm-ir-and-passes Explain this PHI node and which pass likely created it
```
## Common Problems
| Symptom | Cause | Fix |
|---------|-------|-----|
| Pass not found | LLVM version rename | `opt --print-passes` for your build |
| IR mismatch | Different LLVM major | Match clang/opt versions |
| "optnone" blocks opts | `-O0` attribute | Compile with `-O1+` |
| Huge IR | Inlined headers | `-fno-discard-value-names` off; filter function |
| Wrong pipeline | Legacy vs NPM | Use `-passes=` syntax |
## Related Skills
- `skills/compilers/llvm` — toolchain overview
- `skills/compiler-internals/llvm-passes` — writing PassPlugins
- `skills/compiler-internals/compiler-optimizations-deep` — RA and ISel
- `skills/compiler-internals/compiler-frontend` — IR generation
- `skills/rust/rustc-basics` — `rustc --emit=llvm-ir`
© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills