<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi Sue,<br>
</p>
<code></code>
<blockquote
cite="mid:CAJ7oqqRt1Rt4QMxZ2k_5waXGPqkhozJ-Zc0Wx8viFqeaHb-o+w@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div class="gmail-post-text">
<p>A new definition of called function is
constructed(declare x86_fp80 @new_add(x86_fp80,
x86_fp80, ...)), but the body of this new function
is empty. I am very confused how to add the body
and get the IR_New I want. My naive idea is:</p>
<code> for (Instruction i : called function(add in
the example)){
<br>
create new_i with type x86_fp80; <br>
insert new_i in the new function
constructed(new_add in the example);
<br>
}</code></div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<blockquote
cite="mid:CAJ7oqqRt1Rt4QMxZ2k_5waXGPqkhozJ-Zc0Wx8viFqeaHb-o+w@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div class="gmail-post-text">Is this a good way to
achieve my goal please?</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
I think this will work but you would have to care about replacing
operands coming from function's argument with new arguments. Maybe
take a look at CloneFunctionInto. Once you have created both
functions (like it is your case obviously), you need to map
arguments together like:<br>
<br>
ValueToValueMapTy VMap;<br>
for(Function::arg_iterator b_a = func->arg_begin(), e_a =
func->arg_end() ; b_a != e_a ; ++b_a) {<br>
Argument *Arg = &*b_a;<br>
VMap[Arg] = ... (argument from the new function);<br>
}<br>
<br>
CloneFunctionInto will replace them in the new function body (as
they say in the source code, that's the worst part to implement).
Though I am not sure it will work with different types? Maybe
consider doing this at beginning of you instrumentation and then do
you instrumentation to mutate the type.<br>
<blockquote
cite="mid:CAJ7oqqRt1Rt4QMxZ2k_5waXGPqkhozJ-Zc0Wx8viFqeaHb-o+w@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div class="gmail-post-text">
<p>Any advice will be greatly appreciated :)</p>
<p><br>
</p>
<p>Sincerely,</p>
<p>Suhua<br>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
Note that if you don't need to keep your old "add" function there
are better ways to do. But for compatibility reasons it can be nice
to have it.<br>
<br>
Hope that helps,<br>
Pierre
</body>
</html>