Skip to content

Commit 59a3b41

Browse files
[ADT] Deprecate DenseMap::getOrInsertDefault (#107040)
This patch deprecates DenseMap::getOrInsertDefault in favor of DenseMap::operator[], which does the same thing, has been around longer, and is also a household name as part of std::map and std::unordered_map. Note that DenseMap provides several equivalent ways to insert or default-construct a key-value pair: - operator[Key] - try_emplace(Key).first->second - getOrInsertDefault(Key) - FindAndConstruct(Key).second
1 parent 2a9f93b commit 59a3b41

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,11 @@ class DiagnoseHLSLAvailability
11231123

11241124
// Helper methods for dealing with shader stage bitmap
11251125
void AddToScannedFunctions(const FunctionDecl *FD) {
1126-
unsigned &ScannedStages = ScannedDecls.getOrInsertDefault(FD);
1126+
unsigned &ScannedStages = ScannedDecls[FD];
11271127
ScannedStages |= CurrentShaderStageBit;
11281128
}
11291129

1130-
unsigned GetScannedStages(const FunctionDecl *FD) {
1131-
return ScannedDecls.getOrInsertDefault(FD);
1132-
}
1130+
unsigned GetScannedStages(const FunctionDecl *FD) { return ScannedDecls[FD]; }
11331131

11341132
bool WasAlreadyScannedInCurrentStage(const FunctionDecl *FD) {
11351133
return WasAlreadyScannedInCurrentStage(GetScannedStages(FD));

flang/lib/Optimizer/Transforms/AddAliasTags.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ void PassState::processFunctionScopes(mlir::func::FuncOp func) {
103103
if (scopeNames.contains(func))
104104
return;
105105

106-
auto &scopeMap = scopeNames.getOrInsertDefault(func);
107-
auto &scopeOps = sortedScopeOperations.getOrInsertDefault(func);
106+
auto &scopeMap = scopeNames[func];
107+
auto &scopeOps = sortedScopeOperations[func];
108108
func.walk([&](fir::DummyScopeOp op) { scopeOps.push_back(op); });
109109
llvm::stable_sort(scopeOps, [&](const fir::DummyScopeOp &op1,
110110
const fir::DummyScopeOp &op2) {

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ class DenseMapBase : public DebugEpochBase {
322322
/// Returns the value associated to the key in the map if it exists. If it
323323
/// does not exist, emplace a default value for the key and returns a
324324
/// reference to the newly created value.
325+
LLVM_DEPRECATED("Use operator[] instead", "[Key]")
325326
ValueT &getOrInsertDefault(KeyT &&Key) {
326327
return try_emplace(Key).first->second;
327328
}
328329

329330
/// Returns the value associated to the key in the map if it exists. If it
330331
/// does not exist, emplace a default value for the key and returns a
331332
/// reference to the newly created value.
333+
LLVM_DEPRECATED("Use operator[] instead", "[Key]")
332334
ValueT &getOrInsertDefault(const KeyT &Key) {
333335
return try_emplace(Key).first->second;
334336
}

mlir/lib/Transforms/SROA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
5757

5858
auto scheduleAsBlockingUse = [&](OpOperand &use) {
5959
SmallPtrSetImpl<OpOperand *> &blockingUses =
60-
info.userToBlockingUses.getOrInsertDefault(use.getOwner());
60+
info.userToBlockingUses[use.getOwner()];
6161
blockingUses.insert(&use);
6262
};
6363

@@ -122,7 +122,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
122122
assert(llvm::is_contained(user->getResults(), blockingUse->get()));
123123

124124
SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
125-
info.userToBlockingUses.getOrInsertDefault(blockingUse->getOwner());
125+
info.userToBlockingUses[blockingUse->getOwner()];
126126
newUserBlockingUseSet.insert(blockingUse);
127127
}
128128
}

0 commit comments

Comments
 (0)