]> granicus.if.org Git - llvm/commitdiff
[SCEV] Have ExitNotTakenInfo keep a pointer to its predicate; NFC
authorSanjoy Das <sanjoy@playingwithpointers.com>
Sun, 25 Sep 2016 23:12:04 +0000 (23:12 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Sun, 25 Sep 2016 23:12:04 +0000 (23:12 +0000)
SCEVUnionPredicate is a "heavyweight" structure, so it is beneficial to
store the (optional) data out of line.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282366 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/ScalarEvolution.h
lib/Analysis/ScalarEvolution.cpp

index 0c615d150eb2de2a4d84299e6ebb5a0ac7ac8372..64c0378ec6f3f26626f8ef0927a12f06190f9db0 100644 (file)
@@ -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
index 32ef53f4c9c9ea55181a3a5d23c828602e82cc83..a5b1be08df6690fb639d0054a029925813b13ad7 100644 (file)
@@ -5442,7 +5442,7 @@ ScalarEvolution::getPredicatedBackedgeTakenInfo(const Loop *L) {
   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(const Loop *L) {
   // 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::getExact(ScalarEvolution *SE,
       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::BackedgeTakenInfo(
     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.