<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Hi again,<br><br></div><div>I finally managed to find the solution looking at CloneFunctionInto implementation.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div>Not sure what you mean by "you can't clone the function if there is arguments”, CloneFunction is supposed to handle this.</div><span class=""><div><br></div></span></div></div></blockquote><div><br></div><div>I meant that you can't directly splice the function body from a function with arguments (at least if those argument are used in the function body). Because that's what I tried first as an "hand-made" solution, then I had to do the arguments mapping I thought this should probably exist somewhere in LLVM API...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><div></div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>The instructions using these arguments will have Values refering to another function body which triggers errors like:<br><br>Referring to an argument in another function!<br>  store i8* %ptr, i8** %ptr.addr, align 8<br><br></div><div>for a function taking i8* %ptr as argument. </div></div></div></div></div></blockquote><div><br></div></span><div>If you end up with this by *only* calling CloneFunction, that’s a bug. It is supposed to handle this perfectly.</div></div></div></blockquote><div><br></div><div>Nope, that happen when arguments weren't remapped. I didn't managed to use CloneFunction because I didn't get how to build the ValueToValueMapTy argument (given by "typedef ValueMap< const Value*, WeakVH > llvm::ValueToValueMapTy"). <br><br></div><div>At last when I looked to the implementation they used it as a std::map<Value*, Value*>... I'm still confused on that point. Well at least it does make sense to remap the argument with a map like that. And that was my initial question by the way.<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>But I think CloneFunctionInto allows you to do this kind of argument expansion</div></div></div></div></div></blockquote><div><br></div></span><div>Yes, CloneFunction is setting up the call for CloneFunctionInto, if you look at the implementation you should be able to copy it, and with some adaptation call CallFunctionInto.</div><span class=""><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> (because that's the only thing after all: adding an argument to the function).<br></div></div></div></div></div></blockquote><div><br></div></span><div>Note: If you just want to *add* an argument and don’t need to preserve the old function, cloning it is an expensive solution…</div><br><div style="word-wrap:break-word"><span class=""></span><span class=""><br></span></div></blockquote><div><br></div><div>Well I think I don't need to keep the original function around, but how should I do so ? This doesn't look like trivial because every CallInst to the original function has to be modified too to match the new signature. Or doing it with optional arguments ? Never tried those.<br><br></div><div>But anyway I guess the answer to my original question was just "you can put some std::map<Value*, Value*> for the VMap argument" ^^.<br><br></div><div>Thanks for your time, I hope it's the last time I need to ask for help!<br></div></div></div></div>