[PATCH] D61010: [NFC] Instruction: introduce replaceSuccessorWith() function, use it
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 5 12:01:53 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359994: [NFC] Instruction: introduce replaceSuccessorWith() function, use it (authored by lebedevri, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D61010?vs=196805&id=198190#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61010/new/
https://reviews.llvm.org/D61010
Files:
llvm/trunk/include/llvm/IR/Instruction.h
llvm/trunk/lib/IR/Instruction.cpp
llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
Index: llvm/trunk/lib/IR/Instruction.cpp
===================================================================
--- llvm/trunk/lib/IR/Instruction.cpp
+++ llvm/trunk/lib/IR/Instruction.cpp
@@ -675,6 +675,13 @@
llvm_unreachable("not a terminator");
}
+void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
+ for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
+ Idx != NumSuccessors; ++Idx)
+ if (getSuccessor(Idx) == OldBB)
+ setSuccessor(Idx, NewBB);
+}
+
Instruction *Instruction::cloneImpl() const {
llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
}
Index: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
@@ -443,9 +443,7 @@
if (!LoopMD)
LoopMD = TI->getMetadata(LoopMDKind);
TI->setMetadata(LoopMDKind, nullptr);
- for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
- if (TI->getSuccessor(Op) == Header)
- TI->setSuccessor(Op, BEBlock);
+ TI->replaceSuccessorWith(Header, BEBlock);
}
BEBlock->getTerminator()->setMetadata(LoopMDKind, LoopMD);
Index: llvm/trunk/include/llvm/IR/Instruction.h
===================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h
+++ llvm/trunk/include/llvm/IR/Instruction.h
@@ -665,6 +665,10 @@
/// instruction must be a terminator.
void setSuccessor(unsigned Idx, BasicBlock *BB);
+ /// Replace specified successor OldBB to point at the provided block.
+ /// This instruction must be a terminator.
+ void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB);
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() >= Value::InstructionVal;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61010.198190.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190505/371dd423/attachment.bin>
More information about the llvm-commits
mailing list