Skip to content- Sources: primary
- Summary: Fangrui Song describes a DirectCodeGen pass, enabled by -direct-codegen, that compiles a function from LLVM IR to encoded bytes without building a MachineFunction and sends any function it cannot handle to the regular pipeline in the same object file. On the compile-time tracker, clang -O0 -g builds take 14.3% fewer instructions on x86-64 and 21.0% fewer on AArch64, while x86-64 text grows about 10% and AArch64 size is roughly unchanged. Claude Code wrote most of the code and drafted the post, and MC fixes found along the way landed separately.
- Why it matters: Debug build latency is dominated by the back end at -O0, and this shows how much a pipeline-skipping code generator can recover inside LLVM itself.
- Background: At -O0 LLVM selects instructions with FastISel (or GlobalISel on AArch64), then runs dozens of machine IR passes such as fast register allocation, prologue insertion and debug value analysis before the assembly printer emits code. Skipping those passes means each one that can change output, such as stack protectors, CFI or pointer authentication, must be reimplemented or trigger fallback. The post gates on an exhaustive switch over function attributes so a new upstream attribute breaks the build instead of silently miscompiling, and checks that clang -S output assembles to the same bytes as clang -c.