Skip to content

Commit

Permalink
[SCEV] Return ArrayRef from getSCEVValues() (NFC)
Browse files Browse the repository at this point in the history
Return a read-only view on this set. For the one internal use,
directly access ExprValueMap.
  • Loading branch information
nikic committed Feb 25, 2022
1 parent 51fdd80 commit 2d0fc3e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/ScalarEvolution.h
Expand Up @@ -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);
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -4280,19 +4280,18 @@ 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.
for (Value *V : SI->second)
assert(ValueExprMap.count(V));
}
#endif
return &SI->second;
return SI->second.getArrayRef();
}

/// Erase Value from ValueExprMap and ExprValueMap. ValueExprMap.erase(V)
Expand All @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit 2d0fc3e

Please sign in to comment.