[llvm] [Scalar] Simplify code with *Map::operator[] (NFC) (PR #112120)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 21:14:08 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112120

None

>From e5fa05157305c6f1f79401f19d8749e90be2a4c6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 7 Oct 2024 07:33:04 -0700
Subject: [PATCH] [Scalar] Simplify code with *Map::operator[] (NFC)

---
 llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp     |  6 ++----
 llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp | 11 ++++-------
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp b/llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp
index 5d9a7bca7efeca..7f9129697995a0 100644
--- a/llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp
+++ b/llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp
@@ -52,8 +52,7 @@ static void runImpl(Function &F, const TargetLibraryInfo &TLI) {
   for (Instruction &I : instructions(F)) {
     if (!I.hasMetadata(LLVMContext::MD_annotation))
       continue;
-    auto Iter = DebugLoc2Annotated.insert({I.getDebugLoc().getAsMDNode(), {}});
-    Iter.first->second.push_back(&I);
+    DebugLoc2Annotated[I.getDebugLoc().getAsMDNode()].push_back(&I);
 
     for (const MDOperand &Op :
          I.getMetadata(LLVMContext::MD_annotation)->operands()) {
@@ -62,8 +61,7 @@ static void runImpl(Function &F, const TargetLibraryInfo &TLI) {
               ? cast<MDString>(Op.get())->getString()
               : cast<MDString>(cast<MDTuple>(Op.get())->getOperand(0).get())
                     ->getString();
-      auto Iter = Mapping.insert({AnnotationStr, 0});
-      Iter.first->second++;
+      Mapping[AnnotationStr]++;
     }
   }
 
diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index a4ab288b1bfee8..f2ea9f8faf84cd 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -2486,8 +2486,7 @@ class LowerMatrixIntrinsics {
       if (!ExprsInSubprogram.count(V))
         return;
 
-      auto I = Shared.insert({V, {}});
-      I.first->second.insert(Leaf);
+      Shared[V].insert(Leaf);
 
       for (Value *Op : cast<Instruction>(V)->operand_values())
         collectSharedInfo(Leaf, Op, ExprsInSubprogram, Shared);
@@ -2538,14 +2537,12 @@ class LowerMatrixIntrinsics {
           auto *I = cast<Instruction>(KV.first);
           DILocation *Context = I->getDebugLoc();
           while (Context) {
-            auto I =
-                Subprog2Exprs.insert({getSubprogram(Context->getScope()), {}});
-            I.first->second.push_back(KV.first);
+            Subprog2Exprs[getSubprogram(Context->getScope())].push_back(
+                KV.first);
             Context = DebugLoc(Context).getInlinedAt();
           }
         } else {
-          auto I = Subprog2Exprs.insert({nullptr, {}});
-          I.first->second.push_back(KV.first);
+          Subprog2Exprs[nullptr].push_back(KV.first);
         }
       }
       for (auto &KV : Subprog2Exprs) {



More information about the llvm-commits mailing list