_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Thank you for your replyin the last step in the pass.
Actually, I did these three steps. Moreover, the step of eraseFromParent()
ClonedFunction->eraseFromParent();However, I tried to copy each basic block with its successors and the result is good.I want to ask you another question. How could I compare the basic block in the OriginalFunction with the basic block in the ClonedFunction?
If I have basic block bb from ClonedFunction and I need to find it in the OriginalFunction, how to do that?Thank you again for your helpOn 10 June 2013 02:28, Cristianno Martins <cristian...@gmail.com> wrote:Well, that's odd. Some time ago I applied the cloneFunction function in one of my passes, but it was just for a test case. So, I'm not actually using it right now, but I guess this specific piece of code is not that different from then. Ok, so I will try to take you all the way through using this function as I did, and you can check if there is any difference between my approach and yours, ok?First, I have in originalFunction the pointer of the function that I want to clone. clonedFunction will be my pointer to the new clone of the originalFunction, and VMap is a ValueToValueMap, that is used by the cloneFunction to remap the references on each instruction and basic-block of the function (you see, when you clone an instruction, the values used by that clone are the same ones on the original, because the clone() function from llvm::Instruction does not clone its uses, just the instruction itself).Anyways, the code needed to clone that function should be something like// clone the function, but does not add it to any moduleclonedFunction = CloneFunction(originalFunction, VMap, false);
// since this copy will not be called from outside this module, overwrites whatever linkage mode the original had (also cloned) to internal
clonedFunction->setLinkage(GlobalValue::InternalLinkage);
// finally, inserts the clone into the same module where originalFunction is.
originalFunction->getParent()->getFunctionList().push_back(clonedFunction);
After this three steps, I had in clonedFunction an exact copy of all instructions and, as a consequence, the same CFG from the original one.
Can you see any difference from the way you called that function?On Sun, Jun 9, 2013 at 6:06 AM, Rasha Omar <rasha...@gmail.com> wrote:
Thank you for your real helpThe main problem in cloning that when i tried to print the cfg for the original function in a dot file it's printed with the basic block details, but the cloned one is printed the same shape of CFG with empty blocks. I'm not sure , but do you think that it may give me the real blocks or it's something dummy. I'm trying this function from a long time. If you could help me to reach to the real CFG I'll be so grateful for you.Firstly, Thank you for your reply.Secondly, I tried clone function before and it gave me some problems. I tried to use he clone function in the PartialInling.cpp and it gives me the same problems
On 8 June 2013 05:16, Cristianno Martins <cristian...@gmail.com> wrote:
Hello Rasha,I think what you want you can do in LLVM by creating a copy of the whole function you are trying to modify, and applying your transformations only on this new copy. You can easily do that using CloneFunction (a function defined in llvm/Transforms/Util/Cloning.h). An example of its use can be seen on the function unswitchFunction(Function* f), from lib/Transforms/IPO/PartialInlining.cpp file.Hope this can be helpful,