From: Sanjoy Das Date: Sun, 25 Sep 2016 23:11:55 +0000 (+0000) Subject: [SCEV] Remove incidental data structure; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b4332c09011b099ca611b6a4f364232d2a4523f;p=llvm [SCEV] Remove incidental data structure; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282363 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index 0194a3d8029..0fe0d0ba3e5 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -691,22 +691,7 @@ private: SmallVector Exits; }; - /// A struct containing the information attached to a backedge. - struct EdgeInfo { - EdgeInfo(BasicBlock *Block, const SCEV *Taken, SCEVUnionPredicate &P) - : ExitBlock(Block), Taken(Taken), Pred(std::move(P)) {} - - /// The exit basic block. - BasicBlock *ExitBlock; - - /// The (exact) number of time we take the edge back. - const SCEV *Taken; - - /// The SCEV predicated associated with Taken. If Pred doesn't evaluate - /// to true, the information in Taken is not valid (or equivalent with - /// a CouldNotCompute. - SCEVUnionPredicate Pred; - }; + typedef std::pair EdgeExitInfo; /// Information about the backedge-taken count of a loop. This currently /// includes an exact count and a maximum count. @@ -725,7 +710,7 @@ private: BackedgeTakenInfo() : Max(nullptr) {} /// Initialize BackedgeTakenInfo from a list of exact exit counts. - BackedgeTakenInfo(SmallVectorImpl &ExitCounts, bool Complete, + BackedgeTakenInfo(ArrayRef ExitCounts, bool Complete, const SCEV *MaxCount); /// Test whether this BackedgeTakenInfo contains any computed information, diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index e97e6684290..84dca06033b 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -5669,26 +5669,30 @@ bool ScalarEvolution::BackedgeTakenInfo::hasOperand(const SCEV *S, /// Allocate memory for BackedgeTakenInfo and copy the not-taken count of each /// computable exit into a persistent ExitNotTakenInfo array. ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo( - SmallVectorImpl &ExitCounts, bool Complete, const SCEV *MaxCount) + ArrayRef ExitCounts, bool Complete, + const SCEV *MaxCount) : Max(MaxCount) { if (!Complete) ExitNotTaken.setIncomplete(); unsigned NumExits = ExitCounts.size(); - if (NumExits == 0) return; + if (NumExits == 0) + return; - ExitNotTaken.ExitingBlock = ExitCounts[0].ExitBlock; - ExitNotTaken.ExactNotTaken = ExitCounts[0].Taken; + ExitNotTaken.ExitingBlock = ExitCounts[0].first; + ExitNotTaken.ExactNotTaken = ExitCounts[0].second.Exact; // Determine the number of ExitNotTakenExtras structures that we need. unsigned ExtraInfoSize = 0; - if (NumExits > 1) + if (NumExits > 1) { + auto HasNonTrivialPredicate = + [](const ScalarEvolution::EdgeExitInfo &Entry) { + return !Entry.second.Pred.isAlwaysTrue(); + }; ExtraInfoSize = 1 + std::count_if(std::next(ExitCounts.begin()), - ExitCounts.end(), [](EdgeInfo &Entry) { - return !Entry.Pred.isAlwaysTrue(); - }); - else if (!ExitCounts[0].Pred.isAlwaysTrue()) + ExitCounts.end(), HasNonTrivialPredicate); + } else if (!ExitCounts[0].second.Pred.isAlwaysTrue()) ExtraInfoSize = 1; ExitNotTakenExtras *ENT = nullptr; @@ -5698,7 +5702,7 @@ ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo( if (ExtraInfoSize > 0) { ENT = new ExitNotTakenExtras[ExtraInfoSize]; ExitNotTaken.ExtraInfo = &ENT[0]; - *ExitNotTaken.getPred() = std::move(ExitCounts[0].Pred); + *ExitNotTaken.getPred() = std::move(ExitCounts[0].second.Pred); } if (NumExits == 1) @@ -5711,12 +5715,12 @@ ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo( // Handle the rare case of multiple computable exits. for (unsigned i = 1, PredPos = 1; i < NumExits; ++i) { ExitNotTakenExtras *Ptr = nullptr; - if (!ExitCounts[i].Pred.isAlwaysTrue()) { + if (!ExitCounts[i].second.Pred.isAlwaysTrue()) { Ptr = &ENT[PredPos++]; - Ptr->Pred = std::move(ExitCounts[i].Pred); + Ptr->Pred = std::move(ExitCounts[i].second.Pred); } - Exits.emplace_back(ExitCounts[i].ExitBlock, ExitCounts[i].Taken, Ptr); + Exits.emplace_back(ExitCounts[i].first, ExitCounts[i].second.Exact, Ptr); } } @@ -5734,7 +5738,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L, SmallVector ExitingBlocks; L->getExitingBlocks(ExitingBlocks); - SmallVector ExitCounts; + SmallVector ExitCounts; bool CouldComputeBECount = true; BasicBlock *Latch = L->getLoopLatch(); // may be NULL. const SCEV *MustExitMaxBECount = nullptr; @@ -5757,7 +5761,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L, // we won't be able to compute an exact value for the loop. CouldComputeBECount = false; else - ExitCounts.emplace_back(EdgeInfo(ExitBB, EL.Exact, EL.Pred)); + ExitCounts.emplace_back(ExitBB, EL); // 2. Derive the loop's MaxBECount from each exit's max number of // non-exiting iterations. Partition the loop exits into two kinds: