Cranelift
   HOME

TheInfoList



OR:

Cranelift (formerly known as Cretonne) is an optimizing
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
backend that converts a target-independent
intermediate representation An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
into
executable In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
machine code. It is written in
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH) ...
. The project started in 2016 and is currently developed by
Bytecode Alliance WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment. The main goal of W ...
. Unlike compiler backends such as LLVM that focus more on ahead-of-time compilation, Cranelift instead focuses on
just-in-time compilation In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is compilation (of computer code) during execution of a program (at run time) rather than before execution. This may consist of source code transl ...
with short compile time being an explicit goal of the project. As of 2023, Cranelift supports
instruction set architectures In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
such as
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
,
AArch64 AArch64, also known as ARM64, is a 64-bit version of the ARM architecture family, a widely used set of computer processor designs. It was introduced in 2011 with the ARMv8 architecture and later became part of the ARMv9 series. AArch64 allows ...
,
RISC-V RISC-V (pronounced "risk-five") is an open standard instruction set architecture (ISA) based on established reduced instruction set computer (RISC) principles. The project commenced in 2010 at the University of California, Berkeley. It transfer ...
, and IBM
z/Architecture z/Architecture, initially and briefly called ESA Modal Extensions (ESAME), is IBM's 64-bit complex instruction set computer (CISC) instruction set architecture, implemented by its mainframe computers. IBM introduced its first z/Architecture ...
.


History

Prior to the backend framework rewrite in 2020, the project made use of only one intermediate representation (IR) across all compilation stages prior to machine code emission, namely CLIF (Cranelift IR Format). The old design made use of instruction legalizations, which involved transforming the high-level IR continuously until each CLIF instruction corresponded to an instruction of the target machine, at which point the
executable code In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instructions", as opposed to a d ...
could be emitted. In 2020, the backend was rewritten to use a separate, machine-specific IR called ''VCode'' for later compilation stages instead. After this rewrite, a high-level input CLIF would be optimized by a middle layer before being lowered into ''VCode'', which would be further transformed by remaining passes in the backend. ''Peepmatic'', a tool used to generate a peephole optimizer from a
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging ...
(DSL), was also added, though it was later removed. In 2022, a new register allocator, which was adapted from the register allocator from IonMonkey, was added. In addition, the backend framework was reworked to utilize ISLE (
Instruction Selection __NOTOC__ In computer science, ''instruction selection'' is the stage of a compiler backend that transforms its middle-level intermediate representation (IR) into a low-level IR. In a typical compiler, instruction selection precedes both instructio ...
/Lowering Expressions DSL), another DSL in the project that was made to ease the development of the instruction selection stage in backends. The mid-end saw addition of optimization passes that make use of
e-graph In computer science, an e-graph is a data structure that stores an equivalence relation over terms of some language. Definition and operations Let \Sigma be a set of uninterpreted functions, where \Sigma_n is the subset of \Sigma consisting of ...
s in 2022. The optimization passes are enabled by default starting in 2023.


Applications

Currently, Cranelift is being utilized by multiple
WebAssembly WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment. The main goal of ...
runtimes, such as and , with performance comparable to LLVM-based runtimes. An alternative code generator for the Rust compiler that is powered by Cranelift also exists.


See also

*
Emscripten Emscripten is an LLVM/Clang-based compiler that compiles C and C++ source code to WebAssembly, primarily for execution in web browsers. Emscripten allows applications and libraries written in C or C++ to be compiled ahead of time and run effi ...
*
GNU Compiler Collection The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, Computer architecture, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes ...
*
LLVM LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...


References

{{reflist Compilers Free and open source compilers Register-based virtual machines Software using the Apache license