[flang-commits] [clang] [flang] [llvm] [mlir] [ADT] Deprecate DenseMap::getOrInsertDefault (PR #107040)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 2 19:38:02 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/107040.diff
4 Files Affected:
- (modified) clang/lib/Sema/SemaHLSL.cpp (+2-4)
- (modified) flang/lib/Optimizer/Transforms/AddAliasTags.cpp (+2-2)
- (modified) llvm/include/llvm/ADT/DenseMap.h (+2)
- (modified) mlir/lib/Transforms/SROA.cpp (+2-2)
``````````diff
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);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107040
More information about the flang-commits
mailing list