Skip to content
Skills Library
Programming · Learning & explanation

code-generation-and-backends

/code-generation-and-backends

Code generation and backends skill for LLVM targets. Use when explaining instruction selection, DAG legalization, target lowering, or adding backend support overview. Activates on queries about LLVM backend, instruction selection, target lowering, llc, TableGen, or codegen pipeline.

Licence
MIT
Last repository change
27.06.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.06.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Code generation and backends skill for LLVM targets. Use when explaining instruction selection, DAG legalization, target lowering, or adding backend support overview. Activates on queries about LLVM backend, instruction selection, target lowering, llc, TableGen, or codegen pipeline.

Original author description

Code generation and backends skill for LLVM targets. Use when explaining instruction selection, DAG legalization, target lowering, or adding backend support overview. Activates on queries about LLVM backend, instruction selection, target lowering, llc, TableGen, or codegen pipeline.

How it works

  1. Purpose
  2. When to Use
  3. Workflow
  4. Common Problems
  5. Related Skills
Original SKILL.md headings · 92 lines, 392 words
SKILL.md preview
---
name: code-generation-and-backends
description: Code generation and backends skill for LLVM targets. Use when explaining instruction selection, DAG legalization, target lowering, or adding backend support overview. Activates on queries about LLVM backend, instruction selection, target lowering, llc, TableGen, or codegen pipeline.
---

# Code Generation and Backends

## Purpose

Overview LLVM (and general compiler) backend code generation: IR legalization, SelectionDAG instruction selection, register allocation, assembly emission, and what adding a new target entails — complementing IR skills and `skills/compiler-internals/llvm-passes`.

## When to Use

- Reading `llc` output for a specific target
- Understanding why IR type legalizer inserted extra ops
- Evaluating porting compiler to new architecture (high level)
- Debugging wrong code at asm layer (not IR)

## Workflow

### 1. Backend pipeline (LLVM)

```
LLVM IR per function
├── IR legalizer (types/ops target supports)
├── SelectionDAGBuilder
├── LegalizeTypes / LegalizeOps
├── Instruction selection (pattern match TableGen)
├── Scheduling (pre-RA)
├── Register allocation
├── Prolog/epilog insertion
└── AsmPrinter → .s object
```

### 2. llc usage

```bash
clang -c -emit-llvm -O2 -o foo.bc foo.c
llc -march=aarch64 -O2 foo.bc -o foo.s
llc -march=riscv64 -O2 foo.bc -o foo-rv.s
```

### 3. TableGen patterns (conceptual)

```tablegen
def ADD32rr : Pat<(add i32 GPR:$a, GPR:$b),
                  (ADD32rr GPR:$a, GPR:$b)>;
```

Patterns map DAG nodes to machine instructions. `.td` files define registers, calling conv, instr formats.

### 4. Calling convention lowering

ABI rules become `CC_AArch64` / `CC_X86_64` in TableGen — ties to `skills/computer-architecture/abi-and-calling-conventions`.

### 5. Target triple

```bash
clang --target=arm-none-eabi -c -O2 foo.c
llc -mtriple=thumbv7em-none-eabi foo.bc
```

Mismatch between triple and CPU features (`+neon`, `+crc`) causes legalizer failures or suboptimal code.

### 6. Adding a target (outline)

1. Define register classes and instr formats in TableGen
2. Implement lowering hooks (`TargetLowering`)
3. AsmPrinter and MC layer for relocations
4. Builtin calling convention and ELF/COFF object writer

Full port is large — reuse existing backend closest to arch.

### 7. Agent usage

```
/code-generation-and-backends Trace how this IR add becomes AArch64 ADD instruction
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| `Cannot select` fatal | Unsupported IR op on target | Legalize or expand op |
| Wrong soft-float | ABI mismatch | Set `-mfloat-abi` / triple |
| Huge stack frame | Many spills post-RA | IR-level pressure reduction |
| llc vs clang differ | Different targets passed | Same `-mtriple` |
| TableGen build fail | Syntax in .td | `llvm-tblgen` error line |

## Related Skills

- `skills/compiler-internals/llvm-ir-and-passes` — pre-codegen IR
- `skills/compiler-internals/compiler-optimizations-deep` — RA intuition
- `skills/compilers/cross-gcc` — embedded triples
- `skills/computer-architecture/abi-and-calling-conventions` — call lowering
- `skills/low-level-programming/assembly-arm` — read emitted asm

Versions

RepositoryScoreLicence
This page · mohitmishra786/low-level-dev-skills100MIT
OutlineDriven/outline-driven-development100Apache-2.0
gosuda/dalcom-skills95Apache-2.0

Database snapshot: 13.11.2026 · package version 54cb7a9960b6 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100llvm
    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…
  • 100llvm
    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…
  • 100llvm
    Use when working with LLVM IR as a user: emitting IR from clang, running opt passes, lowering with llc, reading IR, or finding a missed optimization. Not for writing new passes: use llvm-passes.
  • 100llvm-optimization
    Expertise in LLVM optimization passes, performance tuning, and code transformation techniques. Use this skill when implementing custom optimizations, analyzing pass behavior, improving generated code quality, or understanding LLVM's optimization pipeline.
  • 100llvm-compiler-architecture
    Use this skill when the user says 'LLVM', 'LLVM IR', 'compiler backend', 'optimization pass', 'frontend/backend separation', 'SSA IR'. Explains LLVM's three-phase design, SSA-form IR, and the pass pipeline. Do NOT use for: eBPF bytecode specifics (use…
  • 100llvm-ir-and-passes
    Use when reading LLVM IR, explaining SSA and PHI nodes, finding what -O2 changed, or running opt on a .ll or .bc file. Not for writing a pass plugin: use llvm-passes.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.