QBE compiler backend

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

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
@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