-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ADT] Deprecate DenseMap::getOrInsertDefault #107040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADT] Deprecate DenseMap::getOrInsertDefault #107040
Conversation
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
@llvm/pr-subscribers-llvm-adt @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesThis patch deprecates DenseMap::getOrInsertDefault in favor of Note that DenseMap provides several equivalent ways to insert or
Full diff: https://github.com/llvm/llvm-project/pull/107040.diff 4 Files Affected:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 83e612c6751644..fabc6f32906b10 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1123,13 +1123,11 @@ class DiagnoseHLSLAvailability
// Helper methods for dealing with shader stage bitmap
void AddToScannedFunctions(const FunctionDecl *FD) {
- unsigned &ScannedStages = ScannedDecls.getOrInsertDefault(FD);
+ unsigned &ScannedStages = ScannedDecls[FD];
ScannedStages |= CurrentShaderStageBit;
}
- unsigned GetScannedStages(const FunctionDecl *FD) {
- return ScannedDecls.getOrInsertDefault(FD);
- }
+ unsigned GetScannedStages(const FunctionDecl *FD) { return ScannedDecls[FD]; }
bool WasAlreadyScannedInCurrentStage(const FunctionDecl *FD) {
return WasAlreadyScannedInCurrentStage(GetScannedStages(FD));
diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
index c68df45afce13a..8feba072cfea67 100644
--- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
+++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
@@ -103,8 +103,8 @@ void PassState::processFunctionScopes(mlir::func::FuncOp func) {
if (scopeNames.contains(func))
return;
- auto &scopeMap = scopeNames.getOrInsertDefault(func);
- auto &scopeOps = sortedScopeOperations.getOrInsertDefault(func);
+ auto &scopeMap = scopeNames[func];
+ auto &scopeOps = sortedScopeOperations[func];
func.walk([&](fir::DummyScopeOp op) { scopeOps.push_back(op); });
llvm::stable_sort(scopeOps, [&](const fir::DummyScopeOp &op1,
const fir::DummyScopeOp &op2) {
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index f71cd5b4771b75..e78700f9a9f3ac 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -322,6 +322,7 @@ class DenseMapBase : public DebugEpochBase {
/// Returns the value associated to the key in the map if it exists. If it
/// does not exist, emplace a default value for the key and returns a
/// reference to the newly created value.
+ LLVM_DEPRECATED("Use operator[] instead", "[Key]")
ValueT &getOrInsertDefault(KeyT &&Key) {
return try_emplace(Key).first->second;
}
@@ -329,6 +330,7 @@ class DenseMapBase : public DebugEpochBase {
/// Returns the value associated to the key in the map if it exists. If it
/// does not exist, emplace a default value for the key and returns a
/// reference to the newly created value.
+ LLVM_DEPRECATED("Use operator[] instead", "[Key]")
ValueT &getOrInsertDefault(const KeyT &Key) {
return try_emplace(Key).first->second;
}
diff --git a/mlir/lib/Transforms/SROA.cpp b/mlir/lib/Transforms/SROA.cpp
index dc902cc63e0b55..aca252b01dce7b 100644
--- a/mlir/lib/Transforms/SROA.cpp
+++ b/mlir/lib/Transforms/SROA.cpp
@@ -57,7 +57,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
auto scheduleAsBlockingUse = [&](OpOperand &use) {
SmallPtrSetImpl<OpOperand *> &blockingUses =
- info.userToBlockingUses.getOrInsertDefault(use.getOwner());
+ info.userToBlockingUses[use.getOwner()];
blockingUses.insert(&use);
};
@@ -122,7 +122,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
assert(llvm::is_contained(user->getResults(), blockingUse->get()));
SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
- info.userToBlockingUses.getOrInsertDefault(blockingUse->getOwner());
+ info.userToBlockingUses[blockingUse->getOwner()];
newUserBlockingUseSet.insert(blockingUse);
}
}
|
@llvm/pr-subscribers-mlir Author: Kazu Hirata (kazutakahirata) ChangesThis patch deprecates DenseMap::getOrInsertDefault in favor of Note that DenseMap provides several equivalent ways to insert or
Full diff: https://github.com/llvm/llvm-project/pull/107040.diff 4 Files Affected:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 83e612c6751644..fabc6f32906b10 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1123,13 +1123,11 @@ class DiagnoseHLSLAvailability
// Helper methods for dealing with shader stage bitmap
void AddToScannedFunctions(const FunctionDecl *FD) {
- unsigned &ScannedStages = ScannedDecls.getOrInsertDefault(FD);
+ unsigned &ScannedStages = ScannedDecls[FD];
ScannedStages |= CurrentShaderStageBit;
}
- unsigned GetScannedStages(const FunctionDecl *FD) {
- return ScannedDecls.getOrInsertDefault(FD);
- }
+ unsigned GetScannedStages(const FunctionDecl *FD) { return ScannedDecls[FD]; }
bool WasAlreadyScannedInCurrentStage(const FunctionDecl *FD) {
return WasAlreadyScannedInCurrentStage(GetScannedStages(FD));
diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
index c68df45afce13a..8feba072cfea67 100644
--- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
+++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
@@ -103,8 +103,8 @@ void PassState::processFunctionScopes(mlir::func::FuncOp func) {
if (scopeNames.contains(func))
return;
- auto &scopeMap = scopeNames.getOrInsertDefault(func);
- auto &scopeOps = sortedScopeOperations.getOrInsertDefault(func);
+ auto &scopeMap = scopeNames[func];
+ auto &scopeOps = sortedScopeOperations[func];
func.walk([&](fir::DummyScopeOp op) { scopeOps.push_back(op); });
llvm::stable_sort(scopeOps, [&](const fir::DummyScopeOp &op1,
const fir::DummyScopeOp &op2) {
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index f71cd5b4771b75..e78700f9a9f3ac 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -322,6 +322,7 @@ class DenseMapBase : public DebugEpochBase {
/// Returns the value associated to the key in the map if it exists. If it
/// does not exist, emplace a default value for the key and returns a
/// reference to the newly created value.
+ LLVM_DEPRECATED("Use operator[] instead", "[Key]")
ValueT &getOrInsertDefault(KeyT &&Key) {
return try_emplace(Key).first->second;
}
@@ -329,6 +330,7 @@ class DenseMapBase : public DebugEpochBase {
/// Returns the value associated to the key in the map if it exists. If it
/// does not exist, emplace a default value for the key and returns a
/// reference to the newly created value.
+ LLVM_DEPRECATED("Use operator[] instead", "[Key]")
ValueT &getOrInsertDefault(const KeyT &Key) {
return try_emplace(Key).first->second;
}
diff --git a/mlir/lib/Transforms/SROA.cpp b/mlir/lib/Transforms/SROA.cpp
index dc902cc63e0b55..aca252b01dce7b 100644
--- a/mlir/lib/Transforms/SROA.cpp
+++ b/mlir/lib/Transforms/SROA.cpp
@@ -57,7 +57,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
auto scheduleAsBlockingUse = [&](OpOperand &use) {
SmallPtrSetImpl<OpOperand *> &blockingUses =
- info.userToBlockingUses.getOrInsertDefault(use.getOwner());
+ info.userToBlockingUses[use.getOwner()];
blockingUses.insert(&use);
};
@@ -122,7 +122,7 @@ computeDestructuringInfo(DestructurableMemorySlot &slot,
assert(llvm::is_contained(user->getResults(), blockingUse->get()));
SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
- info.userToBlockingUses.getOrInsertDefault(blockingUse->getOwner());
+ info.userToBlockingUses[blockingUse->getOwner()];
newUserBlockingUseSet.insert(blockingUse);
}
}
|
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: