Skip to content

Commit c431106

Browse files
committed
Make additional data structures optionals
1 parent f9da56f commit c431106

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ using NonNullPointerSet = SmallDenseSet<AssertingVH<Value>, 2>;
111111
using BBLatticeElementMap =
112112
SmallDenseMap<PoisoningVH<BasicBlock>, ValueLatticeElement, 4>;
113113
using PredecessorValueLatticeMap =
114-
SmallDenseMap<AssertingVH<Value>, BBLatticeElementMap, 4>;
114+
SmallDenseMap<AssertingVH<Value>, BBLatticeElementMap, 2>;
115115

116116
/// This is the cache kept by LazyValueInfo which
117117
/// maintains information about queries across the clients' queries.
@@ -129,7 +129,7 @@ class LazyValueInfoCache {
129129
// This is an extension of the above LatticeElements, caching, for each
130130
// Value, a ValueLatticeElement, for each predecessor of the BB tracked by
131131
// this entry.
132-
PredecessorValueLatticeMap PredecessorLatticeElements;
132+
std::optional<PredecessorValueLatticeMap> PredecessorLatticeElements;
133133
};
134134

135135
/// Cached information per basic block.
@@ -147,8 +147,14 @@ class LazyValueInfoCache {
147147

148148
BlockCacheEntry *getOrCreateBlockEntry(BasicBlock *BB) {
149149
auto It = BlockCache.find_as(BB);
150-
if (It == BlockCache.end())
151-
It = BlockCache.insert({BB, std::make_unique<BlockCacheEntry>()}).first;
150+
if (It == BlockCache.end()) {
151+
std::unique_ptr<BlockCacheEntry> BCE =
152+
std::make_unique<BlockCacheEntry>();
153+
if (PerPredRanges)
154+
BCE->PredecessorLatticeElements =
155+
std::make_optional<PredecessorValueLatticeMap>();
156+
It = BlockCache.insert({BB, std::move(BCE)}).first;
157+
}
152158

153159
return It->second.get();
154160
}
@@ -178,7 +184,7 @@ class LazyValueInfoCache {
178184
BBLatticeElementMap &PredLatticeElements) {
179185
BlockCacheEntry *Entry = getOrCreateBlockEntry(BB);
180186

181-
Entry->PredecessorLatticeElements.insert({Val, PredLatticeElements});
187+
Entry->PredecessorLatticeElements->insert({Val, PredLatticeElements});
182188

183189
addValueHandle(Val);
184190
}
@@ -189,8 +195,8 @@ class LazyValueInfoCache {
189195
if (!Entry)
190196
return std::nullopt;
191197

192-
auto LatticeIt = Entry->PredecessorLatticeElements.find_as(V);
193-
if (LatticeIt == Entry->PredecessorLatticeElements.end())
198+
auto LatticeIt = Entry->PredecessorLatticeElements->find_as(V);
199+
if (LatticeIt == Entry->PredecessorLatticeElements->end())
194200
return std::nullopt;
195201

196202
return LatticeIt->second;
@@ -252,7 +258,7 @@ void LazyValueInfoCache::eraseValue(Value *V) {
252258
if (Pair.second->NonNullPointers)
253259
Pair.second->NonNullPointers->erase(V);
254260
if (PerPredRanges)
255-
Pair.second->PredecessorLatticeElements.erase(V);
261+
Pair.second->PredecessorLatticeElements->erase(V);
256262
}
257263

258264
auto HandleIt = ValueHandles.find_as(V);
@@ -270,7 +276,7 @@ void LazyValueInfoCache::eraseBlock(BasicBlock *BB) {
270276
// Clear all when a BB is removed.
271277
if (PerPredRanges)
272278
for (auto &Pair : BlockCache)
273-
Pair.second->PredecessorLatticeElements.clear();
279+
Pair.second->PredecessorLatticeElements->clear();
274280
BlockCache.erase(BB);
275281
}
276282

@@ -732,7 +738,9 @@ LazyValueInfoImpl::solveBlockValueNonLocal(Value *Val, BasicBlock *BB) {
732738
// find a path to function entry. TODO: We should consider explicitly
733739
// canonicalizing to make this true rather than relying on this happy
734740
// accident.
735-
BBLatticeElementMap PredLatticeElements;
741+
std::optional<BBLatticeElementMap> PredLatticeElements;
742+
if (PerPredRanges)
743+
PredLatticeElements = std::make_optional<BBLatticeElementMap>();
736744
for (BasicBlock *Pred : predecessors(BB)) {
737745
// Skip self loops.
738746
if (Pred == BB)
@@ -753,11 +761,11 @@ LazyValueInfoImpl::solveBlockValueNonLocal(Value *Val, BasicBlock *BB) {
753761
return Result;
754762
}
755763
if (PerPredRanges)
756-
PredLatticeElements.insert({Pred, *EdgeResult});
764+
PredLatticeElements->insert({Pred, *EdgeResult});
757765
}
758766

759767
if (PerPredRanges)
760-
TheCache.insertPredecessorResults(Val, BB, PredLatticeElements);
768+
TheCache.insertPredecessorResults(Val, BB, *PredLatticeElements);
761769

762770
// Return the merged value, which is more precise than 'overdefined'.
763771
assert(!Result.isOverdefined());
@@ -771,7 +779,9 @@ LazyValueInfoImpl::solveBlockValuePHINode(PHINode *PN, BasicBlock *BB) {
771779
// Loop over all of our predecessors, merging what we know from them into
772780
// result. See the comment about the chosen traversal order in
773781
// solveBlockValueNonLocal; the same reasoning applies here.
774-
BBLatticeElementMap PredLatticeElements;
782+
std::optional<BBLatticeElementMap> PredLatticeElements;
783+
if (PerPredRanges)
784+
PredLatticeElements = std::make_optional<BBLatticeElementMap>();
775785
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
776786
BasicBlock *PhiBB = PN->getIncomingBlock(i);
777787
Value *PhiVal = PN->getIncomingValue(i);
@@ -796,11 +806,11 @@ LazyValueInfoImpl::solveBlockValuePHINode(PHINode *PN, BasicBlock *BB) {
796806
}
797807

798808
if (PerPredRanges)
799-
PredLatticeElements.insert({PhiBB, *EdgeResult});
809+
PredLatticeElements->insert({PhiBB, *EdgeResult});
800810
}
801811

802812
if (PerPredRanges)
803-
TheCache.insertPredecessorResults(PN, BB, PredLatticeElements);
813+
TheCache.insertPredecessorResults(PN, BB, *PredLatticeElements);
804814

805815
// Return the merged value, which is more precise than 'overdefined'.
806816
assert(!Result.isOverdefined() && "Possible PHI in entry block?");

0 commit comments

Comments
 (0)