mohitmishra786/low-level-dev-skills / skills/compilers/llvm
llvm
VerifiedLLVM 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.5 KB |
| references/ir-reference.md | markdown | 3.7 KB |
references/ir-reference.md
View on GitHub# LLVM IR Reference
Source: <https://llvm.org/docs/LangRef.html>
## Table of Contents
1. [Types](#types)
2. [Instructions](#instructions)
3. [Attributes and metadata](#attributes-and-metadata)
4. [Opt pass names](#opt-pass-names)
---
## Types
| Type | Description |
|------|-------------|
| `i1` | 1-bit integer (boolean) |
| `i8`, `i16`, `i32`, `i64` | Integer of N bits |
| `float` | 32-bit IEEE 754 |
| `double` | 64-bit IEEE 754 |
| `ptr` | Opaque pointer (LLVM 15+) |
| `[N x T]` | Array of N elements of type T |
| `{T1, T2, ...}` | Struct (packed: `<{...}>`) |
| `<N x T>` | Vector of N elements |
| `void` | No value |
---
## Instructions
### Memory
```llvm
%ptr = alloca i32, align 4 ; stack allocation
%val = load i32, ptr %ptr, align 4 ; load
store i32 42, ptr %ptr, align 4 ; store
%p2 = getelementptr i32, ptr %ptr, i64 1 ; pointer arithmetic
```
### Arithmetic
```llvm
%sum = add i32 %a, %b
%diff = sub i32 %a, %b
%prod = mul i32 %a, %b
%quot = sdiv i32 %a, %b ; signed divide
%quot = udiv i32 %a, %b ; unsigned divide
%rem = srem i32 %a, %b ; signed remainder
%shl = shl i32 %a, 3 ; shift left
%lsr = lshr i32 %a, 3 ; logical shift right
%asr = ashr i32 %a, 3 ; arithmetic shift right
%and = and i32 %a, %b
%or = or i32 %a, %b
%xor = xor i32 %a, %b
```
### Comparison
```llvm
%c = icmp eq i32 %a, %b ; integer compare: eq ne slt sle sgt sge ult ule ugt uge
%c = fcmp oeq float %a, %b ; float compare: oeq one olt ole ogt oge ord uno
```
### Control flow
```llvm
br label %next ; unconditional branch
br i1 %cond, label %true, label %false ; conditional branch
ret i32 %val
ret void
%ret = call i32 @foo(i32 %a, i32 %b)
switch i32 %val, label %default [ i32 0, label %case0
i32 1, label %case1 ]
```
### PHI nodes (SSA merging)
```llvm
%result = phi i32 [ %val_from_block_a, %block_a ],
[ %val_from_block_b, %block_b ]
```
### Type conversion
```llvm
%i = trunc i64 %x to i32 ; truncate
%x = zext i32 %i to i64 ; zero-extend
%x = sext i32 %i to i64 ; sign-extend
%p = inttoptr i64 %addr to ptr ; integer to pointer
%n = ptrtoint ptr %p to i64 ; pointer to integer
%f = sitofp i32 %i to float ; signed int to float
%i = fptosi float %f to i32 ; float to signed int
%d = fpext float %f to double ; float extend
%f = fptrunc double %d to float ; float truncate
```
---
## Attributes and metadata
```llvm
; Function attributes
define i32 @foo(i32 %x) noinline nounwind readonly {
; Parameter attributes
define void @bar(i32 noundef %x, ptr nocapture nonnull %p) {
; Inline hint
define i32 @hot() alwaysinline {
; Alignment
%val = load i32, ptr %ptr, align 16
```
Common function attributes:
- `noinline` — never inline
- `alwaysinline` — always inline
- `noreturn` — never returns (like `abort`)
- `nounwind` — never throws an exception
- `readonly` — only reads memory
- `readnone` — does not access memory
---
## Opt pass names (LLVM 14+ new pass manager)
| Pass name | Effect |
|-----------|--------|
| `mem2reg` | Promote alloca to SSA |
| `instcombine` | Instruction combining |
| `simplifycfg` | CFG simplification |
| `gvn` | Global value numbering |
| `licm` | Loop-invariant code motion |
| `loop-vectorize` | Auto-vectorisation |
| `slp-vectorize` | SLP vectorisation |
| `inline` | Function inlining |
| `early-cse` | Early common subexpression elimination |
| `dce` | Dead code elimination |
| `sroa` | Scalar Replacement of Aggregates |
| `loop-unroll` | Loop unrolling |
| `tailcallelim` | Tail call elimination |
| `reassociate` | Reassociation for better constant folding |
Pipeline example:
```bash
opt -passes='mem2reg,instcombine,simplifycfg,gvn,licm' input.ll -S -o out.ll
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |