Skip to main content
skill CX Codex

code-generation-and-backends — Claude Code skill for LLVM codegen

code-generation-and-backends explains LLVM backend stages, from IR legalization to assembly output. Use it to investigate llc, TableGen patterns, or the outline of a new target port.

MIT 382 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill code-generation-and-backends -a claude-code
Open on GitHub

What code-generation-and-backends does

This skill walks through LLVM code generation: type and operation legalization, SelectionDAG instruction selection with TableGen patterns, scheduling, register allocation, and assembly emission. Its llc examples show how to produce assembly for AArch64 and RISC-V from LLVM bitcode.

It also covers ABI lowering, target triples, and the main pieces involved in a backend, including register classes, TargetLowering, AsmPrinter, and the MC layer. This is an overview, not a full porting guide. A mismatch between the target triple and CPU features can cause legalization failures or poor code, so check both when debugging a target.

What it helps with

  • trace an IR operation to its AArch64 instruction
  • understand why legalization introduced extra operations
  • inspect llc output for a target architecture
  • investigate a Cannot select error
  • outline the work involved in adding a backend

Example prompts for the agent

  • /code-generation-and-backends Trace how this IR addition becomes an AArch64 ADD instruction.
  • /code-generation-and-backends Explain why legalization introduced operations for this IR type.
  • /code-generation-and-backends Review this llc output and check whether the target triple matches the CPU features.

How to install code-generation-and-backends

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill code-generation-and-backends -a claude-code

2Manually: put the files in place

~/.claude/skills/code-generation-and-backends/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/code-generation-and-backends/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about code-generation-and-backends

How do I install code-generation-and-backends in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill code-generation-and-backends -a claude-code. The skill is placed at ~/.claude/skills/code-generation-and-backends/SKILL.md.

What does code-generation-and-backends do?

It explains how LLVM turns IR into machine instructions and assembly, covering legalization, instruction selection, register allocation, and ABI rules.

Why does the LLVM target triple matter?

It identifies the target platform. If it conflicts with CPU features, legalization can fail or the generated code may be suboptimal.

Source text

SKILL.md · MIT
---
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

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Backend and APIs →

From the same set140

The whole set →
spi-i2c-baremetal The spi-i2c-baremetal skill guides bare-metal SPI and I2C driver work, from register reads to bus troubleshooting. Use it when bringing up sensors, flash, or displays. CX Codex +1 384installs protocol-analysis protocol-analysis is a Claude Code skill that decodes I2C, SPI, and UART captures with sigrok and PulseView, then checks them against driver code. It handles silent-sensor bus analysis. CX Codex +1 383installs gpio-baremetal gpio-baremetal configures GPIO modes, alternate functions, pull resistors, and EXTI interrupts on bare-metal microcontrollers without HAL. CX Codex +1 383installs apple-silicon A skill for developers building on Apple Silicon: tuning code for unified memory, Metal Performance Shaders, Instruments profiling, Rosetta 2 behavior, and 16KB page size quirks. CX Codex +1 383installs jit-compilation jit-compilation teaches the agent to build a JIT: LLVM ORC and LLJIT, Cranelift, inline caches, trampolines, Rust dynasm. Useful for interpreter hot paths and REPLs. CX Codex +1 382installs kernel-testing Skill for Linux kernel testing: KUnit for unit tests, kselftest for regression checks, syzkaller for fuzzing, and LTP for syscall compatibility. Activates on kunit.py queries, syzkaller config, or KernelCI setup. CX Codex +1 382installs branch-prediction-and-speculation branch-prediction-and-speculation is a Claude Code skill that explains CPU branch prediction and speculative execution to help optimize hot loops and protect code from cache timing leaks. CX Codex +1 382installs os-dev-scratch os-dev-scratch is a Claude Code skill for building a minimal x86-64 OS, from boot stages to drivers and context switching. It activates on questions about kernel boot, interrupts, page tables, or QEMU. CX Codex +1 381installs

Project sponsors

Companies that keep this analytics open