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");
}
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();
{"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;
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);
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
"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");
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())
// 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");
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;
}
};
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)
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;
}
// 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;
}
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.
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;
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;
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;
};
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;
}
};
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;
}
// 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
// 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.
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.
// 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) {
/// 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(), '/', '\\');
}