Skip to content
HN On Hacker News ↗

QBE - Compiler Backend

▲ 97 points 28 comments by smartmic 2mo ago HN discussion ↗

Pangram verdict · v3.3

We believe that this document is fully human-written

1 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 2 of 2
SEGMENTS · AI 0 of 2
WORD COUNT 398
PEAK AI % 1% · §2
Analyzed
May 8
backend: pangram/v3.3
Segments scanned
2 windows
avg 199 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 398 words · 2 segments analyzed

Human AI-generated
§1 Human · 1%

Intro Docs Users Releases Code

QBE is a compiler backend that aims to provide 70% of the performance of industrial optimizing compilers in 10% of the code. QBE fosters language innovation by offering a compact user-friendly and performant backend. The size limit constrains QBE to focus on the essential and prevents embarking on a never-ending path of diminishing returns.

Overview The C codebase of QBE is intended to remain hobby-scale and pleasant to hack on. Despite the small footprint, QBE provides a number of optimizations with good impact/weight ratio. It also facilitates integration with foreign systems by implementing the C ABI in full. This means that programs compiled by QBE can trivially call into C, and vice versa. The current version of QBE can target amd64 (linux and osx), arm64, and riscv64.

More QBE features

Full support for the C ABI. IEEE 32 and 64 bits floating point numbers. Uniform and simple SSA-based intermediate language (IL). Same IL used at all compilation stages. Copy elimination. Sparse conditional constant propagation. Dead instructions elimination. Registerization of small stack slots. Split spiller and register allocator thanks to SSA form. (Simpler and faster than graph coloring.) Smart spilling heuristic based on loop analysis. Linear register allocator with hinting. Matching and use of amd64 addressing modes. Super quick compile times (2 seconds on a Core 2 Duo with CFLAGS=-O2).

Get started The snippet below is a self-contained program written in QBE intermediate language that shows how to define simple functions, perform arithmetic on words, and call into a variadic C function.

function w $add(w %a, w %b) { # Define a function add @start %c =w add %a, %b # Adds the 2 arguments ret %c # Return the result } export function w $main() { # Main function

§2 Human · 1%

@start %r =w call $add(w 1, w 1) # Call add(1, 1) call $printf(l $fmt, ..., w %r) # Show the result ret 0 } data $fmt = { b "One and one make %d!\n", b 0 } Copy the example in a file, then compile it with qbe -o out.s file.ssa && cc out.s. The output binary should run smoothly, leaning on your local libc to print its output to the terminal.

To learn more about the QBE intermediate language, go read the language documentation.

Community For patches and discussions subscribe to ~mpu/qbe@lists.sr.ht. Come talk to us on irc.eigenstate.org in the #myrddin channel.