[llvm-dev] Problems in adding compare instruction after function call (original) (raw)
archanaa@vt.edu via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 28 09:52:06 PST 2020
- Previous message: [llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ?
- Next message: [llvm-dev] Correct modelling of instructions with types smaller than the register class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ...
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.
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(&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>
- Previous message: [llvm-dev] How to set DebugLoc when using IRBuilder's CreateCall ?
- Next message: [llvm-dev] Correct modelling of instructions with types smaller than the register class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]