Je me demandais comment nous pouvons supprimer un tas d'instructions dans LLVM. J'ai essayé les éléments suivants (sur la base d'un poste de la liste de diffusion LLVM-dev)la suppression d'un tas d'instructions llvm
// delete all instructions between [start,end)
void deleteAllInstructionsInRange(Instruction* startInst,Instruction* endInst)
{
BasicBlock::iterator it(startInst);
BasicBlock::iterator it_end(endInst);
it_end--;
Instruction* currentInst ;
while(it != it_end)
{
currentInst = &*it;
// this cannot be done at the end of the while loop.
// has to be incremented before "erasing" the instruction
++it;
if (!currentInst->use_empty())
{
currentInst->replaceAllUsesWith(UndefValue::get(currentInst->getType()));
}
currentInst->eraseFromParent();
}
}
Tout fonctionne comme prévu, sauf pour la dernière itération. Quelqu'un comprend pourquoi? (J'ai essayé d'utiliser gdb mais cela donne une erreur de segfault dans la dernière itération)