On Sun, 2 May 2004 kiyancla at uiuc.edu wrote:
> Hi,
>
> First, sorry in advance for pasting code like this :)
>
> I'm doing a simple optimization pass for a cs326 class
> project. The pass in question is LICM, and I'm getting an
> assertion when I try to hoist an instruction.
>
> My hoist function is below. I dont think I need that
> copying in there, that was just something people on the
> newsgroup suggested. I get the same assertion regardless.
> So, the code:
There are two problems here. One is that you never delete the "I"
instruction. The "remove" method takes it out of the basic block it
is
in, but it does not actually delete it. If you really want to delete it,
use 'erase' instead of "remove".
> =======================================>
=======================================> bool LICM::hoist(Instruction *I,
const Loop* L){
> DEBUG(std::cerr << "HOIST\n");
>
> //remove instruction, and stick it in the preheader,
> BEFORE
> //the last Instruction of that block (which is a branch)
>
> Instruction* I2 = I->clone();
> I2->setName("Billy");
> I->replaceAllUsesWith(I2);
>
> I->getParent()->getInstList().remove(I);
>
> //we want to insert before the
> //branch at the end
This is the second problem:> iplist<Instruction> preheaderInsts >
L->getLoopPreheader()->getInstList();
This *copies* the ilist in the basic block, where you really want to just
get a reference to it. Try:
iplist<Instruction> &preheaderInsts =
L->getLoopPreheader()->getInstList();
> iplist<Instruction>::iterator i = preheaderInsts.end();
> i--;
>
>
> preheaderInsts.insert(i, I2);
Another comment: Instruction*'s and iterators automatically convert to
each other, so you can use instruction*'s where you would use an iterator.
This means that the above code can get rid of the 'i' iterator and just
use:
preheaderInsts.insert(L->getLoopPreheader()->getTerminator(), I2);
... but that's just a code clarity thing, not a correctness thing.
-Chris
>
> //I->getParent()->getInstList().remove(I);
> DEBUG(std::cerr << "HOIST: DONE\n");
> return false;
> }
>
>
> ==========================================>
==========================================> and the assertion:
> While deleting: int%Billy
> Use still stuck around after Def is destroyed: ret int
> %Billy
>
> opt: Value.cpp:51: virtual llvm::Value::~Value(): Assertion
> `Uses.begin() == Uses.end() &&"Uses remain when a value is
> destroyed!"' failed.
> Aborted
> nadir at quiche:~/src/llvm/lib/Transforms/LICM$ fg
> emacs LICM.cpp
>
> ====================================>
====================================>
> Any help is appreciated,
>
> Nadir Kiyanclar
> kiyancla at uiuc.edu
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/