Getting Started With LLVM?
abhinav Ashok kumar
Curating Insights & Innovating in GPU Compiler | Performance Analyst at Qualcomm | LLVM Contributor | Maintain News Letter | AI/ML in Compiler
In order to get start with the LLVM you have to install it. To know what llvm is you can visit my previous blog (llvm.org official llvm website).
Its easy to build llvm from scratch using CMake .Usually, you only need to build LLVM itself: your system-provided Clang will do just fine as long as the versions match (although there are?instructions for building Clang?too).
You can even see the following link to see the step to build for the llvm.
Understanding LLVM IR
LLVM IR is?a low-level intermediate representation used by the LLVM compiler framework. You can think of LLVM IR as a platform-independent assembly language with an infinite number of function local registers.
To work with llvm we should know about the llvm IR.
Here is the diagram of the llvm ir lets discuss about them in detail. We can understand from the diagram that Module contain?Function, which contain?BasicBlock, which contain?Instruction. Everything but Module descends from?Value.
Most things in LLVM—including Function, BasicBlock, and Instruction—are C++ classes that inherit from an omnivorous base class called?Value. A Value is any data that can be used in a computation—a number, for example, or the address of some code. Global variables and constants (a.k.a. literals or immediates, like 5) are also Values.
Use below mentioned command to generate a llvm ir with clang
$clang -S -emit-llvm -o source.ll source.c
Here on these IR we can run various analysis and transformation Pass.
A Compiler pass refers to?the traversal of a compiler through the entire program.?
All LLVM passes are?subclasses of the Pass class, which implement functionality by overriding virtual methods inherited from Pass?.
LLVM passes are one of the most interesting part of the complete framework. Which will I discuss in upcoming blog post for next article.