diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-04-14 21:41:27 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-06-22 18:20:56 +0000 |
commit | bdd1243df58e60e85101c09001d9812a789b6bc4 (patch) | |
tree | a1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp | |
parent | 781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff) | |
parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp index 96485d15c75b..b125e952ec94 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp @@ -13,7 +13,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" @@ -138,25 +137,28 @@ static bool partitionOuterLoopBlocks(Loop *L, Loop *SubLoop, template <typename T> static bool processHeaderPhiOperands(BasicBlock *Header, BasicBlock *Latch, BasicBlockSet &AftBlocks, T Visit) { - SmallVector<Instruction *, 8> Worklist; SmallPtrSet<Instruction *, 8> VisitedInstr; - for (auto &Phi : Header->phis()) { - Value *V = Phi.getIncomingValueForBlock(Latch); - if (Instruction *I = dyn_cast<Instruction>(V)) - Worklist.push_back(I); - } - while (!Worklist.empty()) { - Instruction *I = Worklist.pop_back_val(); - if (!Visit(I)) - return false; + std::function<bool(Instruction * I)> ProcessInstr = [&](Instruction *I) { + if (VisitedInstr.count(I)) + return true; + VisitedInstr.insert(I); if (AftBlocks.count(I->getParent())) for (auto &U : I->operands()) if (Instruction *II = dyn_cast<Instruction>(U)) - if (!VisitedInstr.count(II)) - Worklist.push_back(II); + if (!ProcessInstr(II)) + return false; + + return Visit(I); + }; + + for (auto &Phi : Header->phis()) { + Value *V = Phi.getIncomingValueForBlock(Latch); + if (Instruction *I = dyn_cast<Instruction>(V)) + if (!ProcessInstr(I)) + return false; } return true; @@ -169,20 +171,12 @@ static void moveHeaderPhiOperandsToForeBlocks(BasicBlock *Header, BasicBlockSet &AftBlocks) { // We need to ensure we move the instructions in the correct order, // starting with the earliest required instruction and moving forward. - std::vector<Instruction *> Visited; processHeaderPhiOperands(Header, Latch, AftBlocks, - [&Visited, &AftBlocks](Instruction *I) { + [&AftBlocks, &InsertLoc](Instruction *I) { if (AftBlocks.count(I->getParent())) - Visited.push_back(I); + I->moveBefore(InsertLoc); return true; }); - - // Move all instructions in program order to before the InsertLoc - BasicBlock *InsertLocBB = InsertLoc->getParent(); - for (Instruction *I : reverse(Visited)) { - if (I->getParent() != InsertLocBB) - I->moveBefore(InsertLoc); - } } /* @@ -261,7 +255,7 @@ llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, // if not outright eliminated. if (SE) { SE->forgetLoop(L); - SE->forgetLoop(SubLoop); + SE->forgetBlockAndLoopDispositions(); } using namespace ore; @@ -349,7 +343,8 @@ llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, // When a FSDiscriminator is enabled, we don't need to add the multiply // factors to the discriminators. - if (Header->getParent()->isDebugInfoForProfiling() && !EnableFSDiscriminator) + if (Header->getParent()->shouldEmitDebugInfoForProfiling() && + !EnableFSDiscriminator) for (BasicBlock *BB : L->getBlocks()) for (Instruction &I : *BB) if (!isa<DbgInfoIntrinsic>(&I)) @@ -375,7 +370,7 @@ llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) { ValueToValueMapTy VMap; BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It)); - Header->getParent()->getBasicBlockList().push_back(New); + Header->getParent()->insert(Header->getParent()->end(), New); // Tell LI about New. addClonedBlockToLoopInfo(*BB, New, LI, NewLoops); @@ -497,7 +492,7 @@ llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, if (CompletelyUnroll) { while (PHINode *Phi = dyn_cast<PHINode>(ForeBlocksFirst[0]->begin())) { Phi->replaceAllUsesWith(Phi->getIncomingValueForBlock(Preheader)); - Phi->getParent()->getInstList().erase(Phi); + Phi->eraseFromParent(); } } else { // Update the PHI values to point to the last aft block |