diff options
Diffstat (limited to 'miniany/doc/c9x.me_compile.txt')
-rw-r--r-- | miniany/doc/c9x.me_compile.txt | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/miniany/doc/c9x.me_compile.txt b/miniany/doc/c9x.me_compile.txt new file mode 100644 index 0000000..a6e68d2 --- /dev/null +++ b/miniany/doc/c9x.me_compile.txt @@ -0,0 +1,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/ |