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

标签 c++ linux llvm x86-64

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

最佳答案

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

引用:

LLVM_TARGETS_TO_BUILD:STRING Semicolon-separated list of targets to build, or all for building all targets. Case-sensitive. For Visual C++ defaults to X86. On the other cases defaults to all. Example: -DLLVM_TARGETS_TO_BUILD="X86;PowerPC".

更新

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

关于c++ - 生成 LLVM C++ API 代码作为后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14751403/

相关文章:

c++ - 为什么可变参数模板在模板介绍中不起作用,但在 requires 子句中起作用? ConceptName{T,U,V,W} <-- 模板<类型名 ...T>

c++ - 从 llvm ir 中删除完整的分支

c++ - 链接到 Unix 上的 Clang 和 LLVM - 强制使用 LLVM 的编译器标志?

c++ - LLVM-5.0 Makefile undefined reference 失败

c++ - 警告 : non-constant array size in new, 无法验证初始化列表的长度

c++ - C++ 中的模式匹配

c++ - 提升文件系统困难

linux - 连接到主机 localhost 端口 22 : Connection refused

C程序分离elf文件的数据部分

c - 如何使用引用了内存中存储的inode创建虚拟文件