LLVM到底是什么?

发布于 2024-08-23 03:41:46 字数 108 浏览 8 评论 0原文

我一直听说 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

感性不性感 2024-08-30 03:41:46

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.

枕花眠 2024-08-30 03:41:46

LLVM 的一个很好的总结是:

在此处输入图像描述

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

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

A good summary of LLVM is this:

enter image description here

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.

指尖微凉心微凉 2024-08-30 03:41:46

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

恏ㄋ傷疤忘ㄋ疼 2024-08-30 03:41:46

根据 'Getting Started With LLVM Core Libraries' 一书(三):

事实上,LLVM 这个名称可能指以下任何一个:

  • LLVM 项目/基础设施:这是多个项目的保护伞
    共同构成完整编译器的项目:前端,
    后端、优化器、汇编器、链接器、libc++、compiler-rt 和
    JIT 引擎。 “LLVM”一词具有这样的含义,例如,在
    下面这句话:“LLVM 由多个项目组成”。

  • 基于 LLVM 的编译器:这是部分构建的编译器,或者
    完全使用 LLVM 基础设施。例如,编译器可能
    前端和后端使用LLVM,但使用GCC和GNU系统
    库来执行最终链接。 LLVM 的含义是这样的
    例如下面这句话:“我使用 LLVM 来编译 C 程序
    MIPS 平台”。

  • LLVM 库:这是可重用的代码部分
    LLVM 基础设施。例如,LLVM 在以下内容中有这样的含义:
    句子:“我的项目使用 LLVM 通过其生成代码
    即时编译框架”。

  • LLVM 核心: 优化
    发生在中间语言级别和后端
    算法构成了项目开始的 LLVM 核心。 LLVM 有这个
    含义如下:“LLVM 和 Clang 是两个不同的
    项目”。

  • LLVM IR:这是 LLVM 编译器中间体
    表示。 LLVM 在诸如以下的句子中使用时具有此含义
    “我构建了一个将我自己的语言翻译为 LLVM 的前端”。

According to 'Getting Started With LLVM Core Libraries' book (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".

芸娘子的小脾气 2024-08-30 03:41:46

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.

你另情深 2024-08-30 03:41:46

低级虚拟机(LLVM)

[Xcode构建过程]

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

LLVM - 是伞式项目(库集),它是不同项目的品牌名称(IR - 中间表示、调试工具...),现在它不是虚拟机的缩写。 LLDB(LLVM 调试器) - 调试工具。由大公司支持

编译器:

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

前端生成中间表示(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:

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

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 by ClassLoader[About]

There are thee equivalent IR forms:

llvm-dis can be used to convert bitcode into human readable

一枫情书 2024-08-30 03:41:46

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文