[LLVMdev] hoisting problem.

kiyancla at uiuc.edu kiyancla at uiuc.edu
Sun May 2 11:09:01 PDT 2004


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: 
======================================== 
======================================== 
  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 
    iplist<Instruction> preheaderInsts = 
L->getLoopPreheader()->getInstList(); 
    iplist<Instruction>::iterator i = preheaderInsts.end(); 
    i--; 
     
    
    preheaderInsts.insert(i, I2); 
   
    //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 



More information about the llvm-dev mailing list