14

在线 LLVM 演示页面有一个选项可以从源代码生成 LLVM C++ API 代码作为后端。但是,该演示页面现在已禁用。我想知道我们如何使用可用的 LLVM 工具自己做到这一点。

我尝试了以下

clang++ -c -emit-llvm input.cpp -o input.ll
llc -march=cpp -o input.ll.cpp input.ll

这给出了以下错误

llc: error: invalid target 'cpp'.

我正在使用 LLVM/Clang 3.2 版。

4

2 回答 2

9

在构建 LLVM 时,必须在配置期间启用 LLVM C++ 后端。它在configure(autotools) 构建中默认启用,但在 Windows 上构建时不会在 CMake 构建中启用。您可以通过在使用 CMake 进行配置时设置适当的标志来启用它。请参阅此页面了解更多信息。

引用:

LLVM_TARGETS_TO_BUILD:STRING 以分号分隔的要构建的目标列表,或 all 用于构建所有目标。区分大小写。对于 Visual C++,默认为 X86。在其他情况下,默认为全部。示例:-DLLVM_TARGETS_TO_BUILD="X86;PowerPC"。

更新

由于version 3.9CppBackend 不再是有效目标。他们已从代码中删除,因为生成的代码存在一些问题。

检查这个提交

Remove bit-rotten CppBackend.

This backend was supposed to generate C++ code which will re-construct
the LLVM IR passed as input. This seems to me to have very marginal
usefulness in the first place.

However, the code has never been updated to use IRBuilder, which makes
its current value negative -- people who look at the output may be
steered to use the *wrong* C++ APIs to construct IR.

Furthermore, it's generated code that doesn't compile since at least
2013.

Differential Revision: http://reviews.llvm.org/D19942

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268631 91177308-0d34-0410-b5e6-96231b3b80d8
于 2013-02-09T22:04:57.753 回答
1

可悲的是,这在更新的 LLVM 版本中似乎不再可能。相关的提交消息很好地解释了它。

正如您在以下提交中看到的那样, 删除位腐烂的 CppBackend,生成的代码会显示问题。

commit 257fabb18605265a79397d35dd79a3973760ffaf
Author: ---
Date:   Thu May 5 14:35:40 2016 +0000

Remove bit-rotten CppBackend.

This backend was supposed to generate C++ code which will re-construct
the LLVM IR passed as input. This seems to me to have very marginal
usefulness in the first place.

However, the code has never been updated to use IRBuilder, which makes
its current value negative -- people who look at the output may be
steered to use the *wrong* C++ APIs to construct IR.

Furthermore, it's generated code that doesn't compile since at least
2013.

Differential Revision: http://reviews.llvm.org/D19942

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268631 91177308-0d34-0410-b5e6-96231b3b80d8
于 2017-03-19T14:46:58.137 回答