Author: Fangrui Song
Date: 2026-09-08T04:09:29Z
New Revision: 62397f8b3c3986f54187ce08f00b3448ea1f8880

URL: 
https://github.com/llvm/llvm-project/commit/62397f8b3c3986f54187ce08f00b3448ea1f8880
DIFF: 
https://github.com/llvm/llvm-project/commit/62397f8b3c3986f54187ce08f00b3448ea1f8880.diff

LOG: Iterate DenseMaps with auto and structured bindings. NFC (#221869)

Avoid naming `std::pair` directly. The DenseMap bucket is subject to
change (#221853).

Added: 
    

Modified: 
    clang/lib/Sema/SemaAttr.cpp
    llvm/lib/Bitcode/Reader/MetadataLoader.cpp
    llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/lib/CodeGen/RegisterUsageInfo.cpp
    llvm/lib/CodeGen/StackColoring.cpp
    llvm/lib/MC/StringTableBuilder.cpp
    llvm/lib/MCA/HardwareUnits/LSUnit.cpp
    llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
    llvm/lib/Transforms/IPO/SampleProfile.cpp
    llvm/lib/Transforms/Scalar/GVNHoist.cpp
    llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
    llvm/lib/Transforms/Utils/Local.cpp
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
    mlir/lib/IR/PDL/PDLPatternMatch.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 67573c9f1c72a..35d14a4444595 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -1074,7 +1074,7 @@ void Sema::ActOnPragmaAttributeAttribute(
     //    variable(is_parameter).
     //  - a sub-rule and a sibling that's negated. E.g.
     //    variable(is_thread_local) and variable(unless(is_parameter))
-    llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
+    llvm::SmallDenseMap<int, attr::ParsedSubjectMatchRuleSet::value_type, 2>
         RulesToFirstSpecifiedNegatedSubRule;
     for (const auto &Rule : Rules) {
       attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);

diff  --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp 
b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index f4ebfce24b016..6f1fbd627edbc 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -241,8 +241,8 @@ void BitcodeReaderMetadataList::tryToResolveCycles() {
     return;
 
   // Give up on finding a full definition for any forward decls that remain.
-  for (const auto &Ref : OldTypeRefs.FwdDecls)
-    OldTypeRefs.Final.insert(Ref);
+  for (const auto &[UUID, CT] : OldTypeRefs.FwdDecls)
+    OldTypeRefs.Final.try_emplace(UUID, CT);
   OldTypeRefs.FwdDecls.clear();
 
   // Upgrade from old type ref arrays.  In strange cases, this could add to

diff  --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 859e073b91cc5..e33b6e0050318 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -579,12 +579,12 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
   void forEachSummary(Functor Callback) {
     if (ModuleToSummariesForIndex) {
       for (auto &M : *ModuleToSummariesForIndex)
-        for (auto &Summary : M.second) {
-          Callback(Summary, false);
+        for (auto &[GUID, GVS] : M.second) {
+          Callback({GUID, GVS}, false);
           // Ensure aliasee is handled, e.g. for assigning a valueId,
           // even if we are not importing the aliasee directly (the
           // imported alias will contain a copy of aliasee).
-          if (auto *AS = dyn_cast<AliasSummary>(Summary.getSecond()))
+          if (auto *AS = dyn_cast<AliasSummary>(GVS))
             Callback({AS->getAliaseeGUID(), &AS->getAliasee()}, true);
         }
     } else {

diff  --git a/llvm/lib/CodeGen/RegisterUsageInfo.cpp 
b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
index 38e4c30ceb634..d139bd430fb20 100644
--- a/llvm/lib/CodeGen/RegisterUsageInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
@@ -70,7 +70,7 @@ PhysicalRegisterUsageInfo::getRegUsageInfo(const Function 
&FP) {
 }
 
 void PhysicalRegisterUsageInfo::print(raw_ostream &OS, const Module *M) const {
-  using FuncPtrRegMaskPair = std::pair<const Function *, 
std::vector<uint32_t>>;
+  using FuncPtrRegMaskPair = decltype(RegMasks)::value_type;
 
   // Create a vector of pointer to RegMasks entries
   SmallVector<const FuncPtrRegMaskPair *, 64> FPRMPairVector(

diff  --git a/llvm/lib/CodeGen/StackColoring.cpp 
b/llvm/lib/CodeGen/StackColoring.cpp
index aa42c0ee28532..0e4c1526d0d0b 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -927,7 +927,7 @@ void StackColoring::remapInstructions(DenseMap<int, int> 
&SlotRemap) {
   // Keep a list of allocas which has been affected by the remap.
   SmallPtrSet<const AllocaInst*, 32> MergedAllocas;
 
-  for (const std::pair<int, int> &SI : SlotRemap) {
+  for (const auto &SI : SlotRemap) {
     const AllocaInst *From = MFI->getObjectAllocation(SI.first);
     const AllocaInst *To = MFI->getObjectAllocation(SI.second);
     assert(To && From && "Invalid allocation object");

diff  --git a/llvm/lib/MC/StringTableBuilder.cpp 
b/llvm/lib/MC/StringTableBuilder.cpp
index eb1a62f1f6412..39d10ad128ed7 100644
--- a/llvm/lib/MC/StringTableBuilder.cpp
+++ b/llvm/lib/MC/StringTableBuilder.cpp
@@ -66,7 +66,7 @@ void StringTableBuilder::write(raw_ostream &OS) const {
   OS << Data;
 }
 
-using StringPair = std::pair<CachedHashStringRef, size_t>;
+using StringPair = DenseMap<CachedHashStringRef, size_t>::value_type;
 
 void StringTableBuilder::write(uint8_t *Buf) const {
   assert(isFinalized());

diff  --git a/llvm/lib/MCA/HardwareUnits/LSUnit.cpp 
b/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
index bf0b432524881..f88f82a7f5279 100644
--- a/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
+++ b/llvm/lib/MCA/HardwareUnits/LSUnit.cpp
@@ -42,7 +42,7 @@ LSUnitBase::LSUnitBase(const MCSchedModel &SM, unsigned LQ, 
unsigned SQ,
 LSUnitBase::~LSUnitBase() = default;
 
 void LSUnit::cycleEvent() {
-  for (const std::pair<unsigned, std::unique_ptr<MemoryGroup>> &G : Groups)
+  for (const auto &G : Groups)
     G.second->cycleEvent();
 }
 

diff  --git a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp 
b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
index cdf3439e07d61..12d062ab6ff9f 100644
--- a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
+++ b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
@@ -473,7 +473,7 @@ void ResourceManager::fastIssueInstruction(
 }
 
 void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) 
{
-  for (std::pair<ResourceRef, unsigned> &BR : BusyResources) {
+  for (auto &BR : BusyResources) {
     if (BR.second)
       BR.second--;
     if (!BR.second) {

diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp 
b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index cb11372183bc8..cd9549cd2f0cc 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -2205,9 +2205,8 @@ bool SampleProfileLoader::runOnModule(Module &M, 
ModuleAnalysisManager &AM,
 
   // Account for cold calls not inlined....
   if (!FunctionSamples::ProfileIsCS)
-    for (const std::pair<Function *, NotInlinedProfileInfo> &pair :
-         notInlinedCallInfo)
-      updateProfileCallee(pair.first, pair.second.entryCount);
+    for (const auto &[Fn, Info] : notInlinedCallInfo)
+      updateProfileCallee(Fn, Info.entryCount);
 
   if (RemoveProbeAfterProfileAnnotation &&
       FunctionSamples::ProfileIsProbeBased) {

diff  --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp 
b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 37562a024a2b0..6bb6d6772fbfb 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -835,7 +835,7 @@ void GVNHoist::findHoistableCandidates(OutValuesType 
&CHIBBs,
 
   // CHIArgs now have the outgoing values, so check for anticipability and
   // accumulate hoistable candidates in HPL.
-  for (std::pair<BasicBlock *, SmallVector<CHIArg, 2>> &A : CHIBBs) {
+  for (auto &A : CHIBBs) {
     BasicBlock *BB = A.first;
     SmallVectorImpl<CHIArg> &CHIs = A.second;
     // Vector of PHIs contains PHIs for 
diff erent instructions.

diff  --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp 
b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
index 9707eee005c56..9b9889b911eee 100644
--- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -1135,9 +1135,8 @@ void StructurizeCFG::setPrevNode(BasicBlock *BB) {
 /// Does BB dominate all the predicates of Node?
 bool StructurizeCFG::dominatesPredicates(BasicBlock *BB, RegionNode *Node) {
   BBPredicates &Preds = Predicates[Node->getEntry()];
-  return llvm::all_of(Preds, [&](std::pair<BasicBlock *, PredInfo> Pred) {
-    return DT->dominates(BB, Pred.first);
-  });
+  return llvm::all_of(
+      Preds, [&](const auto &Pred) { return DT->dominates(BB, Pred.first); });
 }
 
 /// Can we predict that this node will always be called?

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp 
b/llvm/lib/Transforms/Utils/Local.cpp
index b88e506ae681a..f08f1e4868091 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2852,7 +2852,7 @@ static bool markAliveBlocks(Function &F, 
SmallVectorImpl<bool> &Reachable,
         }
         if (DTU) {
           std::vector<DominatorTree::UpdateType> Updates;
-          for (const std::pair<BasicBlock *, int> &I : NumPerSuccessorCases)
+          for (const auto &I : NumPerSuccessorCases)
             if (I.second == 0)
               Updates.push_back({DominatorTree::Delete, BB, I.first});
           DTU->applyUpdates(Updates);

diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index cc2c769b25ce9..ca96f2e70d810 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1053,7 +1053,7 @@ bool 
SimplifyCFGOpt::simplifyEqualityComparisonWithOnlyPredecessor(
 
     if (DTU) {
       std::vector<DominatorTree::UpdateType> Updates;
-      for (const std::pair<BasicBlock *, int> &I : NumPerSuccessorCases)
+      for (const auto &I : NumPerSuccessorCases)
         if (I.second == 0)
           Updates.push_back({DominatorTree::Delete, PredDef, I.first});
       DTU->applyUpdates(Updates);

diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp 
b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5de71f3bf87b5..323442be1c8a7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4480,9 +4480,7 @@ class slpvectorizer::BoUpSLP {
         } while (It != P.first->Scalars.end());
       }
       return all_of(PotentiallyReorderedEntriesCount,
-                    [&](const std::pair<const TreeEntry *, unsigned> &P) {
-                      return P.second == NumOps - 1;
-                    });
+                    [&](const auto &P) { return P.second == NumOps - 1; });
     }
 
     SmallVector<ScheduleCopyableData *>
@@ -11634,9 +11632,7 @@ class InstructionsCompatibilityAnalysis {
           ++Counters[V];
         }
         if (Counters.size() == 2 &&
-            any_of(Counters, [&](const std::pair<const Value *, unsigned> &C) {
-              return C.second == 1;
-            }))
+            any_of(Counters, [&](const auto &C) { return C.second == 1; }))
           return true;
       }
       // First operand not a constant or splat? Last attempt - check for

diff  --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp 
b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
index 370457c85e797..796083062ac72 100644
--- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
+++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
@@ -760,9 +760,8 @@ ParallelToGpuLaunchLowering::matchAndRewrite(ParallelOp 
parallelOp,
 
   // Now that we succeeded creating the launch operation, also update the
   // bounds.
-  for (auto bound : launchBounds)
-    launchOp.setOperand(getLaunchOpArgumentNum(std::get<0>(bound)),
-                        std::get<1>(bound));
+  for (const auto &[processor, bound] : launchBounds)
+    launchOp.setOperand(getLaunchOpArgumentNum(processor), bound);
 
   rewriter.eraseOp(parallelOp);
   return success();

diff  --git a/mlir/lib/IR/PDL/PDLPatternMatch.cpp 
b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
index 62a71aa2c1daa..ceaced2610b6e 100644
--- a/mlir/lib/IR/PDL/PDLPatternMatch.cpp
+++ b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
@@ -82,8 +82,7 @@ void PDLPatternModule::mergeIn(PDLPatternModule &&other) {
     registerRewriteFunction(it.first(), std::move(it.second));
   for (auto &it : other.configs)
     configs.emplace_back(std::move(it));
-  for (auto &it : other.configMap)
-    configMap.insert(it);
+  configMap.insert_range(other.configMap);
 
   // Steal the other state if we have no patterns.
   if (!pdlModule) {


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to