Getting Started With LLVM?
Credit goes to :- https://llvm.org/

Getting Started With LLVM?

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.


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.

  • A?Module?represents a source file. Modules represent the top-level structure in an LLVM program.
  • ?Function, as name suggest they are the function written in our C++/C languages. In llvm both method and function correspond to the LLVM function.
  • Aside from declaring its name and arguments, a Function is mainly a container of?BasicBlock. The?basic block?is a familiar concept from compilers, but for our purposes, it’s just a contiguous chunk of instructions.
  • An?Instruction, in turn, is a single code operation. The level of abstraction is roughly the same as in?RISC-like machine code: an instruction might be an integer addition, a floating-point divide, or a store to memory, for example.

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.

#gcc #coding #cplusplus #developer #fresher #compiler

要查看或添加评论,请登录

abhinav Ashok kumar的更多文章

  • Parallel programming Evolution

    Parallel programming Evolution

    Parallel programming has revolutionized how we leverage modern computing power! From instruction-level parallelism…

  • LLVM vs. GCC: A Comprehensive Comparison

    LLVM vs. GCC: A Comprehensive Comparison

    When it comes to compiling C, C++, and other languages, LLVM and GCC are two of the most widely used compiler…

  • Exploring TVM for Beginners: A Must-Read Guide for Compiler Enthusiasts

    Exploring TVM for Beginners: A Must-Read Guide for Compiler Enthusiasts

    For those diving into machine learning compilers, TVM is a powerful tool that optimizes deep learning models for…

  • Optimizing LLVM Passes: Understanding Pass Execution Time

    Optimizing LLVM Passes: Understanding Pass Execution Time

    Optimizing LLVM passes is crucial for improving performance and efficiency for compiler engineers. A key aspect of this…

  • CPP MCQ Stack

    CPP MCQ Stack

    Welcome to Compiler Sutra — the place to be if you want to improve at C++ and compilers! Link :…

    1 条评论
  • Disabling LLVM Pass

    Disabling LLVM Pass

    ?? Disabling an LLVM Pass for Custom Compiler Modifications ?? LLVM is at the core of many modern compilers, and its…

    1 条评论
  • How LLVM Solve Traditional Compiler Problem m*n

    How LLVM Solve Traditional Compiler Problem m*n

    LLVM (Low-Level Virtual Machine) is a compiler framework that helps compiler developers to transform and build…

  • Pass In LLVM To Count the Number of Instructions in It

    Pass In LLVM To Count the Number of Instructions in It

    You can read the full tutorial here: Read the Full Tutorial This tutorial explores FunctionCount.cpp, a practical…

  • Unlocking C++11 part 2

    Unlocking C++11 part 2

    Hello, Tech Enthusiasts Here is the link for the Unlocking C++11 Part 1 The C++11 standard has transformed how we write…

    1 条评论
  • Unlocking C++11

    Unlocking C++11

    Hello, Tech Enthusiasts! The C++11 standard has transformed how we write C++ code by introducing new features to make…

社区洞察

其他会员也浏览了