LLVM到底是什么?
我一直听说 LLVM。它是 Perl 语言,然后是 Haskell 语言,然后有人用其他语言使用它?它是什么?
- 它与 GCC 到底有什么区别(视角 = 安全等)?
I keep hearing about LLVM all the time. It's in Perl, then it's in Haskell, then someone uses it in some other language? What is it?
- What exactly distinguishes it from GCC (perspectives = safety etc.)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
LLVM 是一个用于构建、优化和生成中间和/或二进制机器代码的库。
LLVM 可以用作编译器框架,您可以在其中提供“前端”(解析器和词法分析器)和“后端”(将 LLVM 表示形式转换为实际机器代码的代码)。
LLVM 还可以充当 JIT 编译器 - 它支持 x86/x86_64 和 PPC/PPC64 程序集生成,并具有旨在提高编译速度的快速代码优化。
不幸的是,自 2013 年起就被禁用了,但可以在演示页面使用由 C 或 C++ 代码生成的 LLVM 机器代码。
LLVM is a library that is used to construct, optimize and produce intermediate and/or binary machine code.
LLVM can be used as a compiler framework, where you provide the "front-end" (parser and lexer) and the "back-end" (code that converts LLVM's representation to actual machine code).
LLVM can also act as a JIT compiler – it has support for x86/x86_64 and PPC/PPC64 assembly generation with fast code optimizations aimed for compilation speed.
Unfortunately disabled since 2013, there was the ability to play with LLVM's machine code generated from C or C++ code at the demo page.
LLVM 的一个很好的总结是:
在前端,您有 Perl 和许多其他高级语言。在后端,您拥有直接在机器上运行的本机代码。
中心是中间代码表示。如果每种高级语言都可以用这种 LLVM IR 格式表示,那么基于该 IR 的分析工具就可以轻松重用 - 这就是基本原理。
A good summary of LLVM is this:
At the frontend you have Perl, and many other high level languages. At the backend, you have the natives code that run directly on the machine.
At the centre is your intermediate code representation. If every high level language can be represented in this LLVM IR format, then analysis tools based on this IR can be easily reused - that is the basic rationale.
LLVM(过去的意思是“低级虚拟机”,但现在不再是了)是一种用 C++ 编写的编译器基础结构,旨在对所编写的程序进行编译时、链接时、运行时和“空闲时”优化在任意编程语言中。 LLVM 最初是为 C/C++ 实现的,独立于语言的设计(以及成功)已经催生了各种各样的前端,包括 Objective C、Fortran、Ada、Haskell、Java 字节码、Python、Ruby、ActionScript、GLSL ,以及其他。
阅读本文以获取更多说明
另请查看Unladen Swallow
LLVM (used to mean "Low Level Virtual Machine" but not anymore) is a compiler infrastructure, written in C++, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. Originally implemented for C/C++, the language-independent design (and the success) of LLVM has since spawned a wide variety of front-ends, including Objective C, Fortran, Ada, Haskell, Java bytecode, Python, Ruby, ActionScript, GLSL, and others.
Read this for more explanation
Also check out Unladen Swallow
根据 'Getting Started With LLVM Core Libraries' 一书(三):
According to 'Getting Started With LLVM Core Libraries' book (c):
LLVM 基本上是一个用于构建编译器和/或面向语言的软件的库。基本要点是,虽然您有 gcc 这可能是最常见的编译器套件,但它并不是为了可重用而构建的。从 gcc 获取组件并使用它来构建您自己的应用程序是很困难的。 LLVM 通过构建一套“模块化且可重用的编译器和工具链技术”很好地解决了这个问题,任何人都可以使用这些技术来构建编译器和面向语言的软件。
LLVM is basically a library used to build compilers and/or language oriented software. The basic gist is although you have gcc which is probably the most common suite of compilers, it is not built to be re-usable ie. it is difficult to take components from gcc and use it to build your own application. LLVM addresses this issue well by building a set of "modular and reusable compiler and toolchain technologies" which anyone could use to build compilers and language oriented software.
低级虚拟机(LLVM)
[Xcode构建过程]
替代方案:GCC(GNU编译器集合) )。 GDB(GNU Debugger) - 调试工具。支持更多语言和架构。
LLVM - 是伞式项目(库集),它是不同项目的品牌名称(IR - 中间表示、调试工具...),现在它不是虚拟机的缩写。 LLDB(LLVM 调试器) - 调试工具。由大公司支持
编译器:
前端生成
中间表示(IR,LLVM IR)
。这种通用语言允许简单的缩放过程。如果你正在创建新的语言,你只负责前端,如果你正在开发新的架构,你应该关心后端。它是 JVM 中的一种.class
文件,由ClassLoader
使用< support>[关于]有三种等效的 IR 形式:
llvm-dis
可用于将位码
转换为人类可读
Low Level Virtual Machine(LLVM)
[Xcode build process]
Alternative: GCC(GNU Compiler Collection). GDB(GNU Debugger) - debug tool. Supports more languages and architectures.
LLVM - is umbrella project(set of libraries) it is a brand name with different projects(IR - Intermediate Representation, debug tool...) And now it is not acronym of Virtual Machine. LLDB(LLVM Debugger) - debug tool. Supported by Big companies
Compiler:
FrontEnd generates
Intermediate Representation (IR, LLVM IR)
. This common language allows simple scale process. If you are creating new language you are responsible only for FrontEnd, if you are developing new architecture you should take care about BackEnd. It is a kind of.class
file in JVM which are used byClassLoader
[About]There are thee equivalent IR forms:
llvm-dis
can be used to convertbitcode
intohuman readable
LLVM 编译器基础设施对于对代码执行优化和转换特别有用。它还包含许多具有不同用途的工具。 llvm-prof 是一个分析工具,允许您对执行进行分析以识别程序热点。 Opt 是一个优化工具,提供各种优化过程(例如死代码消除)。
重要的是,LLVM 为您提供了库来编写您自己的 Pass。例如,如果您需要对传递到程序的某些函数中的某些参数添加范围检查,则编写一个简单的 LLVM Pass 就足够了。
有关编写自己的 Pass 的更多信息,请查看http://llvm.org/docs/WritingAnLLVMPass.html< /a>
The LLVM Compiler Infrastructure is particularly useful for performing optimizations and transformations on code. It also consists of a number of tools serving distinct usages. llvm-prof is a profiling tool that allows you to do profiling of execution in order to identify program hotspots. Opt is an optimization tool that offers various optimization passes (dead code elimination for instance).
Importantly LLVM provides you with the libraries, to write your own Passes. For instance if you require to add a range check on certain arguments that are passed into certain functions of a Program, writing a simple LLVM Pass would suffice.
For more information on writing your own Pass, check this http://llvm.org/docs/WritingAnLLVMPass.html