[LLVMdev] BasicBlock succ iterator

neda 8664 neda8664 at gmail.com
Fri Oct 14 05:34:43 PDT 2011


Hi

I have checked all blocks, each block have a Terminator instruction and each
blocks belongs to a function.
I'm really confused. I guess the problem is caused by the removal of the
Loop,The code is as follows:


*    //every block to header (except the ones in the loop), will now
redirect to newblock
    for (pred_iterator PI = pred_begin(header); PI != pred_end(header);
++PI) {
        BasicBlock *pred = *PI;
        if (L->contains(pred)) {
            continue;
        }
        TerminatorInst *termInst = pred->getTerminator();

        for (unsigned i = 0; i < termInst->getNumOperands(); i++) {
            BasicBlock *bb = dyn_cast<BasicBlock> (termInst->getOperand(i));
            if (bb == header) {
                termInst->setOperand(i,newBlock);
            }
        }
    }*

*    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->replaceAllUsesWith(UndefValue::get(inst->getType()));
            inst->eraseFromParent();
        }
        for (pred_iterator PI = pred_begin(BB); PI != pred_end(BB); ++PI)
        {
            BasicBlock *pred = *PI;
            if (!L->contains(pred))
                continue;
            pred->getTerminator()->eraseFromParent();
        }
        BB->eraseFromParent();
    }
*
May this code be causing the problem?

Best  regards
neda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111014/9b755118/attachment.html>


More information about the llvm-dev mailing list