Tyler Denniston
2014-Oct-02 21:45 UTC
[LLVMdev] Use list preservation when using Instruction::clone
I'm trying to create a clone of a function using Function::Create() and CloneFunctionInto. However, I'm running into an issue. I believe that the instructions in the function clone still have Use edges to values in the original function. This is a problem for my purposes. For example, consider an original function F. I create a new function G belonging to the same module and call CloneFunctionInto(G, F) to copy over the function body. Now, consider a phi node p in F, and an instruction I in F which uses p. The problem is, the cloned phi node p' in G still lists I as a user. Is this intended behavior? And if so, is there a way I can remove these Use edges in my cloned function? Thanks, Tyler
Jingyue Wu
2014-Oct-02 22:26 UTC
[LLVMdev] Use list preservation when using Instruction::clone
Hi Tyler, Doesn't look right. Would you mind attaching the test? Btw, instead of creating an empty function and CloneFunctionInto, can you just CloneFunction? Jingyue On Thu Oct 02 2014 at 2:47:51 PM Tyler Denniston <tyler at csail.mit.edu> wrote:> I'm trying to create a clone of a function using Function::Create() > and CloneFunctionInto. However, I'm running into an issue. I believe > that the instructions in the function clone still have Use edges to > values in the original function. This is a problem for my purposes. > > For example, consider an original function F. I create a new function > G belonging to the same module and call CloneFunctionInto(G, F) to > copy over the function body. Now, consider a phi node p in F, and an > instruction I in F which uses p. The problem is, the cloned phi node > p' in G still lists I as a user. > > Is this intended behavior? And if so, is there a way I can remove > these Use edges in my cloned function? > > Thanks, > > Tyler > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141002/83d72c93/attachment.html>
Tyler Denniston
2014-Oct-03 01:01 UTC
[LLVMdev] Use list preservation when using Instruction::clone
Ok, it took me a little while to isolate this into a test case, but I have one, in the attached tarball. Please run the attached pass on the attached bitcode (LLVM 3.4). The bug I'm seeing is summarized as follows: 1. Save a list of all of the function F's instructions. 2. Create a clone of the function F. 3. JIT and execute the cloned function. 4. Assert that the body of F has not changed. The bug is the assertion in (4) failing. If you run the test case, you should see a crash with this message: Assertion failed: (false), function validateFunctionBody, file Test.cpp, line 50. The reason I started this thread asking about use lists is I think this has to do with instructions in the cloned function listing instructions in the original function as Uses, and thus when the JIT erases some instructions in the cloned function, the originals are deleted as dead code. That's just a hypothesis, anyway, I'm not sure it's correct. I don't think this seems like intended behavior, but perhaps with this additional information about the behavior I'm seeing, someone can shed some light on this for me. Tyler Quoting Jingyue Wu <jingyue at google.com>:> Hi Tyler, > > Doesn't look right. Would you mind attaching the test? > > Btw, instead of creating an empty function and CloneFunctionInto, can you > just CloneFunction? > > Jingyue > > On Thu Oct 02 2014 at 2:47:51 PM Tyler Denniston <tyler at csail.mit.edu> > wrote: > >> I'm trying to create a clone of a function using Function::Create() >> and CloneFunctionInto. However, I'm running into an issue. I believe >> that the instructions in the function clone still have Use edges to >> values in the original function. This is a problem for my purposes. >> >> For example, consider an original function F. I create a new function >> G belonging to the same module and call CloneFunctionInto(G, F) to >> copy over the function body. Now, consider a phi node p in F, and an >> instruction I in F which uses p. The problem is, the cloned phi node >> p' in G still lists I as a user. >> >> Is this intended behavior? And if so, is there a way I can remove >> these Use edges in my cloned function? >> >> Thanks, >> >> Tyler >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>-------------- next part -------------- A non-text attachment was scrubbed... Name: bug.tar.gz Type: application/x-gzip Size: 6656 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141002/12ba25e4/attachment.bin>