我想从两个基本的 C++ 函数生成 LLVM IR 代码,如下所示。
int newFun2(int x){
int z = x + x;
return z;
}
int newFun(int *y){
int first = y[3]; //How to define it using the LLVM API?
int num = newFun2(first);
return num;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是使用 LLVM API 获取数组参数的索引。有任何想法吗 ?非常感谢
已编辑
这是我使用 API 的代码:
llvm::LLVMContext &context = llvm::getGlobalContext();
llvm::Module *module = new llvm::Module("AST", context);
llvm::IRBuilder<> builder(context);
//newFun2
llvm::FunctionType *newFunc2Type = llvm::FunctionType::get(builder.getInt32Ty(), builder.getInt32Ty(), false);
llvm::Function *newFunc2 = llvm::Function::Create(newFunc2Type, llvm::Function::ExternalLinkage, "newFun2", module);
llvm::Function::arg_iterator argsFun2 = newFunc2->arg_begin();
llvm::Value* …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的项目目录下开发llvm传递.为此,我按照http://llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source中的信息进行操作.我在这个链接中正确创建了我的CMakeFiles,我的最终项目目录是这样的;
|-- src
| |-- CMakeLists.txt
| |-- bigForPass
| | |-- CMakeLists.txt
| | |-- bigForPass.cpp
| | |-- merged.bc
| |-- build
Run Code Online (Sandbox Code Playgroud)
我还将我的源文件与llvm根目录链接没有任何问题.最后,我在"build"文件夹下进行构建,并且我的共享库成功创建,没有任何问题(在build/bin文件夹下),名称为LLVMHello1.dylib.但是,当我尝试使用命令运行merged.bc文件(包含我的llvm代码)的传递时
opt -load ../build/bin/LLVMHello1.dylib -bishe_insert <merged.bc> final.bc
Run Code Online (Sandbox Code Playgroud)
我一直在收到错误;
Error opening '../build/bin/LLVMHello1.dylib': dlopen(../build/bin/LLVMHello1.dylib, 9): Symbol not found: __ZTIN4llvm10ModulePassE
Referenced from: ../build/bin/LLVMHello1.dylib
Expected in: flat namespace
in ../build/bin/LLVMHello1.dylib
-load request ignored.
Run Code Online (Sandbox Code Playgroud)
对此有何意见和建议表示赞赏?
非常感谢提前.