2023-08-10 07:00:02

LLVM到底是什么?

我一直听说LLVM。它是Perl的,然后是Haskell的,然后有人在其他语言中使用它?是什么?

它与GCC(透视图=安全等)的确切区别是什么?


当前回答

根据“LLVM核心库入门”一书(c):

In fact, the name LLVM might refer to any of the following: The LLVM project/infrastructure: This is an umbrella for several projects that, together, form a complete compiler: frontends, backends, optimizers, assemblers, linkers, libc++, compiler-rt, and a JIT engine. The word "LLVM" has this meaning, for example, in the following sentence: "LLVM is comprised of several projects". An LLVM-based compiler: This is a compiler built partially or completely with the LLVM infrastructure. For example, a compiler might use LLVM for the frontend and backend but use GCC and GNU system libraries to perform the final link. LLVM has this meaning in the following sentence, for example: "I used LLVM to compile C programs to a MIPS platform". LLVM libraries: This is the reusable code portion of the LLVM infrastructure. For example, LLVM has this meaning in the sentence: "My project uses LLVM to generate code through its Just-in-Time compilation framework". LLVM core: The optimizations that happen at the intermediate language level and the backend algorithms form the LLVM core where the project started. LLVM has this meaning in the following sentence: "LLVM and Clang are two different projects". The LLVM IR: This is the LLVM compiler intermediate representation. LLVM has this meaning when used in sentences such as "I built a frontend that translates my own language to LLVM".

其他回答

LLVM是一个用于构造、优化和生成中间和/或二进制机器代码的库。

LLVM可以用作编译器框架,其中提供“前端”(解析器和词法分析器)和“后端”(将LLVM的表示转换为实际机器代码的代码)。

LLVM还可以充当JIT编译器——它支持x86/x86_64和PPC/PPC64程序集生成,具有旨在提高编译速度的快速代码优化。

不幸的是,从2013年起禁用了,在演示页面上可以使用从C或c++代码生成的LLVM机器代码。

LLVM(以前的意思是“低级虚拟机”,但不再是)是一个编译器基础设施,用c++编写,它是为编译时、链接时、运行时和“空闲时”优化用任意编程语言编写的程序而设计的。LLVM最初是为C/ c++实现的,它独立于语言的设计(以及它的成功)已经衍生出了各种各样的前端,包括Objective C、Fortran、Ada、Haskell、Java字节码、Python、Ruby、ActionScript、GLSL等等。

阅读这篇文章了解更多的解释 也可以看看Unladen Swallow

根据“LLVM核心库入门”一书(c):

In fact, the name LLVM might refer to any of the following: The LLVM project/infrastructure: This is an umbrella for several projects that, together, form a complete compiler: frontends, backends, optimizers, assemblers, linkers, libc++, compiler-rt, and a JIT engine. The word "LLVM" has this meaning, for example, in the following sentence: "LLVM is comprised of several projects". An LLVM-based compiler: This is a compiler built partially or completely with the LLVM infrastructure. For example, a compiler might use LLVM for the frontend and backend but use GCC and GNU system libraries to perform the final link. LLVM has this meaning in the following sentence, for example: "I used LLVM to compile C programs to a MIPS platform". LLVM libraries: This is the reusable code portion of the LLVM infrastructure. For example, LLVM has this meaning in the sentence: "My project uses LLVM to generate code through its Just-in-Time compilation framework". LLVM core: The optimizations that happen at the intermediate language level and the backend algorithms form the LLVM core where the project started. LLVM has this meaning in the following sentence: "LLVM and Clang are two different projects". The LLVM IR: This is the LLVM compiler intermediate representation. LLVM has this meaning when used in sentences such as "I built a frontend that translates my own language to LLVM".

LLVM的一个很好的总结是:

在前端,您有Perl和许多其他高级语言。在后端,有直接在机器上运行的本机代码。

中心是中间代码表示。如果每一种高级语言都可以用这种LLVM IR格式表示,那么基于这种IR的分析工具就可以很容易地重用——这是基本原理。

低级虚拟机(LLVM)

[Xcode构建过程]

替代方案:GCC(GNU编译器集合)。GDB -调试工具。支持更多语言和架构。

LLVM -是伞形项目(库集),它是不同项目的品牌名称(IR -中间表示,调试工具…)现在它已经不是虚拟机的缩写了。LLDB(LLVM Debugger) -调试工具。大公司支持

编译器:

Language FrontEnd(Many: Clang, Haskel, Swiftc...) -> Optimizer(Single) -> Backend(Many: arm64, x86_64, armv7...)

FrontEnd生成中间表示(IR, LLVM IR)。这种通用语言允许简单的缩放过程。如果你正在创建新的语言,你只需要对FrontEnd负责,如果你正在开发新的架构,你应该关注BackEnd。它是JVM中的一种.class文件,由ClassLoader使用[关于]

有三种等效的IR形式:

人类可读的汇编语言表示 内存编译器IR, [磁盘上位码表示方式]

Llvm-dis可用于将位码转换为人类可读的