[LLVMdev] BasicBlock succ iterator

Duncan Sands baldrick at free.fr
Fri Oct 14 06:21:34 PDT 2011


Hi neda, general advice: (1) build LLVM with assertions enabled; (2) run your
pass under valgrind.

Ciao, Duncan.

> I have checked all blocks, each block have a Terminator instruction and each
> blocks belongs to a function.
> I'mreallyconfused. I guess theproblemiscaused bytheremoval ofthe Loop,Thecodeis
> 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
>




More information about the llvm-dev mailing list