On Thu, Feb 17, 2005 at 01:22:22PM -0600, Chris Lattner wrote:> // Approach number 2, the more explicit way: > BB->getParent()->getInstList().erase(BB); // Remove from list & delete > > // Approach number 3, remove from the list, then delete it explicitly: > BB->getParent()->getInstList().remove(BB); // Just remove from list > delete BB; // Delete blockMinor correction there: replace "getInstList()" with "getBasicBlockList()". The former is only applicable to BasicBlocks, the latter to Functions. -- Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
On Thu, 17 Feb 2005, Tanu Sharma wrote:> I created a new block and inserted it into the present basic block list > , but I get this error: > > opt: BasicBlock.cpp:83: virtual llvm::BasicBlock::~BasicBlock(): Assertion `getParent() == 0 && "BasicBlock still linked into the program!"' failed. > > The program completes its task and i get this in the end. I am unable to > resolve this.The problem there is that you're trying to delete some basic block that is still embedded into a function. There are several ways to accomplish this: BasicBlock *BB = ... // Approach number 1, the easy way: BB->eraseFromParent(); // Approach number 2, the more explicit way: BB->getParent()->getInstList().erase(BB); // Remove from list & delete // Approach number 3, remove from the list, then delete it explicitly: BB->getParent()->getInstList().remove(BB); // Just remove from list delete BB; // Delete block I strongly suggest using approach #1, but I listed all of them so you can see the relation between remove and erase. -Chris> John Criswell <criswell at cs.uiuc.edu> wrote: > Tanu Sharma wrote: >> Hello, >> >> In an attempt to randomise the basic blocks in a function, is it >> possible that I can randomise the entry block as well? And maybe insert >> some instructions in the pass to call entry block while running the >> program ? >> >> Is it feasible? >> >> What does entry block consist of ? > > The entry block, by definition, is the first basic block (BB) to be > executed by a function. As I understand it, it has the additional > restriction that it cannot be dominated by other basic blocks (i.e. no > other BBs in the function can branch to it). > > If your entry BB performs useful computations and you want to move it, > you could create a new entry BB that does nothing but branch to the old > entry BB. The old entry BB (now just a regular BB) can then be moved. > > I'm assuming thus far that you're randomizing the basic block order at > the LLVM level (i.e. take LLVM function, randomize order of BBs, and > then codegen each BB in order). Another approach, as I see it, would be > to change the code generator so that it codegens the BBs in a random > order, instead of codegen'ing them in order. > > The first approach, I think, is a lot easier. > > Regards, > > -- John T. > >> >> Thanks >> >> Tanu >> >> >> >> ------------------------------------------------------------------------ >> Do you Yahoo!? >> Yahoo! Search presents - Jib Jab's 'Second Term' >> >> >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com-Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
On Thu, 17 Feb 2005, Misha Brukman wrote:> On Thu, Feb 17, 2005 at 01:22:22PM -0600, Chris Lattner wrote: >> // Approach number 2, the more explicit way: >> BB->getParent()->getInstList().erase(BB); // Remove from list & delete >> >> // Approach number 3, remove from the list, then delete it explicitly: >> BB->getParent()->getInstList().remove(BB); // Just remove from list >> delete BB; // Delete block > > Minor correction there: replace "getInstList()" with > "getBasicBlockList()". The former is only applicable to BasicBlocks, > the latter to Functions.oops, right, thanks Misha! :) -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
Thanks a lot for replying...but I am not doing any deleting or removing node ...I am trying to insert a "new" entry node in an existing list. In another reply I understood (also mentioned on the site) that no other block can branch to the entry block. How do I achieve this ? Is it feasible?Let me know if there is any example. Thanks again, Tanu Chris Lattner <sabre at nondot.org> wrote: On Thu, 17 Feb 2005, Tanu Sharma wrote:> I created a new block and inserted it into the present basic block list > , but I get this error: > > opt: BasicBlock.cpp:83: virtual llvm::BasicBlock::~BasicBlock(): Assertion `getParent() == 0 && "BasicBlock still linked into the program!"' failed. > > The program completes its task and i get this in the end. I am unable to > resolve this.The problem there is that you're trying to delete some basic block that is still embedded into a function. There are several ways to accomplish this: BasicBlock *BB = ... // Approach number 1, the easy way: BB->eraseFromParent(); // Approach number 2, the more explicit way: BB->getParent()->getInstList().erase(BB); // Remove from list & delete // Approach number 3, remove from the list, then delete it explicitly: BB->getParent()->getInstList().remove(BB); // Just remove from list delete BB; // Delete block I strongly suggest using approach #1, but I listed all of them so you can see the relation between remove and erase. -Chris> John Criswell wrote: > Tanu Sharma wrote: >> Hello, >> >> In an attempt to randomise the basic blocks in a function, is it >> possible that I can randomise the entry block as well? And maybe insert >> some instructions in the pass to call entry block while running the >> program ? >> >> Is it feasible? >> >> What does entry block consist of ? > > The entry block, by definition, is the first basic block (BB) to be > executed by a function. As I understand it, it has the additional > restriction that it cannot be dominated by other basic blocks (i.e. no > other BBs in the function can branch to it). > > If your entry BB performs useful computations and you want to move it, > you could create a new entry BB that does nothing but branch to the old > entry BB. The old entry BB (now just a regular BB) can then be moved. > > I'm assuming thus far that you're randomizing the basic block order at > the LLVM level (i.e. take LLVM function, randomize order of BBs, and > then codegen each BB in order). Another approach, as I see it, would be > to change the code generator so that it codegens the BBs in a random > order, instead of codegen'ing them in order. > > The first approach, I think, is a lot easier. > > Regards, > > -- John T. > >> >> Thanks >> >> Tanu >> >> >> >> ------------------------------------------------------------------------ >> Do you Yahoo!? >> Yahoo! Search presents - Jib Jab's 'Second Term' >> >> >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com-Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/ _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20050217/05181295/attachment.html>
On Thu, 17 Feb 2005, Tanu Sharma wrote:> Thanks a lot for replying...but I am not doing any deleting or removing node ...I am trying to insert a "new" entry node in an existing list. > In another reply I understood (also mentioned on the site) that no other block can branch to the entry block. > > How do I achieve this ? Is it feasible?Let me know if there is any example.Can you provide a stack trace for the failed assertion? -Chris> Chris Lattner <sabre at nondot.org> wrote: > On Thu, 17 Feb 2005, Tanu Sharma wrote: >> I created a new block and inserted it into the present basic block list >> , but I get this error: >> >> opt: BasicBlock.cpp:83: virtual llvm::BasicBlock::~BasicBlock(): Assertion `getParent() == 0 && "BasicBlock still linked into the program!"' failed. >> >> The program completes its task and i get this in the end. I am unable to >> resolve this. > > The problem there is that you're trying to delete some basic block that is > still embedded into a function. There are several ways to accomplish > this: > > BasicBlock *BB = ... > > // Approach number 1, the easy way: > BB->eraseFromParent(); > > // Approach number 2, the more explicit way: > BB->getParent()->getInstList().erase(BB); // Remove from list & delete > > // Approach number 3, remove from the list, then delete it explicitly: > BB->getParent()->getInstList().remove(BB); // Just remove from list > delete BB; // Delete block > > > I strongly suggest using approach #1, but I listed all of them so you can > see the relation between remove and erase. > > -Chris > > >> John Criswell wrote: >> Tanu Sharma wrote: >>> Hello, >>> >>> In an attempt to randomise the basic blocks in a function, is it >>> possible that I can randomise the entry block as well? And maybe insert >>> some instructions in the pass to call entry block while running the >>> program ? >>> >>> Is it feasible? >>> >>> What does entry block consist of ? >> >> The entry block, by definition, is the first basic block (BB) to be >> executed by a function. As I understand it, it has the additional >> restriction that it cannot be dominated by other basic blocks (i.e. no >> other BBs in the function can branch to it). >> >> If your entry BB performs useful computations and you want to move it, >> you could create a new entry BB that does nothing but branch to the old >> entry BB. The old entry BB (now just a regular BB) can then be moved. >> >> I'm assuming thus far that you're randomizing the basic block order at >> the LLVM level (i.e. take LLVM function, randomize order of BBs, and >> then codegen each BB in order). Another approach, as I see it, would be >> to change the code generator so that it codegens the BBs in a random >> order, instead of codegen'ing them in order. >> >> The first approach, I think, is a lot easier. >> >> Regards, >> >> -- John T. >> >>> >>> Thanks >>> >>> Tanu >>> >>> >>> >>> ------------------------------------------------------------------------ >>> Do you Yahoo!? >>> Yahoo! Search presents - Jib Jab's 'Second Term' >>> >>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> __________________________________________________ >> Do You Yahoo!? >> Tired of spam? Yahoo! Mail has the best spam protection around >> http://mail.yahoo.com > > -Chris > >-Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/