Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

llvm.txt (3417B)

      1                       ===========
      2                       QBE vs LLVM
      3                       ===========
      6 Both QBE and LLVM are compiler backends using an SSA
      7 representation.  This document will explain why LLVM
      8 does not make QBE a redundant project.  Obviously,
      9 everything following is biased, because written by me.
     11 - Scope
     12 -------
     14 QBE is a much smaller scale project with different goals
     15 than LLVM.
     17   * QBE is for amateur language designers.
     19     It does not address all the problems faced when
     20     conceiving an industry-grade language.  If you are
     21     toying with some language ideas, using LLVM will
     22     be like hauling your backpack with a truck, but
     23     using QBE will feel more like riding a bicycle.
     25   * QBE is about the first 70%, not the last 30%.
     27     It attempts to pinpoint, in the extremely vast
     28     compilation literature, the optimizations that get
     29     you 70% of the performance in 10% of the code of
     30     full blown compilers.
     32     For example, copy propagation on SSA form is
     33     implemented in 160 lines of code in QBE!
     35   * QBE is extremely hackable.
     37     First, it is, and will remain, a small project
     38     (less than 8 kloc).  Second, it is programmed in
     39     non-fancy C99 without any dependencies.  Third,
     40     it is able to dump the IL and debug information in
     41     a uniform format after each pass.
     43     On my Core 2 Duo machine, QBE compiles in half a
     44     second (without optimizations).
     46 - Features
     47 ----------
     49 LLVM is definitely more packed with features, but there
     50 are a few things provided in QBE to consider.
     52   * LLVM does NOT provide full C compatibility for you.
     54     In more technical terms, any language that provides
     55     good C compatibility and uses LLVM as a backend
     56     needs to reimplement large chunks of the ABI in
     57     its frontend!  This well known issue in the LLVM
     58     community causes a great deal of duplication
     59     and bugs.
     61     Implementing a complete C ABI (with struct arguments
     62     and returns) is incredibly tricky, and not really
     63     a lot of fun.  QBE provides you with IL operations
     64     to call in (and be called by) C with no pain.
     65     Moreover the ABI implementation in QBE has been
     66     thoroughly tested by fuzzing and manual tests.
     68   * LLVM IL is more cluttered with memory operations.
     70     Implementing SSA construction is hard.  To save its
     71     users from having to implement it, LLVM provides
     72     stack slots.  This means that one increment of
     73     a variable `v` will be composed of three LLVM
     74     instructions: one load, one add, and one store.
     76     QBE provides simple non-SSA temporaries, so
     77     incrementing `v` is simply done with one instruction
     78     `%v =w add %v, 1`.
     80     This could seem cosmetic, but dividing the size of
     81     the IL by three makes it easier for the frontend
     82     writers to spot bugs in the generated code.
     84   * LLVM IL is more cluttered with type annotations and
     85     casts.
     87     For the sake of advanced optimizations and
     88     correctness, LLVM has complex IL types.  However,
     89     only a few types are really first class and many
     90     operations of source languages require casts to be
     91     compiled.
     93     Because QBE makes a much lighter use of types, the
     94     IL is more readable and shorter.  It can of course be
     95     argued back that the correctness of QBE is jeopardized,
     96     but remember that, in practice, the large amount
     97     of casts necessary in LLVM IL is undermining the
     98     overall effectiveness of the type system.