[Mlir-commits] [mlir] 59a3b41 - [ADT] Deprecate DenseMap::getOrInsertDefault (#107040)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Sep 3 08:19:52 PDT 2024
Author: Kazu Hirata
Date: 2024-09-03T08:19:45-07:00
New Revision: 59a3b4156836c3ea8589d7a39e7b4712fc8698ec
URL: https://github.com/llvm/llvm-project/commit/59a3b4156836c3ea8589d7a39e7b4712fc8698ec
DIFF: https://github.com/llvm/llvm-project/commit/59a3b4156836c3ea8589d7a39e7b4712fc8698ec.diff
LOG: [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
Added:
Modified:
clang/lib/Sema/SemaHLSL.cpp
flang/lib/Optimizer/Transforms/AddAliasTags.cpp
llvm/include/llvm/ADT/DenseMap.h
mlir/lib/Transforms/SROA.cpp
Removed:
################################################################################
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);
}
}
More information about the Mlir-commits
mailing list