<div dir="ltr">Thank you ,Cheers. <div>I also found a good example of inserting call "printf" instruction in <a href="https://chromium.googlesource.com/chromiumos/third_party/llvm/+/release_16/lib/Transforms/Instrumentation/TraceValues.cpp">https://chromium.googlesource.com/chromiumos/third_party/llvm/+/release_16/lib/Transforms/Instrumentation/TraceValues.cpp</a><div>
<br></div><div>The code in this link also use GetOrInsertFunction().</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/17 Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">> But I got another problems. I successfully compile the pass and I can insert<br>
> the call printf (C Lib function) instructions in the LLVM IR(eg: call.bc).<br>
> If the call.bc didn't contain call printf instruction ,I can call printf<br>
> successfully ,but if not ,there exists a problem. the llvm will rename my<br>
> inserted call function , and the transformed code can not run correctly!<br>
<br>
</div>That looks like the issue Hongxu mentioned: you're always creating a<br>
new Function (at which point LLVM renames it if one already exists)<br>
when you should really be calling GetOrInsertFunction to lookup an<br>
existing "printf" if it's available.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div>