llvm.org GIT mirror llvm / bd7d65f
[NFC] Instruction: introduce replaceSuccessorWith() function, use it Summary: There is `Instruction::getNumSuccessors()`, `Instruction::getSuccessor()` and `Instruction::setSuccessor()`, but no function to replace every specified `BasicBlock*` successor with some other specified `BasicBlock*`. I've found one place where it should clearly be used. Reviewers: chandlerc, craig.topper, spatel, danielcdh Reviewed By: craig.topper Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61010 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359994 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev 1 year, 5 months ago
3 changed file(s) with 12 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
664664 /// instruction must be a terminator.
665665 void setSuccessor(unsigned Idx, BasicBlock *BB);
666666
667 /// Replace specified successor OldBB to point at the provided block.
668 /// This instruction must be a terminator.
669 void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB);
670
667671 /// Methods for support type inquiry through isa, cast, and dyn_cast:
668672 static bool classof(const Value *V) {
669673 return V->getValueID() >= Value::InstructionVal;
674674 llvm_unreachable("not a terminator");
675675 }
676676
677 void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
678 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
679 Idx != NumSuccessors; ++Idx)
680 if (getSuccessor(Idx) == OldBB)
681 setSuccessor(Idx, NewBB);
682 }
683
677684 Instruction *Instruction::cloneImpl() const {
678685 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
679686 }
442442 if (!LoopMD)
443443 LoopMD = TI->getMetadata(LoopMDKind);
444444 TI->setMetadata(LoopMDKind, nullptr);
445 for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
446 if (TI->getSuccessor(Op) == Header)
447 TI->setSuccessor(Op, BEBlock);
445 TI->replaceSuccessorWith(Header, BEBlock);
448446 }
449447 BEBlock->getTerminator()->setMetadata(LoopMDKind, LoopMD);
450448