Skip to content

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-mlir-affine

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/111330.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Analysis/Utils.cpp (+3-3)
diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index 194ee9115e3d7a..29608647d85746 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -1927,9 +1927,9 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
       return opInst->emitError("error obtaining memory region\n");
     }
 
-    auto it = regions.find(region->memref);
-    if (it == regions.end()) {
-      regions[region->memref] = std::move(region);
+    auto [it, inserted] = regions.try_emplace(region->memref);
+    if (inserted) {
+      it->second = std::move(region);
     } else if (failed(it->second->unionBoundingBox(*region))) {
       return opInst->emitWarning(
           "getMemoryFootprintBytes: unable to perform a union on a memory "

@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/111330.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Analysis/Utils.cpp (+3-3)
diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index 194ee9115e3d7a..29608647d85746 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -1927,9 +1927,9 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
       return opInst->emitError("error obtaining memory region\n");
     }
 
-    auto it = regions.find(region->memref);
-    if (it == regions.end()) {
-      regions[region->memref] = std::move(region);
+    auto [it, inserted] = regions.try_emplace(region->memref);
+    if (inserted) {
+      it->second = std::move(region);
     } else if (failed(it->second->unionBoundingBox(*region))) {
       return opInst->emitWarning(
           "getMemoryFootprintBytes: unable to perform a union on a memory "

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

regions[region->memref] = std::move(region);
auto [it, inserted] = regions.try_emplace(region->memref);
if (inserted) {
it->second = std::move(region);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you could also do the std::move in try_emplace (because it will only actually get moved if inserted), but it's probably more confusing than this variant...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's safe but confusing. Personally, when I see std::move, I don't want to see any use until the end of the scope.

@kazutakahirata kazutakahirata merged commit 31e8c53 into llvm:main Oct 7, 2024
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_Utils branch October 7, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants