<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Dear All</p>
<p>I'm making an instrumentation pass. The pass is supposed to modify the given IR in a specefic way. One of the required modifications is to insert a call to a function at a specific location. </p>
<p>This is the signature of the called function:</p>
<p> void myclass::foo(Function *f, BasicBlock* b)</p>
<p>This function's prototype is in an foofile.h file in include/llvm</p>
<p>And the function definition is in foofile.cpp file in the MCJIT folder.</p>
<p>and running "make" at this folder works fine and the foofile.cpp is compiled with MCJIT.cpp and another function in the same file works just fine as expected.</p>
<p>Not back to the instrumentation pass. How can I insert a callinst to the foo function in the given IR?</p>
<p>Here is the snippet that inserts the call:</p>
<p> Type* retTy = Type::getInt32Ty(C);</p>
<p> FunctionType* FuncTy = FunctionType::get(retTy, false);</p>
<p> PointerType* PtrToFuncTy = PointerType::get(FuncTy, 0);</p>
<p></p>
<p> Constant *fun = M->getOrInsertFunction("foo", Type::getVoidTy(C), PtrToFuncTy, Type::getLabelTy(C), nullptr);</p>
<p></p>
<p> Function *dofoo = cast<Function>(fun);</p>
<p> Instruction* dofooCall = CallInst::Create(fun, Args2, "", bb);</p>
<p><br>
</p>
<p>Note: Args2 is an arraylist containing 2 value pointers to a function and a basicblock, bb is the basicblock to insert the call in.</p>
<p><br>
</p>
<p>When I run the pass using op on a given IR, it produces a declaration and a call correctly like this:</p>
<p> declaration: declare void @foo(i32 ()*, label)</p>
<p> call: call void @foo(i32 ()* @main, label %for.cond)</p>
<p>But when I try to run the resulting .ll file using lli, everything explodes! This the first 2 lines before the stacktrace:</p>
<p> Can't get register for value!</p>
<p> UNREACHABLE executed at /home/marwayusuf/llvm-env/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1158!</p>
<p> </p>
<p>I concluded that the problem is it can't find the foo function. If this is the problem, how can I create the callinst correctly?</p>
<p> </p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<div class="BodyFragment"><font size="2"><span style="font-size:10pt">
<div class="PlainText">Regards,<br>
Marwa Yusuf<br>
Teaching Assistant - Computer Engineering Department<br>
Faculty of Engineering - Benha University<br>
E-JUST PhD Student<br>
Computer Science & Engineering Dept.</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>