r/Compilers • u/0x6461726B • May 11 '26
r/Compilers • u/NoVibeCoding • May 11 '26
Writing an LLM compiler from scratch [Part 2]: Lowering to a GPU Schedule
cloudrift.aiThe modern ML (LLM) compiler stack is brutal. TVM is 500K+ lines of C++. PyTorch piles Dynamo, Inductor, and Triton on top of each other. I built a hackable LLM compiler from scratch and am documenting the process. It takes a small model (TinyLlama, Qwen2.5-7B) and lowers it to a sequence of CUDA kernels through six IRs.
Currently, on RTX 5090, the emitted FP32 kernels run at geomean 1.11× vs PyTorch eager and 1.20× vs torch.compile, with full-block parity on TinyLlama-128 and Qwen2.5-7B at seq=128. Wins on small reductions / SDPA / kv-projections (up to 4.7×); losses on dense matmul at seq=512.
Part 1 took an RMSNorm layer end-to-end and walked the upper half of that pipeline in detail. This second part closes the gap and explains Tile IR, Kernel IR, and associated lowering rules in depth.
Full article: A Principled ML Compiler Stack in 5,000 Lines of Python Repo: deplodock
The article focuses on producing a GPU schedule for an operation written in loop-nest form (Loop IR). Example for RMSNorm:
=
# free
# reduce
=
=
<-
=
=
=
# free
=
=
=
=
=
The stack mimics a sequence of optimization steps a CUDA engineer would perform when optimizing kernels: stage inputs to smem, reduce bank conflicts, increase occupancy, and so on.
LoopOp
│
▼
[001] tileify — lift outer free Loops to thread axes
[002] chunk_matmul_k — chunk the K reduce into K-outer × K-inner (intra-CTA)
[003] split_matmul_k — promote the K-outer chunk loop into a grid dimension
[004] cooperative_reduce — let multiple threads share one reduce; tree-merge with Combine
[005] blockify_launch — pick block extents; partition free axes into BLOCK and THREAD
[006] chunk_reduce — chunk non-matmul reduces so their Loads fit in shared memory
[007] stage_inputs — hoist hot input slabs into Stage nodes
[008] register_tile — replicate the inner tile so each thread owns a register block
[009] permute_register_tile — reorder the register strip so bank-conflicting loads land on far columns
[010] double_buffer — promote K-outer Stages to BufferedStage (ping-pong)
[011] tma_copy — narrow eligible BufferedStages to TmaBufferedStage (sm_90+)
[012] split_inner_for_swizzle — split the inner cache axis of a TmaBufferedStage for swizzle
[013] async_copy — narrow the rest to AsyncBufferedStage (cp.async, sm_80+)
[014] pad_smem — pad shared-memory strides to break bank conflicts
[015] pipeline_k_outer — rotate the K-outer loop into prologue/steady-state/epilogue (cp.async + TMA)
[016] mark_unroll — annotate small inner loops for #pragma unroll
│
▼
TileOp (fully scheduled)
Each stage can be reproduced with a CLI command. For example, the stage_inputs pass stages input buffers into smem if possible and if there is a benefit in doing that (inputs are being read multiple times within CTA). To see it, the following command can be used:
|
>>> t:007_stage_inputs
v0 = reciprocal(2048)
Tile(axes=(a0:256=THREAD, a1:32=BLOCK)):
+ x_smem = Stage(x, origin=(0, a1, 0), slab=(a2:2048@2))
StridedLoop(a2 = a0; < 2048; += 256): # reduce
- in2 = load x[0, a1, a2]
+ in2 = load x_smem[a2]
v1 = multiply(in2, in2)
acc0 <- add(acc0, v1)
v4 = rsqrt(v3)
StridedLoop(a2 = a0; < 2048; += 256): # free
- in3 = load x[0, a1, a2]
+ in3 = load x_smem[a2]
in4 = load p_weight[a2]
v5 = multiply(in3, v4)
<<< t:007_stage_inputs
The final CUDA kernel for the RMSNorm layer:
extern "C" __global__
void
r/Compilers • u/Tricky_Football_85 • May 11 '26
Is there a JIT compiler that recompiles the compiler using JIT so it can optimise its compiling efficiency?
r/Compilers • u/requiehmmm • May 12 '26
im building a DSL for constrained decoding in LLMs
the idea is simple:
- an OpenAPI spec defines the API surface/schema
- a "companion" DSL (dubbed "invariants") defines executable interaction semantics/state transitions
- the DSL compiles into an abstract machine/runtime automaton
- during the LLM's decoding step, this machine will incrementally constrain or bias valid continuations
- thus, instead of post-hoc validation (which requires full regeneration in case of error!) we can attempt local correction during generation
the main goal is reducing regeneration cost/latency while improving consistency for structured API outputs and tool usage. i'm especially interested in whether this resembles any existing work in constrained decoding, parser repair, attribute grammars, streaming validation, or anything else?
any tips/advice would be greatly appreciated.
r/Compilers • u/JeffD000 • May 11 '26
Recently used Nore to partially solve the performance portability problem
reddit.comr/Compilers • u/framelanger • May 11 '26
Frame: a DSL for state machines that transpiles to 17 languages
Hello — I've been working on a state machine language called Frame, which is now in a decent alpha state and in active development. You can check it out at https://github.com/frame-lang/framec.
The main Frame tool is actually a preprocessor called the framepiler that looks for Frame syntax embedded inside your native source file. The framepiler transpiles Frame state machines (called systems) to plain, dependency-free classes (or equivalent) in the target language. Frame currently supports 17 target languages — Python, TypeScript, JavaScript, Rust, C, C++, Java, C#, Go, PHP, Kotlin, Swift, Ruby, Erlang, Lua, Dart, and GDScript — plus a GraphViz backend for visualization.
I would greatly appreciate any and all feedback on the language and technical approach, good or bad.
Thanks!
r/Compilers • u/shetrynajerkme • May 10 '26
Progress on my C compiler in C.
Hey everybody,
I've been making a C11 compiler in C, following "Writing a C Compiler" book. It's my first compiler.
Here's the link: https://github.com/stjmm/CinC
It has:
- An on demand lexer
- Parser with Pratt expression parsing
- Semantic Analysis/Type system with a couple of passes
- Three Address IR
- x86_64 code emission
Right now it supports:
- expressions
- if/else/break/continue
- for/while/dowhile/break/continue/goto
- switch/case/default
- arithmetic, bitwise, logical operations
- int (and voids for functions) types
- extern/static/auto storage classes
- functions, function calls
- it assembles/links via gcc so you can already call functions like `putchar()`
Now I'm going to start implementing the rest of types, and maybe a preprocessor. Eventually I want to implement such a subset of C11, to compile more real world projects.
I'd be grateful for input on the code. It's has been a great meta-learning experience about my favorite language.
r/Compilers • u/Pure_Treat6246 • May 10 '26
PhysCC: A DSL Compiler for Physics Simulations (SYCL, MPI, AVX2)
I’ve been working on PhysCC, an open-source tool designed to bridge the gap between high-level physics equations and low-level hardware optimization.
The problem: Writing boilerplate for SYCL, MPI, or AVX2 stencils is tedious. The solution: You write a simple equation like u = u + dt * lap(u) and PhysCC generates the optimized backend code.
Key Features:
- Multi-backend support (Single-core, OpenMP, MPI, SYCL, CUDA).
- AI-informed pass: It analyzes the PDE type (Hyperbolic, Parabolic, Elliptic) and suggests optimal work-group sizes for Intel Iris Xe.
- Built-in visualization script for heatmaps.
It’s still a work in progress, but I’d love to hear your thoughts on the codegen or the feature extraction logic!
https://github.com/NikosPappas/PhysCC
r/Compilers • u/TrustSig • May 10 '26
Building a Wasm-in-Wasm Virtualizer (with JIT decrypted paged memory)
trustsig.euWebAssembly is way too easy to decompile. To fix this, I built a virtualization pipeline that takes a normal Wasm file and compiles it into a hardened version.
The original logic is destroyed and replaced with encrypted bytecode that runs inside a hidden, internal interpreter.
I just finished a step-by-step guide on how I built it. Here is what's inside:
- Designing a custom, randomized instruction set to break standard decompilers.
- Building a zero-allocation VM in Rust that doesn't need a heap or a memory allocator.
- Implementing JIT page decryption using a sliding window to hide your logic from memory scrapers.
- Using the Walrus crate to automate the AST rewriting and bytecode injection.
The end result is a Wasm binary that looks like cryptographic noise to anyone trying to reverse-engineer it.
r/Compilers • u/AppledogHu • May 09 '26
Stuck trying to self-host from assembly
Hi! I wrote my own CPU emulator (the SD-8516), and I am trying to get a C compiler working on it. I have gotten quite far, the big thing was understanding the symbol table, but I got stuck because I made the symbol table only 16 bits and I had to rewrite everything because it couldn't hold a 24 bit pointer. Now it works and it can compile functions like strcmp and strlen (yay!) but I am completely lost as to what to do next. I'm getting a bit desperate. AI can't help me, it's not smart enough to figure this stuff out, and I am thinking, maybe I better try and rewrite it again. The problem is it's in assembly, so I have translate anything I get into my own custom assembly language. The faster I can get C up the better! Its currently a one pass compiler with no AST. My plan was to compile a C version of itself, but its getting too large to fit in my brain. Maybe what I need is to try rewriting it again but using ASTs? Whats an AST? ._.
Question: Are there any books that contain practical code examples, in C, that can be used during the bootstrapping process? Once I get a C version to compile itself I am sure I will be in business! Right now I can compile a kind of 'B with char pointers and arrays' (no for loops yet but we can do while). I had thought maybe there was a series of C compilers out there that could compile themselves and I could slowly bring up C that way. But now I realize its the same problem with trying to write a back-end. The C compiler is of course intimately connected with the system architecture. I wonder though, if there isn't some pseudo-code C compiler out there, somewhere, that I could study?
r/Compilers • u/TrustSig • May 09 '26
From Bytecode to CFGs inside our online WebAssembly reverse engineering tool
trustsig.euJust as a privacy note (you can double-check with dev tools): This tool works fully offline, we do NOT send any uploaded binaries or data to our backend.
This tool was built by our WebAssembly analysis team, originally it was for internal use only but we have decided to make it public and free for everyone, forever.
Please do leave feedback in the comments! We'd love to hear what you think and how we can improve it even further. It is still heavily in a barebones beta phase, as we work on adding more features.
(This is not an advertising post for any paid or free services of TrustSig, this post is strictly to share a blog post on how we made it, and the tool itself)
r/Compilers • u/OtherwisePush6424 • May 09 '26
Inside cmd/compile: how Go lowers AST to SSA and machine code
blog.gaborkoos.comWalks through Go compiler internals with emphasis on IR/SSA transitions and optimization behavior (inlining context, escape analysis interactions, BCE/nil-check elimination, and lowering to target backends). It also includes a tooling workflow for inspecting each phase directly.
r/Compilers • u/mttd • May 08 '26
Practical Formal Verification for MLIR Programs
arxiv.orgr/Compilers • u/AfraidAct1830 • May 08 '26
Hypervisor role vs ML compiler startup
I am a fresh grad and deciding between two paths.
One is a systems role at Siemens DISW involving hypervisor virtualization Intel Arc and OS level work.
The other is a startup doing ML optimization or compiler related work on three layers
I love low level topics and never really got in ML stuff. I like compilers OS internals architecture performance etc. I have read compiler material and built a small AOT compiler before.
My concern with Siemens is ending up in slow corporate maintenance work especially it being in a third world regional office.
My concern with the startup is that the compiler side may mostly be AI hype or infra glue instead of real systems or optimization work. They do claim to be optimizing across all three layers Abstract layer (Quantization etc), MLIR (Compiler) and SIMD compute kernels. Engineers over there have max 4 YOE not just in ML compilers/optimizations but like as in total experience. Although they did start with this work.
Long term I care more about durable technical depth and hard to automate skills than hype.
For people working in systems compilers virtualization or AI infra
Which path do you think ages better over 5 to 10 years
How transferable is hypervisor and systems experience into other fields
How do you identify whether an ML compiler startup is doing real technical work or mostly marketing and if they will bait and switch me into high level ML stuff (a big no no)
How saturated or expected to be saturated is ML compiler Path
I am trying to optimize more for long term technical growth than immediate salary.
Thanks in advance for your advice