Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While I'm not a compiler expert, I believe that it boils down to the fact that you lose something in translation to C as opposed to translating to e.g. LLVM's intermediate language.</p> <p>If you think about the process of compiling to C, you create a compiler that translates to C code, then the C compiler translates to an intermediate representation (the in-memory AST), then translates that to machine code. The creators of the C compiler have probably spent a lot of time optimizing certain human-made patterns in the language, but you're not likely to be able to create a fancy enough compiler from a source language to C to emulate the way humans write code. There is a loss of fidelity going to C - the C compiler doesn't have any knowledge about your original code's structure. To get those optimizations, you're essentially back-fitting your compiler to try to generate C code that the C compiler knows how to optimize when it's building its AST. Messy.</p> <p>If, however, you translate directly to LLVM's intermediate language, that's like compiling your code to a machine-independent high-level bytecode, which is akin to the C compiler giving you access to specify exactly what its AST should contain. Essentially, you cut out the middleman that parses the C code and go directly to the high-level representation, which preserves more of the characteristics of your code by requiring less translation.</p> <p>Also related to performance, LLVM can do some really tricky stuff for dynamic languages like generating binary code at runtime. This is the "cool" part of just-in-time compilation: it is writing binary code to be executed at runtime, instead of being stuck with what was created at compile time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COJIT compilation is a big plus of course. I agree with what you are saying to an extent.. I just can't see what one "loses" when compiling to C but does not lose it if one compiles to LLVm, can you please elaborate on that a little bit. I mean I agree that one "loses" some structure with language transformation, but does the same not happen with LLVM or any other backend language?
      singulars
    2. COOK, imagine in C the statement `x++` - this could be compiled to copy x to another register, then increment the value of x, then return the copied (previous) value of x. A very obvious optimization is to compile this using a [test-and-set](http://en.wikipedia.org/wiki/Test-and-set) instruction, if the processor supports it, which does exactly this, but faster and atomically. If you represent the same statement in C as `x = x + 1`, it may not be optimized, because it's not exactly the same - you never need to return the previous value, right?
      singulars
    3. COSo to get this optimization, you would have to build _your_ compiler - the one generating c - to know the difference between the two and produce different c code depending on the situation. If you compile to LLVM bytecode, LLVM can infer this from your generated bytecode by e.g. checking if you look at the return value and deciding to optimize then. GCC _may_ be smart enough to do this, since this is such a trivial example, but it's just easier for an optimizer to find this sort of low hanging fruit when dealing with a lower level language, like LLVM bytecode, than when dealing with c.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload