如何启用LLVM后端? [英] How to enable a LLVM backend?
问题描述
我正在使用Archlinux,并使用官方软件包(使用 pacman -S llvm
)安装了LLVM.我想在 wasm-32
后端(根据源代码).
I am using Archlinux and installed LLVM using the official package (using pacman -S llvm
).
I'd like to use it with the wasm-32
backend (available according to the source code).
但是,我的计算机上未启用此后端:
However, this backend is not enabled on my computer:
$ llc --version
LLVM (http://llvm.org/):
LLVM version 5.0.0
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
armeb - ARM (big endian)
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
mips - Mips
mips64 - Mips64 [experimental]
mips64el - Mips64el [experimental]
mipsel - Mipsel
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
如何启用LLVM后端?
How can I enable LLVM backends?
推荐答案
正如 Arrowd的消息所述,LLVM不是很构建后即可配置.如果您需要超出默认设置的配置,您必须自己编译LLVM .
As Arrowd's message mentions, LLVM is not very configurable once it is built. If you need a configuration beyond the defaults, you have to compile LLVM yourself.
LLVM上有几篇文章解释了如何编译它,但是并没有准确描述如何启用其他目标:
LLVM has a few articles explaining how to compile it, but it does not describe exactly how to enable additional targets:
启用的目标由调用CMake时需要定义的两个变量控制准备构建目录: LLVM_TARGETS_TO_BUILD
和 LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
.
The enabled targets are controlled by two variables that you need to define when invoking CMake
to prepare the build directory: LLVM_TARGETS_TO_BUILD
and LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
.
LLVM_TARGETS_TO_BUILD
仅控制稳定目标.您可以使用特殊值all
启用所有 stable 目标,也可以提供以分号分隔的目标列表,例如ARM; PowerPC; X86
.有待处理请求将特殊值重命名为stable
,并将all
用于 all 目标.它的默认值为all
(请参阅下面的目标列表).
LLVM_TARGETS_TO_BUILD
controls only the stable targets. You can either use the special valueall
to enable all the stable targets or provide a semicolon-separated list of targets such asARM;PowerPC;X86
. There is a pending request to rename the special value tostable
and useall
for all the targets. Its default value isall
(see below for the list of targets).
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
是一个未记录(或隐藏得很好)的变量,它使您可以启用您想要的任何目标.这也是用分号分隔的目标列表.
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
is an undocumented (or well hidden) variable that allows you
to enable any target you want. This is also a semicolon-separated list of targets.
已启用的目标将与两个列表的并集相对应.
The enabled targets will correspond to the union of both lists.
现在,您需要找出目标的实际名称,以及它是稳定目标还是实验目标.可以在入门"文章中找到稳定目标的列表./p>
Now, you need to find out the actual name of your target and if it is a stable or experimental target. The list of stable targets can be found in the Getting Started article.
默认值包括:
AArch64
,AMDGPU
,ARM
,BPF
,Hexagon
,Mips
,MSP430
,NVPTX
,PowerPC
,Sparc
,SystemZ
,X86
,XCore
.
The default value includes:
AArch64
,AMDGPU
,ARM
,BPF
,Hexagon
,Mips
,MSP430
,NVPTX
,PowerPC
,Sparc
,SystemZ
,X86
,XCore
.
This list is defined in the main CMakeFile (permalink).
如您所见,Wasm不在此列表中.我们必须找到LLVM使用的名称,然后使用 LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
.不幸的是,由于未记录此变量,因此无法在其网站上找到所有目标的列表.经过一番尝试和错误之后,看来可用目标与
As you can see, Wasm is not in this list. We'll have to find the name used by LLVM and then use LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
.
Unfortunately, since this variable is not documented, I wasn't able to find the list of all the targets on their website.
After some trial and error, it seems that the available targets correspond to the names of the directories in /lib/Target
.
总结:要使用LLVM进行wasm,您需要使用 LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
启用 WebAssembly
目标使用CMake准备构建目录时使用变量.
To sum up: to use LLVM for wasm, you'll need to enable the WebAssembly
target using the LLVM_EXPERIMENTAL_TARGETS_TO_BUILD
variable when preparing the build directory with CMake.
以下是我用来编译LLVM版本的确切步骤.我用的是Linux机器但您应该能够使其适应环境.
Here are the exact steps I used to compile my version of LLVM. I used a Linux machine but you should be able to adapt it to your environment.
要求:
- CMake
- Subversion
- GCC,CLang或Visual Studio,具体取决于您的平台
-
zlib
- CMake
- Subversion
- GCC, CLang or Visual Studio depending on your platform
zlib
- 使用 subversion 检出(克隆)LLVM 存储库.我将使用
/opt/llvm
目录作为主目录定制版本的LLVM(这是命令的最后一个参数,用您要使用的路径替换).
- Checkout (clone) the LLVM repo using subversion. I'll use the
/opt/llvm
directory for the home directory of my custom version of LLVM (this is the last argument to the command, replace it by the path you want to use).
svn co http://llvm.org/svn/llvm-project/llvm/trunk/opt/llvm
- 导航到LLVM源:
cd/opt/llvm
- 签出其他工具.
clang
是必需的,其他是可选的.请参阅入门指南
- Checkout the additional tools.
clang
is required but the others are optional. See Getting Started
svn co http://llvm.org/svn/llvm-project/cfe/trunk tools/clang
- 创建您的构建目录并导航到它.
mkdir build&&cd构建
- 使用CMake准备构建目录.这是您需要注意的步骤设置变量.就我而言,我将使用
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ="WebAssembly"
和将LLVM_TARGETS_TO_BUILD
保留为其默认值(所有稳定的目标).我将设置的另一个重要变量是CMAKE_BUILD_TYPE = Release
,以获取优化的版本并CMAKE_INSTALL_PREFIX =/opt/llvm/bin
将此版本的LLVM保留在其目录中并执行不会干扰我的系统上已有的版本(我只会将此目录添加到$ PATH中当我需要它时.)
- Use CMake to prepare your build directory. This is the step where you need take care
of setting the variables. In my case I'll use
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly"
and leaveLLVM_TARGETS_TO_BUILD
to its default value (all stable targets). Another important variable that I'll set isCMAKE_BUILD_TYPE=Release
to get an optimized build andCMAKE_INSTALL_PREFIX=/opt/llvm/bin
to keep this version of LLVM in its directory and do not interfere with the version I already have on my system (I'll just add this directory to the $PATH when I'll need it).
cmake -G"Unix Makefiles" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD ="WebAssembly" -DCMAKE_INSTALL_PREFIX =/opt/llvm/bin -DCMAKE_BUILD_TYPE =发布/opt/llvm
- 构建LLVM,这可能需要一段时间:
cmake --build.
- 安装LLVM:
cmake --build.--target安装
这篇关于如何启用LLVM后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!