News for hackers. Stuff that matters.
Re:GCC Rust Approved by GCC Steering Committee by nrclark on Monday July 11, 2022 @11:39AM (#32057577)
Compilers are often implemented as a front-end/back-end split.

The front-end compiles your input language (C, C++, Rust, etc) down to a low-level language called an Intermediate Representation. Then the back-end of the compiler optimizes the IR and compiles it into object code. A family of compilers will usually share the back-end.

This kind of split allows for deduplication across different compilers in the same family, and also makes it easier to design a new language without having to fully re-implement everything about the compiler yourself.

In GCC, these are bundled together as a common project afaik. In Clang/LLVM, these are split into the front-end (clang) and the back-end (LLVM).

Re:GCC Rust Approved by GCC Steering Committee by FrankHB on Wednesday July 13, 2022 @06:38AM (#32080896)
In some stricter sense, back-end is for target-depending stuff like ISA-dependent code generation. A great deal of work in both GCC and LLVM is in the so-called mid-end. Both have more than one IRs in the pipeline after the front-end.
Re:GCC Rust Approved by GCC Steering Committee by not2b on Monday July 11, 2022 @07:09PM (#32063348)
GCC also has front ends (compile many languages into a a common form, GIMPLE), a "middle end" (optimization), and many back ends (for different processor architectures).
Re:GCC Rust Approved by GCC Steering Committee by sdfhdhjdw3 on Monday July 11, 2022 @11:57AM (#32057843)
Oh damn, THIS is what the "intermediate representation" i keep hearing about is.

I knew that Julia uses LLVM. I also knew that Julia has something called IR, but i didn't know what it was. So Julia's IR is probably LLVM's IR...

Re:GCC Rust Approved by GCC Steering Committee by jcranmer on Monday July 11, 2022 @12:02PM (#32057919)
I suspect Julia has its own IR that is later lowered into LLVM IR. One of the aspects of multiple compilers is that it's basically a massive tower of IRs that get progressively lowered into lower- and lower-level IRs.
Re:GCC Rust Approved by GCC Steering Committee by ChrisRackauckas on Monday July 11, 2022 @10:39PM (#32064935)
https://stackoverflow.com/a/43456211/1544203 is a little old, but still very much relevant. Julia has an untyped IR that it lowers into, then typed IR on which inference is performed, then it lowers to LLVM which lowers it to native. You can introspect the IR at these steps by taking a function call and doing `@code_lowered`, `@code_typed`, `@code_llvm`, and `@code_native`.

For some examples, the compiler plugins interface acts on typed IR, so things like Diffractor for automatic differentiation or JET static analysis and EscapeAnalysis.jl act there. Notably, Zygote automatic differentiation acted on the untyped IR. GPUCompiler.jl does some operations on the typed IR then lowers to the LLVM IR level and then intercepts the normal compilation process to choose alternative backends (e.g. compile to .ptx for compilation of native Julia to CUDA). Enzyme.jl uses the Enzyme LLVM-based automatic differentiation, so it does some actions on the typed IR before lowering to LLVM and then injecting the Enzyme LLVM pass before compiling via GPUCompiler.jl (now to the normal CPU backend).

Re:GCC Rust Approved by GCC Steering Committee by borodi on Monday July 11, 2022 @12:01PM (#32057907)
Julia has an IR called Julia IR that is used before compiling to LLVM IR, it's a bit higher level than LLVM ir
Re:GCC Rust Approved by GCC Steering Committee by kzrdude on Monday July 11, 2022 @12:25PM (#32058242)
Rustc has HIR, MIR and then finally llvm IR