PenYiWang via llvm-dev
2020-Feb-27 11:32 UTC
[llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ?
Hi I want to insert some functions into the llvm bitcode ir files. So I use IRBuilder and CreateCall(). But it how error : inlinable function call in a function with debug info must have a !dbg location. I don't know what DebugLoc should I give the new CallInst to setDebugLoc. I Create this CallInst , so this CallInst doesn't hava so-called "DebugLoc" mapping to the source code , right ? And also I want the compiler can do some inline optimization to my program. So I have to give this CallInst a DebugLoc.... What would happen if the DebugLoc of an Instruction is wrong ? would there be any error? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200227/b7399554/attachment.html>
Robinson, Paul via llvm-dev
2020-Feb-27 18:19 UTC
[llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ?
Applying a “wrong” DebugLoc to an Instruction will not cause any errors. The “wrong” location would be carried through to the debugging information in the object file, which might cause your debugger to do something unexpected while debugging the program. One tactic, which ought to be fairly easy, is to give your new Instruction the same DebugLoc as the Instruction before (or after) your new Instruction. This will make your new Instruction appear to be part of the same source statement as the neighboring Instruction. Hope this helps, --paulr From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of PenYiWang via llvm-dev Sent: Thursday, February 27, 2020 6:33 AM To: llvm-dev at lists.llvm.org Subject: [llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ? Hi I want to insert some functions into the llvm bitcode ir files. So I use IRBuilder and CreateCall(). But it how error : inlinable function call in a function with debug info must have a !dbg location. I don't know what DebugLoc should I give the new CallInst to setDebugLoc. I Create this CallInst , so this CallInst doesn't hava so-called "DebugLoc" mapping to the source code , right ? And also I want the compiler can do some inline optimization to my program. So I have to give this CallInst a DebugLoc.... What would happen if the DebugLoc of an Instruction is wrong ? would there be any error? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200227/e902f7c2/attachment-0001.html>
PenYiWang via llvm-dev
2020-Feb-28 03:38 UTC
[llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ?
I use DebugLoc of nearest instruction (before or after). Then I solve this problem. Thank You Help me a lot !! Robinson, Paul <paul.robinson at sony.com> 於 2020年2月28日 週五 上午2:19寫道:> Applying a “wrong” DebugLoc to an Instruction will not cause any errors. > The “wrong” location would be carried through to the debugging information > in the object file, which might cause your debugger to do something > unexpected while debugging the program. > > > > One tactic, which ought to be fairly easy, is to give your new Instruction > the same DebugLoc as the Instruction before (or after) your new > Instruction. This will make your new Instruction appear to be part of the > same source statement as the neighboring Instruction. > > > > Hope this helps, > > --paulr > > > > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *PenYiWang > via llvm-dev > *Sent:* Thursday, February 27, 2020 6:33 AM > *To:* llvm-dev at lists.llvm.org > *Subject:* [llvm-dev] How to set DebugLoc when using IRBuilder's > CreateCall ? > > > > > > Hi > > > > I want to insert some functions into the llvm bitcode ir files. > > > > So I use IRBuilder and CreateCall(). > > > > But it how error : inlinable function call in a function with debug info > must have a !dbg location. > > > > I don't know what DebugLoc should I give the new CallInst to setDebugLoc. > > > > I Create this CallInst , so this CallInst doesn't hava so-called > "DebugLoc" mapping to the source code , right ? > > > > And also I want the compiler can do some inline optimization to my program. > > > > So I have to give this CallInst a DebugLoc.... > > > > What would happen if the DebugLoc of an Instruction is wrong ? > > > > would there be any error? > > > > Thanks. > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200228/0c20caa3/attachment.html>
archanaa@vt.edu via llvm-dev
2020-Feb-28 17:52 UTC
[llvm-dev] Problems in adding compare instruction after function call
Dear all, I am trying to build a pass which compares the output of all function calls with a predefined value. I encountered two issues. For example, the following IR ..... %before = alloca i32, i32 55 %fooRet = call i32 @foo(i32 10) ..... should be transformed to the following IR after the pass .... %before = alloca i32, i32 55 %fooRet = call i32 @foo(i32 10) %check = icmp eq i32 %call, i32 %before br i1 %check label %3, label %4 ... 1) I am not able to add icmp instruction using IRbuilder after the function call instruction (I was able to add icmp instruction using IRbuilder after other instructions, e.g. mul instruction): I wrote a pass(snippet below) to do the above instrumentation which also adds other new instructions, running the pass with opt does not throw any error when there is a CreateIcmpEQ with two constant operands, but only the icmp instruction after the function call is not present in the instrumented IR. 2) How to pass the output of a function call to CreateIcmpEQ() as a argument? I understand that fooRet is the return value of my call instruction. When I use check = builder.CreateICmpEQ(call, newConst, "check"), I get a Type mismatch assert. /[ICmpInst::AssertOK(): Assertion 'getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to Icmp instruction are not of the same type!"]/. I guess if I can make the types match, I will be able to pass the return value as argument. How can I achieve that? A snippet of the pass: if(CallInst *call = dyn_cast<CallInst>(&I)) { call->setName("fooRet"); IRBuilder<> builder(call); Value* newConst = ConstantInt::get(Int32Ty,55); Value* before = builder.CreateAlloca(Int32Ty, newConst,"before"); builder.SetInsertPoint(&bb, ++builder.GetInsertPoint()); *Value* check = builder.CreateICmpEQ(call, newConst, "check");* auto * branch = builder.CreateCondBr(check, true, false); } Any help is appreciated. Thank you. Regards, Archanaa -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200228/2ba19b4d/attachment.html>
Reasonably Related Threads
- [RFC] Add DebugLoc parameter in Instruction’s Create() functions
- How to get return address at llvm ir level?
- [LLVMdev] Arguments to IRBuilder CreateCall function
- [LLVMdev] IRBuilder<>::CreateCall, CreateCall2, CreateCall3, ...
- [LLVMdev] IRBuilder<>::CreateCall, CreateCall2, CreateCall3, ...