Exp 11
Exp 11
11
• LLVM is an acronym that stands for low level virtual machine. It also refers to a
compiling technology called the LLVM project, which is a collection of modular and
reusable compiler and toolchain technologies.
• The LLVM project has grown beyond its initial scope as the project is no longer
focused on traditional virtual machines.
• LLVM is a compiler and a toolkit for building compilers, which are programs that
convert instructions into a form that can be read and executed by a computer. The
LLVM project is a collection of modular and reusable compiler and tool chain
technologies.
• LLVM helps build new computer languages and improve existing languages.
• It automates many of the difficult and unpleasant tasks involved in language
creation, such as porting the output code to multiple platforms and architectures.
HOW DOES A LLVM COMPILER WORK?
• On the front end, the LLVM compiler infrastructure uses clang-a compiler for
programming languages C, C++ and CUDA - to turn source code into an interim
format. Then the LLVM clang code generator on the back end turns the interim
format into final machine code.
• The compiler has five basic phases:
• Lexical Analysis-Converts program text into words and tokens (everything apart from
words, such as spaces and semicolons).
• Parsing Groups the words and tokens from the lexical analysis into a form that makes
sense. Semantic Analyser Identifies the types and logics of the programs.
• Optimization-Cleans the code for better run-time performance and addresses
memory-related issues.
• Code Generation-Turns code into a binary file that is executable LLVM COMPILER.
ARCHITECTURE:
At the frontend you have Perl and many other high level Languages. At the backend, you
have the natives code that runs directly on the machine.
At the centre is your intermediate code representation If every high level language can be
represented in this LLVM IR format, then analysis tools based on this IR can be easily reused-
that is the basic rationale.
The LLVM project/infrastructure: This is an umbrella for several projects that, together, form
a complete compiler, frontends, backends, optimizers, assemblers, linkers, libc++, compiler-
rt, and a JIT engine. The word "LLVM" has this meaning, for example, in the following
sentence: "LLVM consists of several projects".
An LLVM-based compiler: This is a compiler built partially or completely with the LLVM
infrastructure. For example, a compiler might use LLVM for the frontend and backend but
use GCC and GNU system libraries to perform the final link. LLVM has this meaning in the
following sentence, for example: "I used LVM to compile C programs to a MIPS platform".
LLVM libraries: This is the reusable code portion of the LLVM infrastructure. For example,
LLVM has this meaning in the sentence: "My project uses LLVM to generate code through its
Just-in-Time compilation framework".
LVM core: The optimizations that happen at the intermediate language level and the
backend algorithms firm the LLVM core where the project started. LLVM has this meaning in
the following sentence: "LLVM and Clang are two different projects".
The LLVM IR: This is the LLVM compiler intermediate representation. LLVM has this meaning
when used sentences such as "I built a frontend that translates my own language to LLVM".
Three Primary LLVM Components:
1. The LLVM Virtual Instruction Set.
2. The common language- and target-independent IR. 1. Internal (IR) and external
(persistent) representation.
3. Internal(IR) and external(persistent) representation.
WHY LLVM?
USES OF LLVM:
LLVM is a modular compiler infrastructure: - Primary focus is on providing good interfaces &
robust components-LLVM can be used for many things other than simple static compilers.
LVM provides language-and target-independent components:- Does not force use of JIT, GC,
or a particular object model-Code from different languages can be linked together and
optimized.
LLVM is well designed and provides aggressive functionality: Inter procedural optimization,
link- time/install-time optimization today.
CONCLUSION:
Hence, we have successfully studied about LLVM and code generation using LLVM.