summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2017-12-30 15:27:33 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2017-12-30 15:27:33 +0000
commitc7fc81e6595865296738fe0f8ffe692ea41b1ffc (patch)
tree9c14093b59b87a53d42ecbeb9c263c85f46f97e3 /llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
parent06f6d262f99d4bc13739eb224084d239f5445682 (diff)
downloadbcm5719-llvm-c7fc81e6595865296738fe0f8ffe692ea41b1ffc.tar.gz
bcm5719-llvm-c7fc81e6595865296738fe0f8ffe692ea41b1ffc.zip
Use phi ranges to simplify code. No functionality change intended.
llvm-svn: 321585
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp34
1 files changed, 12 insertions, 22 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 3d0fca0bc3a..aba732bc413 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -271,19 +271,14 @@ static bool areLoopExitPHIsLoopInvariant(Loop &L, BasicBlock &ExitingBB,
static void rewritePHINodesForUnswitchedExitBlock(BasicBlock &UnswitchedBB,
BasicBlock &OldExitingBB,
BasicBlock &OldPH) {
- for (Instruction &I : UnswitchedBB) {
- auto *PN = dyn_cast<PHINode>(&I);
- if (!PN)
- // No more PHIs to check.
- break;
-
+ for (PHINode &PN : UnswitchedBB.phis()) {
// When the loop exit is directly unswitched we just need to update the
// incoming basic block. We loop to handle weird cases with repeated
// incoming blocks, but expect to typically only have one operand here.
- for (auto i : seq<int>(0, PN->getNumOperands())) {
- assert(PN->getIncomingBlock(i) == &OldExitingBB &&
+ for (auto i : seq<int>(0, PN.getNumOperands())) {
+ assert(PN.getIncomingBlock(i) == &OldExitingBB &&
"Found incoming block different from unique predecessor!");
- PN->setIncomingBlock(i, &OldPH);
+ PN.setIncomingBlock(i, &OldPH);
}
}
}
@@ -302,14 +297,9 @@ static void rewritePHINodesForExitAndUnswitchedBlocks(BasicBlock &ExitBB,
assert(&ExitBB != &UnswitchedBB &&
"Must have different loop exit and unswitched blocks!");
Instruction *InsertPt = &*UnswitchedBB.begin();
- for (Instruction &I : ExitBB) {
- auto *PN = dyn_cast<PHINode>(&I);
- if (!PN)
- // No more PHIs to check.
- break;
-
- auto *NewPN = PHINode::Create(PN->getType(), /*NumReservedValues*/ 2,
- PN->getName() + ".split", InsertPt);
+ for (PHINode &PN : ExitBB.phis()) {
+ auto *NewPN = PHINode::Create(PN.getType(), /*NumReservedValues*/ 2,
+ PN.getName() + ".split", InsertPt);
// Walk backwards over the old PHI node's inputs to minimize the cost of
// removing each one. We have to do this weird loop manually so that we
@@ -320,18 +310,18 @@ static void rewritePHINodesForExitAndUnswitchedBlocks(BasicBlock &ExitBB,
// allowed us to create a single entry for a predecessor block without
// having separate entries for each "edge" even though these edges are
// required to produce identical results.
- for (int i = PN->getNumIncomingValues() - 1; i >= 0; --i) {
- if (PN->getIncomingBlock(i) != &OldExitingBB)
+ for (int i = PN.getNumIncomingValues() - 1; i >= 0; --i) {
+ if (PN.getIncomingBlock(i) != &OldExitingBB)
continue;
- Value *Incoming = PN->removeIncomingValue(i);
+ Value *Incoming = PN.removeIncomingValue(i);
NewPN->addIncoming(Incoming, &OldPH);
}
// Now replace the old PHI with the new one and wire the old one in as an
// input to the new one.
- PN->replaceAllUsesWith(NewPN);
- NewPN->addIncoming(PN, &ExitBB);
+ PN.replaceAllUsesWith(NewPN);
+ NewPN->addIncoming(&PN, &ExitBB);
}
}
OpenPOWER on IntegriCloud