LLVM它是什么以及如何使用它来跨平台编译

时间:2021-08-29 12:09:24

I was reading here and there about llvm that can be used to ease the pain of cross platform compilations in c++ , i was trying to read the documents but i didn't understand how can i use it in real life development problems can someone please explain me in simple words how can i use it ?

我正在这里和那里阅读有关llvm,可以用来缓解c ++中跨平台编译的痛苦,我试图阅读文档,但我不明白我如何在现实生活中使用它开发问题有人请解释我用简单的话说,我怎么用它?

5 个解决方案

#1


The key concept of LLVM is a low-level "intermediate" representation (IR) of your program. This IR is at about the level of assembler code, but it contains more information to facilitate optimization.

LLVM的关键概念是程序的低级“中间”表示(IR)。此IR大约是汇编程序代码的级别,但它包含更多信息以便于优化。

The power of LLVM comes from its ability to defer compilation of this intermediate representation to a specific target machine until just before the code needs to run. A just-in-time (JIT) compilation approach can be used for an application to produce the code it needs just before it needs it.

LLVM的强大之处在于它能够将此中间表示的编译推迟到特定目标机器,直到代码需要运行之前。实时(JIT)编译方法可用于应用程序,以便在需要之前生成所需的代码。

In many cases, you have more information at the time the program is running that you do back at head office, so the program can be much optimized.

在许多情况下,您在总部运行的程序运行时有更多信息,因此可以对程序进行大量优化。

To get started, you could compile a C++ program to a single intermediate representation, then compile it to multiple platforms from that IR.

首先,您可以将C ++程序编译为单个中间表示,然后将其从该IR编译到多个平台。

You can also try the Kaleidoscope demo, which walks you through creating a new language without having to actually write a compiler, just write the IR.

您还可以尝试Kaleidoscope演示,它将引导您创建一种新语言而无需实际编写编译器,只需编写IR即可。

In performance-critical applications, the application can essentially write its own code that it needs to run, just before it needs to run it.

在性能关键型应用程序中,应用程序基本上可以编写自己需要运行的代码,就在它需要运行之前。

#2


Why don't you go to the LLVM website and check out all the documentation there. They explain in great detail what LLVM is and how to use it. For example they have a Getting Started page.

你为什么不去LLVM网站查看那里的所有文件。他们非常详细地解释了LLVM是什么以及如何使用它。例如,他们有一个入门页面。

#3


LLVM is, as its name says a low level virtual machine which have code generator. If you want to compile to it, you can use either gcc front end or clang, which is c/c++ compiler for LLVM which is still work in progress.

正如其名称所示,LLVM是一个具有代码生成器的低级虚拟机。如果要编译它,可以使用gcc前端或clang,它是用于LLVM的c / c ++编译器,它仍在进行中。

#4


It's important to note that a bunch of information about the target comes from the system header files that you use when compiling. LLVM does not defer resolving things like "size of pointer" or "byte layout" so if you compile with 64-bit headers for a little-endian platform, you cannot use that LLVM source code to target a 32-bit big-endian assembly output pater.

值得注意的是,有关目标的大量信息来自编译时使用的系统头文件。 LLVM不会推迟解析诸如“指针大小”或“字节布局”之类的内容,因此如果使用64位头为小端平台编译,则无法使用该LLVM源代码来定位32位大端程序集输出。

#5


There is a good chapter in a book explaining everything nicely here: www.aosabook.org/en/llvm.html

书中有一个很好的章节,在这里很好地解释了一切:www.aosabook.org/en/llvm.html

#1


The key concept of LLVM is a low-level "intermediate" representation (IR) of your program. This IR is at about the level of assembler code, but it contains more information to facilitate optimization.

LLVM的关键概念是程序的低级“中间”表示(IR)。此IR大约是汇编程序代码的级别,但它包含更多信息以便于优化。

The power of LLVM comes from its ability to defer compilation of this intermediate representation to a specific target machine until just before the code needs to run. A just-in-time (JIT) compilation approach can be used for an application to produce the code it needs just before it needs it.

LLVM的强大之处在于它能够将此中间表示的编译推迟到特定目标机器,直到代码需要运行之前。实时(JIT)编译方法可用于应用程序,以便在需要之前生成所需的代码。

In many cases, you have more information at the time the program is running that you do back at head office, so the program can be much optimized.

在许多情况下,您在总部运行的程序运行时有更多信息,因此可以对程序进行大量优化。

To get started, you could compile a C++ program to a single intermediate representation, then compile it to multiple platforms from that IR.

首先,您可以将C ++程序编译为单个中间表示,然后将其从该IR编译到多个平台。

You can also try the Kaleidoscope demo, which walks you through creating a new language without having to actually write a compiler, just write the IR.

您还可以尝试Kaleidoscope演示,它将引导您创建一种新语言而无需实际编写编译器,只需编写IR即可。

In performance-critical applications, the application can essentially write its own code that it needs to run, just before it needs to run it.

在性能关键型应用程序中,应用程序基本上可以编写自己需要运行的代码,就在它需要运行之前。

#2


Why don't you go to the LLVM website and check out all the documentation there. They explain in great detail what LLVM is and how to use it. For example they have a Getting Started page.

你为什么不去LLVM网站查看那里的所有文件。他们非常详细地解释了LLVM是什么以及如何使用它。例如,他们有一个入门页面。

#3


LLVM is, as its name says a low level virtual machine which have code generator. If you want to compile to it, you can use either gcc front end or clang, which is c/c++ compiler for LLVM which is still work in progress.

正如其名称所示,LLVM是一个具有代码生成器的低级虚拟机。如果要编译它,可以使用gcc前端或clang,它是用于LLVM的c / c ++编译器,它仍在进行中。

#4


It's important to note that a bunch of information about the target comes from the system header files that you use when compiling. LLVM does not defer resolving things like "size of pointer" or "byte layout" so if you compile with 64-bit headers for a little-endian platform, you cannot use that LLVM source code to target a 32-bit big-endian assembly output pater.

值得注意的是,有关目标的大量信息来自编译时使用的系统头文件。 LLVM不会推迟解析诸如“指针大小”或“字节布局”之类的内容,因此如果使用64位头为小端平台编译,则无法使用该LLVM源代码来定位32位大端程序集输出。

#5


There is a good chapter in a book explaining everything nicely here: www.aosabook.org/en/llvm.html

书中有一个很好的章节,在这里很好地解释了一切:www.aosabook.org/en/llvm.html