llvm-ir

Create local string using LLVM

£可爱£侵袭症+ 提交于 2019-12-07 04:49:35
问题 I'm trying to create a local variable using LLVM to store strings, but my code is currently throwing a syntax error. lli: test2.ll:8:23: error: constant expression type mismatch %1 = load [6 x i8]* c"hello\00" My IR code that allocates and store the string: @.string = private constant [4 x i8] c"%s\0A\00" define void @main() { entry: %a = alloca [255 x i8] %0 = bitcast [255 x i8]* %a to i8* %1 = load [6 x i8]* c"hello\00" %2 = bitcast [6 x i8]* %1 to i8* %3 = tail call i8* @strncpy(i8* %0, i8

LLVM error accessing loopinfo in function pass

心不动则不痛 提交于 2019-12-06 19:42:35
I'm trying to get loop information from IR by writing a function pass. So I followed some examples and wrote like following. I'm not very familiar with writing passes and pass managers. #include <iostream> #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Function.h" #include "llvm/BasicBlock.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/IRReader.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Pass.h" #include "llvm/PassManager.h" using

How to emit LLVM-IR from Cargo

六眼飞鱼酱① 提交于 2019-12-06 19:24:00
问题 How can I get cargo to emit LLVM-IR instead of a binary for my project? I know that you can use the --emit=llvm-ir flag in rustc , but I've read some Github issues that show it's impossible to pass arbitrary compiler flags to cargo. Is there any way I can get cargo to emit LLVM-IR directly? 回答1: There is cargo rustc to pass arbitrary compiler flags through Cargo to rustc . So I think: cargo rustc -- --emit=llvm-ir is what you want! 回答2: EDIT: You should use Jacob's answer instead; a lot

Get pointer to llvm::Value previously allocated for CreateLoad function

霸气de小男生 提交于 2019-12-06 16:39:14
I'm new to llvm and I'm writing a small llvm IR Builder. I use the IRBuilder and all these Create* functions to generate my IR. What I'm trying to do is to create a load instruction which create a new SSA local variable with value of a previously allocated llvm::Value . What I expected to have : %2 = load i32* %1 With %2 results of load instruction and %1 my previously allocated Value (CreateAlloca) Here is what I tried : // Get Ptr from Val Value* ptr = ConstantExpr::getIntToPtr((Constant*)loc[n],PointerType::getUnqual(builder->getInt32Ty())); // Générate load instruction with the new Ptr

How to tell if LLVM Instruction as a Left-Hand Side

孤者浪人 提交于 2019-12-06 14:20:48
Is there a way to tell if an LLVM Instruction has a left-hand side? That is, whether it produces a value? For example, an add instruction would have a left-hand side; however, a store or br instruction would not. In general you can identify those instructions which cannot have a result assignment, but you cannot say if an instruction will result in an assignment, only that it might . This is because you don't have to assign the result of an operation. For instance, the following line of code is valid in LLVM IR: add nsw i32 %a, %b but it's pointless because it has no effect whatsoever. No sane

How to generate metadata for LLVM IR?

做~自己de王妃 提交于 2019-12-06 12:51:54
I am trying to generate a metadata for the LLVM IR i have generated. I want to generate a metadata of the form : !nvvm.annotations = !{!0} !0 = metadata !{void ()* @foo, metadata !"kernel", i32 1} Where foo is a function in my LLVM IR. Right now I am only able to generate a metadata of the form: !nvvm.annotations = !{!0} !0 = !{!"kernel"} I used the following code for the above metadata generation. char metaDataArgument[512]; sprintf(metaDataArgument, "%s", pipelineKernelName); llvm::NamedMDNode *nvvmMetadataNode = LLVMModule->getOrInsertNamedMetadata("nvvm.annotations"); llvm::MDNode

Convert std::string to llvm::MemoryBuffer

僤鯓⒐⒋嵵緔 提交于 2019-12-06 10:47:01
问题 I am looking to create an LLVM Module from existing LLVM IR code. The two methods I have found are the following: ParseIRFile - This accepts a file name and generates a module ParseIR - This accepts MemoryBuffer and generates a module I want to create a Module when the LLVM IR is already read to a string as an std::string or const char * . Is there a way to convert an IR string to llvm::MemoryBuffer ? 回答1: I figured this out with the help of a colleague. This is how you would do it: std:

LLVM Error : External function could not be resolved

99封情书 提交于 2019-12-06 07:47:15
I am reading the LLVM's Kaleidoscope tutorial ( http://llvm.org/docs/tutorial/index.html ). I wanted to compile and test the language. After some compiler's errors (EngineBuilder and Module's constructor, linking libs...), the example program was built. Then, I tried the language. I got a few problems with InitializeNativeTargets, DataLayoutPass... But I managed to correct them. Howewer, I don't manage to resolve one error. When I write extern printd(x); printd(5); , the program doesn't work : "LLVM ERROR : Program used external function 'printd' which could not be resolved". I looked for the

Getting actual value of local variables in llvm

空扰寡人 提交于 2019-12-05 13:55:58
If I have this example: int a=0, b=0; a and b are local variables and make any modifications in their values, such as: a++; b++; I need to get the value in this line code during running MCJIT. I mean by value not Value class, but the actual integer or any type value. You need to return the value from a JITed LLVM function in order to retrieve it from the code invoking MCJIT. Check out this Kaleidoscope example . The relevant code is in HandleTopLevelExpression(): if (FunctionAST *F = ParseTopLevelExpr()) { if (Function *LF = F->Codegen()) { // JIT the function, returning a function pointer.

Create local string using LLVM

不打扰是莪最后的温柔 提交于 2019-12-05 11:04:36
I'm trying to create a local variable using LLVM to store strings, but my code is currently throwing a syntax error. lli: test2.ll:8:23: error: constant expression type mismatch %1 = load [6 x i8]* c"hello\00" My IR code that allocates and store the string: @.string = private constant [4 x i8] c"%s\0A\00" define void @main() { entry: %a = alloca [255 x i8] %0 = bitcast [255 x i8]* %a to i8* %1 = load [6 x i8]* c"hello\00" %2 = bitcast [6 x i8]* %1 to i8* %3 = tail call i8* @strncpy(i8* %0, i8* %2, i64 255) nounwind %4 = getelementptr inbounds [6 x i8]* %a, i32 0, i32 0 %5 = call i32 (i8*, ...)