Use range-based for loops (NFC)
authorKazu Hirata <kazu@google.com>
Sun, 21 Aug 2022 04:18:32 +0000 (21:18 -0700)
committerKazu Hirata <kazu@google.com>
Sun, 21 Aug 2022 04:18:32 +0000 (21:18 -0700)
16 files changed:
clang/lib/AST/ASTContext.cpp
clang/lib/Driver/Compilation.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/TreeTransform.h
lldb/source/Utility/ArchSpec.cpp
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
llvm/lib/Support/ARMAttributeParser.cpp
llvm/lib/Support/CSKYAttributeParser.cpp
llvm/lib/Support/RISCVAttributeParser.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/tools/llvm-config/llvm-config.cpp

index 2c2f466..0786c1e 100644 (file)
@@ -7065,12 +7065,11 @@ QualType ASTContext::getPromotedIntegerType(QualType Promotable) const {
       uint64_t FromSize = getTypeSize(BT);
       QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy,
                                   LongLongTy, UnsignedLongLongTy };
-      for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) {
-        uint64_t ToSize = getTypeSize(PromoteTypes[Idx]);
+      for (const auto &PT : PromoteTypes) {
+        uint64_t ToSize = getTypeSize(PT);
         if (FromSize < ToSize ||
-            (FromSize == ToSize &&
-             FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType()))
-          return PromoteTypes[Idx];
+            (FromSize == ToSize && FromIsSigned == PT->isSignedIntegerType()))
+          return PT;
       }
       llvm_unreachable("char type should fit into long long");
     }
index b4367a0..ecf3da2 100644 (file)
@@ -283,9 +283,9 @@ void Compilation::initCompilationForDiagnostics() {
       options::OPT_o,  options::OPT_MD, options::OPT_MMD, options::OPT_M,
       options::OPT_MM, options::OPT_MF, options::OPT_MG,  options::OPT_MJ,
       options::OPT_MQ, options::OPT_MT, options::OPT_MV};
-  for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
-    if (TranslatedArgs->hasArg(OutputOpts[i]))
-      TranslatedArgs->eraseArg(OutputOpts[i]);
+  for (const auto &Opt : OutputOpts) {
+    if (TranslatedArgs->hasArg(Opt))
+      TranslatedArgs->eraseArg(Opt);
   }
   TranslatedArgs->ClaimAllArgs();
 
index bc86e5b..3434b5c 100644 (file)
@@ -185,11 +185,11 @@ static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
       {"clang-dxc", "--driver-mode=dxc"},
   };
 
-  for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i) {
-    StringRef Suffix(DriverSuffixes[i].Suffix);
+  for (const auto &DS : DriverSuffixes) {
+    StringRef Suffix(DS.Suffix);
     if (ProgName.endswith(Suffix)) {
       Pos = ProgName.size() - Suffix.size();
-      return &DriverSuffixes[i];
+      return &DS;
     }
   }
   return nullptr;
index 2421f8d..e0707c6 100644 (file)
@@ -198,8 +198,8 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) {
   if (DKind == OMPD_unknown)
     return OMPD_unknown;
 
-  for (unsigned I = 0; I < llvm::array_lengthof(F); ++I) {
-    if (DKind != F[I][0])
+  for (const auto &I : F) {
+    if (DKind != I[0])
       continue;
 
     Tok = P.getPreprocessor().LookAhead(0);
@@ -210,9 +210,9 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) {
     if (SDKind == OMPD_unknown)
       continue;
 
-    if (SDKind == F[I][1]) {
+    if (SDKind == I[1]) {
       P.ConsumeToken();
-      DKind = F[I][2];
+      DKind = I[2];
     }
   }
   return unsigned(DKind) < llvm::omp::Directive_enumSize
index d163ad3..1d8df94 100644 (file)
@@ -5023,9 +5023,8 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       "extern", "inline", "static", "typedef"
     };
 
-    const unsigned NumCTypeSpecs = llvm::array_lengthof(CTypeSpecs);
-    for (unsigned I = 0; I != NumCTypeSpecs; ++I)
-      Consumer.addKeywordResult(CTypeSpecs[I]);
+    for (const auto *CTS : CTypeSpecs)
+      Consumer.addKeywordResult(CTS);
 
     if (SemaRef.getLangOpts().C99)
       Consumer.addKeywordResult("restrict");
@@ -5077,9 +5076,8 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       static const char *const CXXExprs[] = {
         "delete", "new", "operator", "throw", "typeid"
       };
-      const unsigned NumCXXExprs = llvm::array_lengthof(CXXExprs);
-      for (unsigned I = 0; I != NumCXXExprs; ++I)
-        Consumer.addKeywordResult(CXXExprs[I]);
+      for (const auto *CE : CXXExprs)
+        Consumer.addKeywordResult(CE);
 
       if (isa<CXXMethodDecl>(SemaRef.CurContext) &&
           cast<CXXMethodDecl>(SemaRef.CurContext)->isInstance())
@@ -5103,9 +5101,8 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       // Statements.
       static const char *const CStmts[] = {
         "do", "else", "for", "goto", "if", "return", "switch", "while" };
-      const unsigned NumCStmts = llvm::array_lengthof(CStmts);
-      for (unsigned I = 0; I != NumCStmts; ++I)
-        Consumer.addKeywordResult(CStmts[I]);
+      for (const auto *CS : CStmts)
+        Consumer.addKeywordResult(CS);
 
       if (SemaRef.getLangOpts().CPlusPlus) {
         Consumer.addKeywordResult("catch");
index 142e00a..c5337de 100644 (file)
@@ -14536,11 +14536,10 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
     SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
     SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
   };
-  const unsigned NumTypes = llvm::array_lengthof(Types);
   QualType SizeType;
-  for (unsigned I = 0; I != NumTypes; ++I)
-    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
-      SizeType = Types[I];
+  for (const auto &T : Types)
+    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
+      SizeType = T;
       break;
     }
 
index 348a62d..1cc8ab7 100644 (file)
@@ -255,13 +255,13 @@ struct ArchDefinition {
 };
 
 void ArchSpec::ListSupportedArchNames(StringList &list) {
-  for (uint32_t i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
-    list.AppendString(g_core_definitions[i].name);
+  for (const auto &def : g_core_definitions)
+    list.AppendString(def.name);
 }
 
 void ArchSpec::AutoComplete(CompletionRequest &request) {
-  for (uint32_t i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
-    request.TryCompleteCurrentArg(g_core_definitions[i].name);
+  for (const auto &def : g_core_definitions)
+    request.TryCompleteCurrentArg(def.name);
 }
 
 #define CPU_ANY (UINT32_MAX)
@@ -446,16 +446,12 @@ static const ArchDefinition g_coff_arch_def = {
 static const ArchDefinition *g_arch_definitions[] = {
     &g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def};
 
-static const size_t k_num_arch_definitions =
-    llvm::array_lengthof(g_arch_definitions);
-
 //===----------------------------------------------------------------------===//
 // Static helper functions.
 
 // Get the architecture definition for a given object type.
 static const ArchDefinition *FindArchDefinition(ArchitectureType arch_type) {
-  for (unsigned int i = 0; i < k_num_arch_definitions; ++i) {
-    const ArchDefinition *def = g_arch_definitions[i];
+  for (const ArchDefinition *def : g_arch_definitions) {
     if (def->type == arch_type)
       return def;
   }
@@ -464,9 +460,9 @@ static const ArchDefinition *FindArchDefinition(ArchitectureType arch_type) {
 
 // Get an architecture definition by name.
 static const CoreDefinition *FindCoreDefinition(llvm::StringRef name) {
-  for (unsigned int i = 0; i < llvm::array_lengthof(g_core_definitions); ++i) {
-    if (name.equals_insensitive(g_core_definitions[i].name))
-      return &g_core_definitions[i];
+  for (const auto &def : g_core_definitions) {
+    if (name.equals_insensitive(def.name))
+      return &def;
   }
   return nullptr;
 }
index 5944dee..55f9851 100644 (file)
@@ -2579,11 +2579,11 @@ void DAGTypeLegalizer::SplitVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N,
                              NewElts](SmallVectorImpl<int> &Mask) {
     SetVector<SDValue> UniqueInputs;
     SetVector<SDValue> UniqueConstantInputs;
-    for (unsigned I = 0; I < array_lengthof(Inputs); ++I) {
-      if (IsConstant(Inputs[I]))
-        UniqueConstantInputs.insert(Inputs[I]);
-      else if (!Inputs[I].isUndef())
-        UniqueInputs.insert(Inputs[I]);
+    for (const auto &I : Inputs) {
+      if (IsConstant(I))
+        UniqueConstantInputs.insert(I);
+      else if (!I.isUndef())
+        UniqueInputs.insert(I);
     }
     // Adjust mask in case of reused inputs. Also, need to insert constant
     // inputs at first, otherwise it affects the final outcome.
index 69a969f..af79a58 100644 (file)
@@ -463,11 +463,9 @@ Error ARMAttributeParser::also_compatible_with(AttrType tag) {
 
 Error ARMAttributeParser::handler(uint64_t tag, bool &handled) {
   handled = false;
-  for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
-       ++AHI) {
-    if (uint64_t(displayRoutines[AHI].attribute) == tag) {
-      if (Error e =
-              (this->*displayRoutines[AHI].routine)(static_cast<AttrType>(tag)))
+  for (const auto &AH : displayRoutines) {
+    if (uint64_t(AH.attribute) == tag) {
+      if (Error e = (this->*AH.routine)(static_cast<AttrType>(tag)))
         return e;
       handled = true;
       break;
index ea1ac92..1310eed 100644 (file)
@@ -69,10 +69,9 @@ const CSKYAttributeParser::DisplayHandler
 
 Error CSKYAttributeParser::handler(uint64_t tag, bool &handled) {
   handled = false;
-  for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
-       ++AHI) {
-    if (uint64_t(displayRoutines[AHI].attribute) == tag) {
-      if (Error e = (this->*displayRoutines[AHI].routine)(tag))
+  for (const auto &AH : displayRoutines) {
+    if (uint64_t(AH.attribute) == tag) {
+      if (Error e = (this->*AH.routine)(tag))
         return e;
       handled = true;
       break;
index 393861c..b9fdfe0 100644 (file)
@@ -53,10 +53,9 @@ Error RISCVAttributeParser::stackAlign(unsigned tag) {
 
 Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) {
   handled = false;
-  for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
-       ++AHI) {
-    if (uint64_t(displayRoutines[AHI].attribute) == tag) {
-      if (Error e = (this->*displayRoutines[AHI].routine)(tag))
+  for (const auto &AH : displayRoutines) {
+    if (uint64_t(AH.attribute) == tag) {
+      if (Error e = (this->*AH.routine)(tag))
         return e;
       handled = true;
       break;
index 5d2ba7e..33869c4 100644 (file)
@@ -705,10 +705,9 @@ static const LdStNInstrDesc LdStNInstInfo[] = {
 };
 
 static const LdStNInstrDesc *getLdStNInstrDesc(unsigned Opcode) {
-  unsigned Idx;
-  for (Idx = 0; Idx != array_lengthof(LdStNInstInfo); ++Idx)
-    if (LdStNInstInfo[Idx].Opcode == Opcode)
-      return &LdStNInstInfo[Idx];
+  for (const auto &Info : LdStNInstInfo)
+    if (Info.Opcode == Opcode)
+      return &Info;
 
   return nullptr;
 }
index 92aa103..79fda24 100644 (file)
@@ -2468,9 +2468,9 @@ static const AddSubFlagsOpcodePair AddSubFlagsOpcodeMap[] = {
 };
 
 unsigned llvm::convertAddSubFlagsOpcode(unsigned OldOpc) {
-  for (unsigned i = 0, e = array_lengthof(AddSubFlagsOpcodeMap); i != e; ++i)
-    if (OldOpc == AddSubFlagsOpcodeMap[i].PseudoOpc)
-      return AddSubFlagsOpcodeMap[i].MachineOpc;
+  for (const auto &Entry : AddSubFlagsOpcodeMap)
+    if (OldOpc == Entry.PseudoOpc)
+      return Entry.MachineOpc;
   return 0;
 }
 
index d943507..9c06c46 100644 (file)
@@ -301,8 +301,8 @@ SystemZELFFrameLowering::SystemZELFFrameLowering()
   // Create a mapping from register number to save slot offset.
   // These offsets are relative to the start of the register save area.
   RegSpillOffsets.grow(SystemZ::NUM_TARGET_REGS);
-  for (unsigned I = 0, E = array_lengthof(ELFSpillOffsetTable); I != E; ++I)
-    RegSpillOffsets[ELFSpillOffsetTable[I].Reg] = ELFSpillOffsetTable[I].Offset;
+  for (const auto &Entry : ELFSpillOffsetTable)
+    RegSpillOffsets[Entry.Reg] = Entry.Offset;
 }
 
 // Add GPR64 to the save instruction being built by MIB, which is in basic
@@ -906,9 +906,8 @@ SystemZXPLINKFrameLowering::SystemZXPLINKFrameLowering()
   // Create a mapping from register number to save slot offset.
   // These offsets are relative to the start of the local are area.
   RegSpillOffsets.grow(SystemZ::NUM_TARGET_REGS);
-  for (unsigned I = 0, E = array_lengthof(XPLINKSpillOffsetTable); I != E; ++I)
-    RegSpillOffsets[XPLINKSpillOffsetTable[I].Reg] =
-        XPLINKSpillOffsetTable[I].Offset;
+  for (const auto &Entry : XPLINKSpillOffsetTable)
+    RegSpillOffsets[Entry.Reg] = Entry.Offset;
 }
 
 // Checks if the function is a potential candidate for being a XPLeaf routine.
index c303307..ca6c156 100644 (file)
@@ -4267,8 +4267,7 @@ void LSRInstance::GenerateCrossUseConstantOffsets() {
       ImmMapTy::const_iterator OtherImms[] = {
           Imms.begin(), std::prev(Imms.end()),
          Imms.lower_bound(Avg)};
-      for (size_t i = 0, e = array_lengthof(OtherImms); i != e; ++i) {
-        ImmMapTy::const_iterator M = OtherImms[i];
+      for (const auto &M : OtherImms) {
         if (M == J || M == JE) continue;
 
         // Compute the difference between the two.
index 18958e8..8b28a00 100644 (file)
@@ -170,10 +170,8 @@ static std::vector<std::string> ComputeLibsForComponents(
 
   // Build a map of component names to information.
   StringMap<AvailableComponent *> ComponentMap;
-  for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) {
-    AvailableComponent *AC = &AvailableComponents[i];
-    ComponentMap[AC->Name] = AC;
-  }
+  for (auto &AC : AvailableComponents)
+    ComponentMap[AC.Name] = &AC;
 
   // Visit the components.
   for (unsigned i = 0, e = Components.size(); i != e; ++i) {
@@ -546,15 +544,14 @@ int main(int argc, char **argv) {
         /// built, print LLVM_DYLIB_COMPONENTS instead of everything
         /// in the manifest.
         std::vector<std::string> Components;
-        for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
+        for (const auto &AC : AvailableComponents) {
           // Only include non-installed components when in a development tree.
-          if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
+          if (!AC.IsInstalled && !IsInDevelopmentTree)
             continue;
 
-          Components.push_back(AvailableComponents[j].Name);
-          if (AvailableComponents[j].Library && !IsInDevelopmentTree) {
-            std::string path(
-                GetComponentLibraryPath(AvailableComponents[j].Library, false));
+          Components.push_back(AC.Name);
+          if (AC.Library && !IsInDevelopmentTree) {
+            std::string path(GetComponentLibraryPath(AC.Library, false));
             if (DirSep == "\\") {
               std::replace(path.begin(), path.end(), '/', '\\');
             }