diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp index 9bbfe06b9abb..3be96ebc93a2 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/UnifyLoopExits.cpp @@ -23,6 +23,7 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/Dominators.h" #include "llvm/InitializePasses.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -30,6 +31,11 @@ using namespace llvm; +static cl::opt<unsigned> MaxBooleansInControlFlowHub( + "max-booleans-in-control-flow-hub", cl::init(32), cl::Hidden, + cl::desc("Set the maximum number of outgoing blocks for using a boolean " + "value to record the exiting block in CreateControlFlowHub.")); + namespace { struct UnifyLoopExitsLegacyPass : public FunctionPass { static char ID; @@ -88,7 +94,7 @@ static void restoreSSA(const DominatorTree &DT, const Loop *L, using InstVector = SmallVector<Instruction *, 8>; using IIMap = MapVector<Instruction *, InstVector>; IIMap ExternalUsers; - for (auto BB : L->blocks()) { + for (auto *BB : L->blocks()) { for (auto &I : *BB) { for (auto &U : I.uses()) { auto UserInst = cast<Instruction>(U.getUser()); @@ -114,10 +120,10 @@ static void restoreSSA(const DominatorTree &DT, const Loop *L, // didn't exist in the original CFG. auto Def = II.first; LLVM_DEBUG(dbgs() << "externally used: " << Def->getName() << "\n"); - auto NewPhi = PHINode::Create(Def->getType(), Incoming.size(), - Def->getName() + ".moved", - LoopExitBlock->getTerminator()); - for (auto In : Incoming) { + auto NewPhi = + PHINode::Create(Def->getType(), Incoming.size(), + Def->getName() + ".moved", &LoopExitBlock->front()); + for (auto *In : Incoming) { LLVM_DEBUG(dbgs() << "predecessor " << In->getName() << ": "); if (Def->getParent() == In || DT.dominates(Def, In)) { LLVM_DEBUG(dbgs() << "dominated\n"); @@ -129,7 +135,7 @@ static void restoreSSA(const DominatorTree &DT, const Loop *L, } LLVM_DEBUG(dbgs() << "external users:"); - for (auto U : II.second) { + for (auto *U : II.second) { LLVM_DEBUG(dbgs() << " " << U->getName()); U->replaceUsesOfWith(Def, NewPhi); } @@ -149,9 +155,9 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) { // We need SetVectors, but the Loop API takes a vector, so we use a temporary. SmallVector<BasicBlock *, 8> Temp; L->getExitingBlocks(Temp); - for (auto BB : Temp) { + for (auto *BB : Temp) { ExitingBlocks.insert(BB); - for (auto S : successors(BB)) { + for (auto *S : successors(BB)) { auto SL = LI.getLoopFor(S); // A successor is not an exit if it is directly or indirectly in the // current loop. @@ -181,8 +187,9 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) { SmallVector<BasicBlock *, 8> GuardBlocks; DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); - auto LoopExitBlock = CreateControlFlowHub(&DTU, GuardBlocks, ExitingBlocks, - Exits, "loop.exit"); + auto LoopExitBlock = + CreateControlFlowHub(&DTU, GuardBlocks, ExitingBlocks, Exits, "loop.exit", + MaxBooleansInControlFlowHub.getValue()); restoreSSA(DT, L, ExitingBlocks, LoopExitBlock); @@ -196,7 +203,7 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) { // The guard blocks were created outside the loop, so they need to become // members of the parent loop. if (auto ParentLoop = L->getParentLoop()) { - for (auto G : GuardBlocks) { + for (auto *G : GuardBlocks) { ParentLoop->addBasicBlockToLoop(G, LI); } ParentLoop->verifyLoop(); @@ -213,7 +220,7 @@ static bool runImpl(LoopInfo &LI, DominatorTree &DT) { bool Changed = false; auto Loops = LI.getLoopsInPreorder(); - for (auto L : Loops) { + for (auto *L : Loops) { LLVM_DEBUG(dbgs() << "Loop: " << L->getHeader()->getName() << " (depth: " << LI.getLoopDepth(L->getHeader()) << ")\n"); Changed |= unifyLoopExits(DT, LI, L); |