hi i want replacing a global variable by a constant value for erase instruction. i had seen the code that as follows for (llvm::GlobalVariable::use_iterator U = gv->use_begin(); U !gv->use_end();--U ) { llvm::Instruction *I = llvm::cast<llvm::Instruction>(U); I->replaceAllUsesWith(constPtr); I->eraseFromParent(); } but i dont know how can declare constptr. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111005/35b8a0c8/attachment.html>
Hi nada,> i want replacing a global variable by a constant value for erase instruction.I'm not sure what you mean exactly. A GlobalVariable has pointer type. Do you want to replace that pointer by a constant pointer? Or is it rather that you want to say that the contents of the memory pointed to by the GlobalVariable is constant, and have all places that load that GlobalVariable use the constant instead? Ciao, Duncan.> i had seen the code that as follows > > for (llvm::GlobalVariable::use_iterator U = gv->use_begin(); U != gv->use_end();--U ) { > llvm::Instruction *I = llvm::cast<llvm::Instruction>(U); > I->replaceAllUsesWith(constPtr); > I->eraseFromParent(); > } > > but i dont know how can declare constptr. > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
I would delete the Loop. I used the following code. cout << "begin to delete loop" << endl; for (Loop::block_iterator bi = L->block_begin(), bi2; bi !L->block_end(); bi = bi2) { bi2 = bi; bi2++; BasicBlock * BB = *bi; for (BasicBlock::iterator ii = BB->begin(), ii2; ii != BB->end(); ii= ii2) { ii2 = ii; ii2++; Instruction *inst = ii; inst->eraseFromParent(); } BB->eraseFromParent(); } But I get the following error: Use still stuck around after Def is destroyed: %t1 = icmp sle i32 %t0, 9 opt: /home/llvm/src/lib/VMCore/Value.cpp:75: virtual llvm::Value::~Value(): Assertion `use_empty() && "Uses remain when a value is destroyed!"' failed. 0 opt 0x0848e569 Stack dump: What suggestions do you have for solve this problem? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111006/4fb0c505/attachment.html>