What is LLVM?

This is an introduction to understand what is the?LLVM?compiler infrastructure. This blog should be enough for the engineer who want to know what to get familiar with llvm (Low Level Virtual Machine)is.

LLVM is a compiler framework which is designed to support transparent, lifelong program analysis and transformation for arbitrary programs, by providing high-level information to compiler transformations at compile-time, link-time, run-time, and in idle time between runs. LLVM defines a common, low-level code representation in Static Single Assignment (SSA) form, with several novel features: a simple, language-independent type-system that exposes the primitives commonly used to implement high-level language features; an instruction for typed address arithmetic; and a simple mechanism that can be used to implement the exception handling features of high-level languages (and setjmp/longjmp in C) uniformly and efficiently.

LLVM is nicely written: its architecture is?way?more modular than other compilers framework .

?LLVM have become an industrial-strength compiler framework where lots of Proprietary compiler use LLVM as a backend.

Modern applications are increasing in size, change their behavior significantly during execution, support dynamic extensions and upgrades, and often have components written in multiple different languages. While some applications have small hot spots, others spread their execution time evenly throughout the application . In order to maximize the efficiency of all of these programs, we believe that program analysis and transformation must be performed throughout the lifetime of a program. Such “lifelong code optimization” techniques encompass inter-procedural optimizations performed at link-time (to preserve the benefits of separate compilation), machine-dependent optimizations at install time on each system, dynamic optimization at runtime, and profile-guided optimization between runs (“idle time”) using profile information collected from the end-user.

LLVM — Low-Level Virtual Machine — a compiler framework that aims to make lifelong program analysis and transformation available for arbitrary software, and in a manner that is transparent to programmers. LLVM achieves this through two parts:

(a) code representation with several novel features that serves as a common representation for analysis, transformation, and code distribution;

(b) compiler design that exploits this representation to provide a combination of capabilities that is not available in any previous compilation approach we know of.

LLVM Phases

There are:

  • The?front end, which takes your source code and turns it into an?intermediate representation?or IR. This translation simplifies the job of the rest of the compiler, which doesn’t want to deal with the full complexity of C++ source code.
  • The?passes, which transform IR to IR. In ordinary circumstances, passes usually optimize the code: that is, they produce an IR program as output that does the same thing as the IR they took as input, except that it’s faster.?This is where you want to hack.?Your research tool can work by looking at and changing IR as it flows through the compilation process. The LLVM Pass Framework is an important part of the LLVM system, because LLVM passes are where most of the interesting parts of the compiler exist.

The?back end, which generates actual machine code. The backend of LLVM features a target-independent code generator that may create output for several types of target CPUs — including X86, PowerPC, ARM, and SPARC. The backend may also be used to generate code targeted at SPUs of the Cell processor or GPUs to support the execution of compute kernels.

In upcoming tutorial we will discuss about how to get start with the LLVM.

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

社区洞察

其他会员也浏览了