DEV Community

Cover image for Overview of LLVM Architecture
Plume
Plume

Posted on • Updated on

Overview of LLVM Architecture

First of all, let's see a graph of LLVM Architecture.

As you can see in Picture 1, source code of arbitrary language(C, C++, Go, etc) are compiled by an appropriate compiler to LLVM-IR(LLVM's Intermidiate code Representation) codes, these LLVM-IR codes are saved in .o files(object files).
Then, an Optimizing Linker is used to link the .o files, libraries of the native system, and libraries of LLVM Architecture into a .exe file, the .exe file contains both LLVM-IR and native code(Machine Code which can run on the Host Machine).

Now, let's have a break

Before we continue describing Picture 1, we'd better illustrate the meaning of Offline and Profile & Trace Info first.

According to the context, Offline can mean:

  1. While .exe file is not running(in idle time).
  2. After .exe file is generated.
  3. After the program(.exe file) is installed.
  4. On Host Machine(User's Computer).
  5. Without source code(.c, .cpp, .go, etc).

Profile means:

Information about which regions of the .exe file's code runs more frequently on Host Machine, these frequently-run code regions are called Hot Codes.

Continue

After .exe file is generated, the Run-time Optimizer is used to capture Profile & Trace Info, use the information contained by Profile to find Hot Code, optimize the LLVM-IR contained by .exe file to improve Hot Code's performance at the cost of Cold Code's performance. This kind of optimization is called Profile-guided Optimization.
Then, the Run-time Optimizer passes the generated Native Code to Host Machine to run it.

Sometimes, the Profile-guided Optimization is too sophisticated to perform at run-time or the Profile-guided Optimization is valuable enough to retain long-term, so the Profile information is passed to the Offline Reoptimizer, the Offline Reoptimizer use the information contained by Profile to find Hot Code, optimize the LLVM-IR contained by .exe file to improve Hot Code's performance at the cost of Cold Code's performance.
Then, the Offline Reoptimizer passes the reoptimized LLVM-IR and Native Code to .exe file to save them long-term.

Top comments (0)