The clone llvm:CloneBasicBlock copies the phi function in the replicated basic block from the original basic block. I don't want the copy of phi in relplicated block. For now I am creating .bc file with -O0 option so that it doesn't generate phi function in first place. Is this a good approach or there are some other function available for it. Tarun On Sun, Apr 17, 2011 at 5:22 AM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Sat, Apr 16, 2011 at 4:32 PM, tarun agrawal <tarun at cse.iitb.ac.in> > wrote: > > Hi, > > > > I am writing a pass for constant propagation using graph restructuring ( > > code duplication). I am facing following difficulties.. > > > > 1) I need to replicate the basic block but without phi function in the > > replicated block. How can I do this. > > > > 2) I need to insert that basic block after and before some particular > basic > > block. > > You probably want to use llvm::CloneBasicBlock from > Transforms/Utils/Cloning.h to get a cloned version of a block. > BasicBlock::splitBasicBlock might be useful as well. > > -Eli >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110417/e917db8a/attachment.html>
On 4/16/11 7:01 PM, tarun agrawal wrote:> The clone llvm:CloneBasicBlock copies the phi function in the > replicated basic block from the original basic block.After you clone the basic block, you can probably replace the phi instruction with another value of your choice. If you're adding variables, you'll probably want to create them as allocas and use loads and stores to access them. In such as case, you'd replace the phi in the new BasicBlock with a load of your new variable. Once all your basic blocks are in place and all the terminator instructions are modified so that your control-flow graph is the way you want it to be, you can run mem2reg to change your alloca variables into real SSA variables with phi-nodes in your new basic blocks. -- John T.> I don't want the copy of phi in relplicated block. For now I am > creating .bc file with -O0 option so that it doesn't generate phi > function in first place. Is this a good approach or there are some > other function available for it. > > Tarun > > On Sun, Apr 17, 2011 at 5:22 AM, Eli Friedman <eli.friedman at gmail.com > <mailto:eli.friedman at gmail.com>> wrote: > > On Sat, Apr 16, 2011 at 4:32 PM, tarun agrawal > <tarun at cse.iitb.ac.in <mailto:tarun at cse.iitb.ac.in>> wrote: > > Hi, > > > > I am writing a pass for constant propagation using graph > restructuring ( > > code duplication). I am facing following difficulties.. > > > > 1) I need to replicate the basic block but without phi function > in the > > replicated block. How can I do this. > > > > 2) I need to insert that basic block after and before some > particular basic > > block. > > You probably want to use llvm::CloneBasicBlock from > Transforms/Utils/Cloning.h to get a cloned version of a block. > BasicBlock::splitBasicBlock might be useful as well. > > -Eli > > > > _______________________________________________ > 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/20110416/1a4a8040/attachment.html>
On Sat, Apr 16, 2011 at 5:01 PM, tarun agrawal <tarun at cse.iitb.ac.in> wrote:> The clone llvm:CloneBasicBlock copies the phi function in the replicated > basic block from the original basic block. > I don't want the copy of phi in relplicated block. For now I am creating .bc > file with -O0 option so that it doesn't generate phi function in first > place. Is this a good approach or there are some other function available > for it.CloneBasicBlock isn't going to do anything magical... I pointed towards BasicBlock::splitBasicBlock because I figured you could split the PHIs out of the block you want to clone, or something like that. Using DemotePHIToStack on PHI nodes to eliminate them is another possibility. Trying to do optimizations without running mem2reg is a really bad idea for practical use: most optimization opportunities will be hidden behind loads and stores to allocas. -Eli
Thanks John I will try it... Tarun On Sun, Apr 17, 2011 at 5:39 AM, John Criswell <criswell at illinois.edu>wrote:> On 4/16/11 7:01 PM, tarun agrawal wrote: > > The clone llvm:CloneBasicBlock copies the phi function in the replicated > basic block from the original basic block. > > > After you clone the basic block, you can probably replace the phi > instruction with another value of your choice. If you're adding variables, > you'll probably want to create them as allocas and use loads and stores to > access them. In such as case, you'd replace the phi in the new BasicBlock > with a load of your new variable. > > Once all your basic blocks are in place and all the terminator instructions > are modified so that your control-flow graph is the way you want it to be, > you can run mem2reg to change your alloca variables into real SSA variables > with phi-nodes in your new basic blocks. > > -- John T. > > > I don't want the copy of phi in relplicated block. For now I am creating > .bc file with -O0 option so that it doesn't generate phi function in first > place. Is this a good approach or there are some other function available > for it. > > Tarun > > On Sun, Apr 17, 2011 at 5:22 AM, Eli Friedman <eli.friedman at gmail.com>wrote: > >> On Sat, Apr 16, 2011 at 4:32 PM, tarun agrawal <tarun at cse.iitb.ac.in> >> wrote: >> > Hi, >> > >> > I am writing a pass for constant propagation using graph restructuring ( >> > code duplication). I am facing following difficulties.. >> > >> > 1) I need to replicate the basic block but without phi function in the >> > replicated block. How can I do this. >> > >> > 2) I need to insert that basic block after and before some particular >> basic >> > block. >> >> You probably want to use llvm::CloneBasicBlock from >> Transforms/Utils/Cloning.h to get a cloned version of a block. >> BasicBlock::splitBasicBlock might be useful as well. >> >> -Eli >> > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110417/0d4ebbfc/attachment.html>
Splitting the basic block might not work for me but I think DemotePHIToStack will solve the problem.. Thanks for the reply. Tarun On Sun, Apr 17, 2011 at 5:45 AM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Sat, Apr 16, 2011 at 5:01 PM, tarun agrawal <tarun at cse.iitb.ac.in> > wrote: > > The clone llvm:CloneBasicBlock copies the phi function in the replicated > > basic block from the original basic block. > > I don't want the copy of phi in relplicated block. For now I am creating > .bc > > file with -O0 option so that it doesn't generate phi function in first > > place. Is this a good approach or there are some other function available > > for it. > > CloneBasicBlock isn't going to do anything magical... I pointed > towards BasicBlock::splitBasicBlock because I figured you could split > the PHIs out of the block you want to clone, or something like that. > Using DemotePHIToStack on PHI nodes to eliminate them is another > possibility. > > Trying to do optimizations without running mem2reg is a really bad > idea for practical use: most optimization opportunities will be hidden > behind loads and stores to allocas. > > -Eli >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110417/affec0ca/attachment.html>