<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Llvm-and-Popular-Compilers on 兜忆轩 | Cedric's Compiler Notes</title><link>https://douyixuan.github.io/tags/llvm-and-popular-compilers/</link><description>Recent content in Llvm-and-Popular-Compilers on 兜忆轩 | Cedric's Compiler Notes</description><image><title>兜忆轩 | Cedric's Compiler Notes</title><url>https://douyixuan.github.io/images/papermod-cover.png</url><link>https://douyixuan.github.io/images/papermod-cover.png</link></image><generator>Hugo -- 0.146.0</generator><language>en-us</language><lastBuildDate>Mon, 15 Apr 2024 07:09:24 +0100</lastBuildDate><atom:link href="https://douyixuan.github.io/tags/llvm-and-popular-compilers/index.xml" rel="self" type="application/rss+xml"/><item><title>llvm and popular compilers</title><link>https://douyixuan.github.io/posts/compiler/llvm-and-popular-compilers/</link><pubDate>Mon, 15 Apr 2024 07:09:24 +0100</pubDate><guid>https://douyixuan.github.io/posts/compiler/llvm-and-popular-compilers/</guid><description>&lt;h1 id="llvm-and-popular-compilers">LLVM And Popular Compilers&lt;/h1>
&lt;p>大多数人印象中的的程序典型编译流程：&lt;/p>
&lt;ol>
&lt;li>预处理 ( Preprocessing )&lt;/li>
&lt;li>编译 ( Compilation )&lt;/li>
&lt;li>汇编 ( Assemble )&lt;/li>
&lt;li>链接 ( Linking )&lt;/li>
&lt;/ol>
&lt;p>这也是 Unix 操作系统上 GCC 编译器编译 C 代码的编译流程。&lt;/p>
&lt;h2 id="llvm">LLVM&lt;/h2>
&lt;p>LLVM 则是一个 modulized 的编译器基础设施，提供了编译器开发所需的各种工具和库。&lt;/p>
&lt;p>LLVM 有自己的语言，LLVM assembly language，有自己的一套&lt;a href="https://llvm.org/docs/LangRef.html#syntax">语法&lt;/a>和&lt;a href="https://llvm.org/docs/LangRef.html#high-level-structure">结构&lt;/a>，是一个静态单赋值的代码表示（code representation），同时提供了类型安全、接近于汇编（low level）的运算操作，还有很强的灵活性，几乎可以表示一切其他语言。&lt;/p>
&lt;p>设计成三种等价的不同形式来使用。&lt;/p>
&lt;h3 id="llvm-assembly-language">LLVM assembly language&lt;/h3>
&lt;p>是文件文本存储格式。文件后缀是 &lt;code>.ll&lt;/code>。
&lt;a href="https://godbolt.org/z/Whec98z15">示例&lt;/a>&lt;/p>
&lt;h3 id="llvm-bitcode">LLVM bitcode&lt;/h3>
&lt;p>LLVM bitcode 是文件二进制存储格式，文件后缀是 &lt;code>.bc&lt;/code>。&lt;/p>
&lt;h3 id="llvm-ir-intermediate-representation">LLVM IR (Intermediate Representation)&lt;/h3>
&lt;p>LLVM IR 是代码表示在内存中的表示。因为通常用作其他语言实现的中间表示，所以被称作 IR ，官方设计目标是成为 universal IR。&lt;/p>
&lt;p>下面统一称作 LLVM IR。&lt;/p>
&lt;p>LLVM 项目提供了完善的工具链，提供以下编译能力：&lt;/p>
&lt;ul>
&lt;li>AOT(Ahead of Time) 静态编译器，提前把 LLVM IR 编译到可执行文件，直接运行&lt;/li>
&lt;li>JIT(Just in Time) 动态解释器，运行时先编译，再执行&lt;/li>
&lt;li>Interpreter 动态解释器，运行时直接解释执行 LLVM IR&lt;/li>
&lt;/ul>
&lt;p>&lt;img alt="AOT-JIT-Interpreter" loading="lazy" src="../../posts/compiler/llvm-and-popular-compilers/image.png">&lt;/p></description></item></channel></rss>