/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
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill code-generation-and-backends --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/code-generation-and-backends
Context preview
The summary Claude sees to decide when to auto-load this skill.
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
SKILL.md
code-generation-and-backends.SKILL.mdname: 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
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)
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
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
Read more
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
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)
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
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
A curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /custom-allocators
Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

