[llvm] 2d0fc3e - [SCEV] Return ArrayRef from getSCEVValues() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 25 00:32:30 PST 2022


Author: Nikita Popov
Date: 2022-02-25T09:32:22+01:00
New Revision: 2d0fc3e46ff386a05fa388874b8456bf61c4ce7a

URL: https://github.com/llvm/llvm-project/commit/2d0fc3e46ff386a05fa388874b8456bf61c4ce7a
DIFF: https://github.com/llvm/llvm-project/commit/2d0fc3e46ff386a05fa388874b8456bf61c4ce7a.diff

LOG: [SCEV] Return ArrayRef from getSCEVValues() (NFC)

Return a read-only view on this set. For the one internal use,
directly access ExprValueMap.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ScalarEvolution.h
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 61659bfbd126d..ddd4f6a3b8af8 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1281,7 +1281,7 @@ class ScalarEvolution {
   DenseMap<const SCEV *, uint32_t> MinTrailingZerosCache;
 
   /// Return the Value set from which the SCEV expr is generated.
-  ValueSetVector *getSCEVValues(const SCEV *S);
+  ArrayRef<Value *> getSCEVValues(const SCEV *S);
 
   /// Private helper method for the GetMinTrailingZeros method
   uint32_t GetMinTrailingZerosImpl(const SCEV *S);

diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 05ee7da886090..aa7f124ce4d30 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4280,11 +4280,10 @@ bool ScalarEvolution::containsAddRecurrence(const SCEV *S) {
 
 /// Return the ValueOffsetPair set for \p S. \p S can be represented
 /// by the value and offset from any ValueOffsetPair in the set.
-ScalarEvolution::ValueSetVector *
-ScalarEvolution::getSCEVValues(const SCEV *S) {
+ArrayRef<Value *> ScalarEvolution::getSCEVValues(const SCEV *S) {
   ExprValueMapType::iterator SI = ExprValueMap.find_as(S);
   if (SI == ExprValueMap.end())
-    return nullptr;
+    return None;
 #ifndef NDEBUG
   if (VerifySCEVMap) {
     // Check there is no dangling Value in the set returned.
@@ -4292,7 +4291,7 @@ ScalarEvolution::getSCEVValues(const SCEV *S) {
       assert(ValueExprMap.count(V));
   }
 #endif
-  return &SI->second;
+  return SI->second.getArrayRef();
 }
 
 /// Erase Value from ValueExprMap and ExprValueMap. ValueExprMap.erase(V)
@@ -4301,11 +4300,11 @@ ScalarEvolution::getSCEVValues(const SCEV *S) {
 void ScalarEvolution::eraseValueFromMap(Value *V) {
   ValueExprMapType::iterator I = ValueExprMap.find_as(V);
   if (I != ValueExprMap.end()) {
-    const SCEV *S = I->second;
-    // Remove V from the set of ExprValueMap[S]
-    if (auto *SV = getSCEVValues(S))
-      SV->remove(V);
-    ValueExprMap.erase(V);
+    auto EVIt = ExprValueMap.find(I->second);
+    bool Removed = EVIt->second.remove(V);
+    (void) Removed;
+    assert(Removed && "Value not in ExprValueMap?");
+    ValueExprMap.erase(I);
   }
 }
 

diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 00c5b5053f9e3..327d15d1b90db 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1872,17 +1872,17 @@ Value *SCEVExpander::expandCodeForImpl(const SCEV *SH, Type *Ty, bool Root) {
 
 Value *SCEVExpander::FindValueInExprValueMap(const SCEV *S,
                                              const Instruction *InsertPt) {
-  auto *Set = SE.getSCEVValues(S);
+  ArrayRef<Value *> Set = SE.getSCEVValues(S);
   // If the expansion is not in CanonicalMode, and the SCEV contains any
   // sub scAddRecExpr type SCEV, it is required to expand the SCEV literally.
   if (CanonicalMode || !SE.containsAddRecurrence(S)) {
     // If S is scConstant, it may be worse to reuse an existing Value.
-    if (S->getSCEVType() != scConstant && Set) {
+    if (S->getSCEVType() != scConstant) {
       // Choose a Value from the set which dominates the InsertPt.
       // InsertPt should be inside the Value's parent loop so as not to break
       // the LCSSA form.
-      for (Value *V : *Set) {
-        Instruction *EntInst = dyn_cast_or_null<Instruction>(V);
+      for (Value *V : Set) {
+        Instruction *EntInst = dyn_cast<Instruction>(V);
         if (!EntInst)
           continue;
 


        


More information about the llvm-commits mailing list