神刀安全网

Qbe: a new llvm alternative

Qbe: a new llvm alternative QBE

A Quick Backend

QBE aims to be a pure C embeddable backend that provides 70% of the performance of advanced compilers in 10% of the code. Its small size serves both its aspirations of correctness and our ability to understand, fix, and improve it. It also serves its users by providing trivial integration and great flexibility.

Code

git clone git://c9x.me/<a href="http://c9x.me/git/?p=qbe.git;a=summary">qbe.git</a>

QBE is known to compile and pass its test suite on the following x64 operating systems.

  • Linux
  • FreeBSD
  • Mac OS X

Compiling QBE requires GNU Make and a C99 compiler. The HTML documentation is generated from regular text files by an OCaml program.

Status

QBE is in constant change. It is a young project and I still have manyideas to try. The core of it should now work pretty reliably for simple language experiments. To palliate the youth and lack of users, complex parts of the register allocator and the ABI implementation have been thoroughly fuzz tested.

Some smartness is already baked in at this time.

  • Very good compatibility with C code.
  • IEEE floating points support.
  • SSA -based intermediate language.
  • 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.
  • Recognizes and uses x64 addressing modes.
  • Uniform and simple IL syntax.
  • Gets compiled really quick (2 seconds on my Core 2 Duo with CFLAGS=-O2 ).

You might encounter some friction because of these points.

  • Only x64 platforms are currently supported. ARM support is planned.
  • Computed goto (switch) is not provided. It will be implemented.
  • Some hardcoded limits might be hit. But they can also be tweaked easily.
  • Text input only. A C library interface is work in progress.

Documentation

  • Thereference document for QBE’s intermediate language.

  • A shortcomparison with LLVM.

  • Abibliography useful to understand and hack QBE.

  • A simple description of theUNIX x64 ABI used in QBE.

A few frontends targeting QBE already exist.

  • A tutorial frontend is included in the distribution in the minic/ directory. In less than 1000 lines it compiles a dumbed-down C. Small benchmarks are provided too.
  • Some ongoing work on the Myrddin compiler aims to use QBE as backend.
  • Two frontends for Brainfuck and C were written in Myrddin by Andrew Chambers.
  • A more ambitious C compiler from the suckless fame.

Hello World

The intermediate language used as input to QBE is spoken by all the compilation passes and can be dumped anytime in the compiler pipeline using command line options. The example program below can call the C function printf out of the box, with no special syntax. C compatibility is baked in. Similarly C can call any function compiled with QBE.

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 }

Toss the above in a file, then run qbe -o asm.s file.ssa && cc asm.s . You should get a binary executable file ready to rock.

Contact

To report a problem with QBE or ask a question: bugs@c9x.me .

IRC: irc.eigenstate.org in #myrddin (nick: mpu).

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Qbe: a new llvm alternative

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址