<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 6/20/16 6:17 AM, Pierre Gagelin via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CALAmmgRQS010vzSX_0ewUUNSL=KyF=3OuUGZr+uCfp5iS5hE4g@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>
<div>
<div>Hi everyone,<br>
<br>
</div>
I am trying to replace the call of a certain function with a
call to another function. It would for example replace the
following:<br>
<br>
%call = tail call noalias i8* @func(i64 10)<br>
</div>
<div>by<br>
%call = tail call noalias i8* @other_func(i64 10)<br>
</div>
<div><br>
</div>
<div>I managed to declare other_func correctly but I am having
troubles to understand how I should proceed to do the
replacement.<br>
</div>
<div><br>
I tried to use ReplaceInstWithInst function as follows:<br>
<br>
CallInst *call_to_other_func_inst =
IRBuilder.CreateCall(ptr_to_other_func, args);<br>
ReplaceInstWithInst(call_to_func_inst, newI);<br>
<br>
</div>
LLVM builds correctly but the instrumentation crashes at
optimization time. I know this isn't the correct way to do it
because IRBuilder generates IR and I just want to have an
instance of a CallInst. But I don't see how it is supposed to
be done?<br>
</div>
</div>
</blockquote>
<br>
Do you have assertions enabled? If so, is the crash an assertion
failure and, if so, which assertion is failing? It's nearly
impossible to tell what the problem is just by knowing that it is
crashing.<br>
<br>
<blockquote
cite="mid:CALAmmgRQS010vzSX_0ewUUNSL=KyF=3OuUGZr+uCfp5iS5hE4g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
There are methods to create CallInst in the Instruction.h file
but those needs to give an inserting point. Shoud I insert the
call to other_func before the one to func and just remove the
call instruction to func?<br>
</div>
</div>
</blockquote>
<br>
Yes. You need to place the new call instruction within the same
basic block as the old call instruction. Placing it right before
the old call instruction is a good place.<br>
<br>
The code that Ashutosh provided is what I'd use to do what you're
doing.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<blockquote
cite="mid:CALAmmgRQS010vzSX_0ewUUNSL=KyF=3OuUGZr+uCfp5iS5hE4g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Thanks for your help,<br>
</div>
<div>Pierre<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>