Howto properly discard parentless instructions

Hi there,

i am currently working on a transformation pass where i replace some function calls. I use replaceAllUsesWith() to replace them.

After that i want to clean up like this:

callInst->removeFromParent();
delete callInst;

If the instruction is not deleted an error occurs when running the pass (parentless instruction). So is it okay to do it this way or is there a better way to do it?

Regards

Lorenz

Refer to [1], maybe you can try Instruction::eraseFromParent().

[1] http://llvm.org/doxygen/classllvm_1_1Instruction.html