创建LLVM的原因是什么?

发布于 2024-08-04 21:03:35 字数 214 浏览 12 评论 0原文

LLVM 和常规编译器有什么区别?
它是否更加动态,因此可以用来将通常非常动态的语言(即Javascript)编译为静态二进制代码? 创建它背后的原则是什么?
我知道关于编译器的《龙书》,但是对于 LLVM 有这样的东西吗?

编辑: 我发现这个有趣的项目。

What are the differences between an LLVM and a regular compiler?
Is it more dynamic and thus can be used to compile normally very dynamic languages (i.e. Javascript) into static binary code?
What are the principles behind creating one?
I know the Dragon Book for compilers, but is there such a thing for a LLVM?

EDIT:
I have found this interesting project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

草莓味的萝莉 2024-08-11 21:03:35

LLVM 和“常规编译器”之间有一些区别,我假设它的意思是“gcc”:

  • LLVM 是为整个程序分析(又名链接时分析)而设计的,因此它可以选择将代码编译为“ bitcode”,一种稍后可以重新分析的格式。
  • LLVM 提供了即时编译器 (JIT),以便它可以在程序运行时重新分析程序,就像 JVM 一样。
  • LLVM 设计得非常好:
    • 其组件是模块化且分离良好的,
    • 它有 3 种中间表示格式(文本、二进制和内存表示),它们是等效的,
    • 其中间表示使用SSA形式,
    • 它的中间表示有一个类型系统。

至于 Javascript 和其他动态语言,我们在动态语言社区中看到了很多对 LLVM 的兴趣,Python 和 Ruby 实现都在尝试。然而,这些编译器并不试图成为静态编译器。他们专注于使用 JIT。特别是,他们使用“混合模式解释器”优化长时间运行的可执行文件,首先解释程序,然后在运行时使用 LLVM 编译它们。我还没有见过使用 LLVM 的 javascript 引擎,但可能有一个。它只是不会创建静态可执行文件,除非在特殊情况下,或者对于 Javascript 的缩减版本。

至于创建 LLVM 的原因,它是作为 Vikram Adve 的研究小组在终身编译(这意味着 JIT 和链接时优化)方面的工作。获得博士学位后,Chris Lattner 转到 Apple,这极大地推动了该项目的发展(可能是因为它是 BSD 许可的,这在过去给他们带来了 gcc(即 GPL)问题)。

There are a couple of difference between LLVM and "a regular compiler", which I'll assume to mean "gcc":

  • LLVM is designed for whole-program analysis (aka link-time analysis), so it can optionally compile code to "bitcode", a format that it can re-analyse later.
  • LLVM provides a just-in-time compiler (JIT) so that it can re-analyse programs while they are running, just like the JVM does.
  • LLVM is very well designed:
    • its components are modular and well separated,
    • it has 3 formats for its intermediate representation (textual, binary, and an in-memory representation), which are equivalent,
    • its intermediate representation uses SSA form,
    • its intermediate represenation has a type system.

As for Javascript and other dynamic languages, we're seeing a lot of interesting in LLVM from the dynamic language community, with Python and Ruby implementations trying it out. However, these are not attempting to be static compilers. They are focussed on using the JIT. In particular, the are optimizing long running executables using a "mixed mode interpreter", where they initially interpret the programs, and then compile them using LLVM at run-time. I haven't seen a javascript engine using LLVM, but there probably is one. It just won't create static executables, except in unusual circumstances, or for cut down versions of Javascript.

As for the reason for the creation of LLVM, it started as part of Vikram Adve's research group's work on life long compilation (which means JITs and link-time optimization). After his PhD, Chris Lattner moved to Apple, which is moving the project forward greatly (probably because it is BSD licenced, which has caused them problems in the past with gcc, which is GPL).

笔芯 2024-08-11 21:03:35

没什么,它是一个常规编译器。创建它的主要原因是为编译器研究创建一个平台。因此,它被设计得非常模块化,以便您可以处理编译器中处理您的研究的部分,而不必担心编译器的其他部分。没有 Dragon 编译器,就像没有 LLVM 书籍一样(您在 Dragon 书籍或任何其他编译器书籍中阅读的任何理论都应该直接适用)。事实上,虽然我有一段时间没有查看 LLVM,但他们的文档相当糟糕。

Nothing it is a regular compiler. Its primary reason for creation was to create a platform for compiler research. Therefore it is designed to be very modular so that you can work on that part of the compiler that deals with your research and not have to worry about other parts of the compiler. There is no dragon compiler just as there is no LLVM book(any theory you read in the dragon book or any other compiler book should be directly applicable). In fact while I haven't looked in on LLVM in a while their documentation was pretty poor.

ㄖ落Θ余辉 2024-08-11 21:03:35

我根本不是开发人员,但是:即使 gpl 迫使 NeXt 在 80 年代发布其 ObjC 运行时,苹果资助另一个编译器(无论是否是 GPL)的主要原因是它愿意与 IDE 集成。事实证明,GCC 在这方面有太大的惯性,并且 GCC 的模块化程度不够高,无法实现代码部分的重用(xcode“修复它”功能)。
这就是我从阅读中了解到的

I am not developper at all, but : even if gpl forced NeXt to publish its ObjC runtime in the 80's, the main reason for apple to fund another compiler (GPL or not) is its will to integrate with the IDE. GCC proved to have too much inertia in this area, and GCC is not modular enough to enable reuse of code parts (xcode "fix it" feature).
That's what I understood from my readings

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