生成LLVM C ++ API代码作为后端

时间:2013-02-07 12:42:30

标签: c++ linux llvm x86-64

Online LLVM demo页面可以选择从源代码生成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版。

2 个答案:

答案 0 :(得分:7)

构建LLVM时,必须在配置期间启用LLVM C ++后端。它默认在configure(autotools)构建中启用,但在Windows上构建时不在CMake构建中启用。您可以通过在配置CMake时设置适当的标志来启用它。有关详细信息,请参阅this page

引用:

  

<强> LLVM_TARGETS_TO_BUILD:STRING       要建立的以分号分隔的目标列表,或者用于构建所有目标的所有目标。区分大小写。对于Visual C ++,默认为X86。在   其他情况默认为​​全部。例:   -DLLVM_TARGETS_TO_BUILD = “X86;的PowerPC”

<击>

<强>更新

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

Check this commit

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

答案 1 :(得分:1)

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

正如您在以下提交中所看到的, Remove bit-rotten 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