[llvm] r282366 - [SCEV] Have ExitNotTakenInfo keep a pointer to its predicate; NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 25 16:12:04 PDT 2016


Author: sanjoy
Date: Sun Sep 25 18:12:04 2016
New Revision: 282366

URL: http://llvm.org/viewvc/llvm-project?rev=282366&view=rev
Log:
[SCEV] Have ExitNotTakenInfo keep a pointer to its predicate; NFC

SCEVUnionPredicate is a "heavyweight" structure, so it is beneficial to
store the (optional) data out of line.

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=282366&r1=282365&r2=282366&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Sun Sep 25 18:12:04 2016
@@ -581,10 +581,16 @@ private:
   struct ExitNotTakenInfo {
     AssertingVH<BasicBlock> ExitingBlock;
     const SCEV *ExactNotTaken;
-    SCEVUnionPredicate Predicate;
+    std::unique_ptr<SCEVUnionPredicate> Predicate;
     bool hasAlwaysTruePredicate() const {
-      return Predicate.isAlwaysTrue();
+      return !Predicate || Predicate->isAlwaysTrue();
     }
+
+    explicit ExitNotTakenInfo(AssertingVH<BasicBlock> ExitingBlock,
+                              const SCEV *ExactNotTaken,
+                              std::unique_ptr<SCEVUnionPredicate> Predicate)
+        : ExitingBlock(ExitingBlock), ExactNotTaken(ExactNotTaken),
+          Predicate(std::move(Predicate)) {}
   };
 
   /// Information about the backedge-taken count of a loop. This currently

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=282366&r1=282365&r2=282366&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sun Sep 25 18:12:04 2016
@@ -5442,7 +5442,7 @@ ScalarEvolution::getPredicatedBackedgeTa
   BackedgeTakenInfo Result =
       computeBackedgeTakenCount(L, /*AllowPredicates=*/true);
 
-  return PredicatedBackedgeTakenCounts.find(L)->second = Result;
+  return PredicatedBackedgeTakenCounts.find(L)->second = std::move(Result);
 }
 
 const ScalarEvolution::BackedgeTakenInfo &
@@ -5517,7 +5517,7 @@ ScalarEvolution::getBackedgeTakenInfo(co
   // recusive call to getBackedgeTakenInfo (on a different
   // loop), which would invalidate the iterator computed
   // earlier.
-  return BackedgeTakenCounts.find(L)->second = Result;
+  return BackedgeTakenCounts.find(L)->second = std::move(Result);
 }
 
 void ScalarEvolution::forgetLoop(const Loop *L) {
@@ -5615,8 +5615,8 @@ ScalarEvolution::BackedgeTakenInfo::getE
       BECount = ENT.ExactNotTaken;
     else if (BECount != ENT.ExactNotTaken)
       return SE->getCouldNotCompute();
-    if (Preds)
-      Preds->add(&ENT.Predicate);
+    if (Preds && !ENT.hasAlwaysTruePredicate())
+      Preds->add(ENT.Predicate.get());
 
     assert((Preds || ENT.hasAlwaysTruePredicate()) &&
            "Predicate should be always true!");
@@ -5670,13 +5670,17 @@ ScalarEvolution::BackedgeTakenInfo::Back
     ArrayRef<ScalarEvolution::EdgeExitInfo> ExitCounts, bool Complete,
     const SCEV *MaxCount)
     : MaxAndComplete(MaxCount, Complete) {
-  std::transform(ExitCounts.begin(), ExitCounts.end(),
-                 std::back_inserter(ExitNotTaken),
-                 [&](const ScalarEvolution::EdgeExitInfo &EEI) {
-                   BasicBlock *ExitBB = EEI.first;
-                   const ExitLimit &EL = EEI.second;
-                   return ExitNotTakenInfo({ExitBB, EL.ExactNotTaken, EL.Predicate});
-                 });
+  std::transform(
+      ExitCounts.begin(), ExitCounts.end(), std::back_inserter(ExitNotTaken),
+      [&](const ScalarEvolution::EdgeExitInfo &EEI) {
+        BasicBlock *ExitBB = EEI.first;
+        const ExitLimit &EL = EEI.second;
+        if (EL.Predicate.isAlwaysTrue())
+          return ExitNotTakenInfo(ExitBB, EL.ExactNotTaken, nullptr);
+        return ExitNotTakenInfo(
+            ExitBB, EL.ExactNotTaken,
+            llvm::make_unique<SCEVUnionPredicate>(std::move(EL.Predicate)));
+      });
 }
 
 /// Invalidate this result and free the ExitNotTakenInfo array.




More information about the llvm-commits mailing list