1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
QBE compiler backend
* [1]Intro
* [2]Docs
* [3]Users
* [4]Releases
* [5]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 [6]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
@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 [7]the
language documentation.
Community
* For patches and discussions subscribe to [8]~mpu/qbe@lists.sr.ht.
* Come talk to us on irc.eigenstate.org in the #myrddin channel.
References
1. https://c9x.me/compile/
2. https://c9x.me/compile/docs.html
3. https://c9x.me/compile/users.html
4. https://c9x.me/compile/releases.html
5. https://c9x.me/compile/code.html
6. https://en.wikipedia.org/wiki/Static_single_assignment_form
7. https://c9x.me/compile/doc/il.html
8. https://lists.sr.ht/~mpu/qbe/
|