Skip to content

Commit 99bf41c

Browse files
[TargetParser] Use range-based for loops (#168296)
While I am at it, this patch converts one of the loops to use llvm::is_contained. Identified with modernize-loop-convert.
1 parent 498a01d commit 99bf41c

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

llvm/lib/TargetParser/Host.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -512,32 +512,28 @@ StringRef sys::detail::getHostCPUNameForS390x(StringRef ProcCpuinfoContent) {
512512

513513
// Look for the CPU features.
514514
SmallVector<StringRef, 32> CPUFeatures;
515-
for (unsigned I = 0, E = Lines.size(); I != E; ++I)
516-
if (Lines[I].starts_with("features")) {
517-
size_t Pos = Lines[I].find(':');
515+
for (StringRef Line : Lines)
516+
if (Line.starts_with("features")) {
517+
size_t Pos = Line.find(':');
518518
if (Pos != StringRef::npos) {
519-
Lines[I].drop_front(Pos + 1).split(CPUFeatures, ' ');
519+
Line.drop_front(Pos + 1).split(CPUFeatures, ' ');
520520
break;
521521
}
522522
}
523523

524524
// We need to check for the presence of vector support independently of
525525
// the machine type, since we may only use the vector register set when
526526
// supported by the kernel (and hypervisor).
527-
bool HaveVectorSupport = false;
528-
for (unsigned I = 0, E = CPUFeatures.size(); I != E; ++I) {
529-
if (CPUFeatures[I] == "vx")
530-
HaveVectorSupport = true;
531-
}
527+
bool HaveVectorSupport = llvm::is_contained(CPUFeatures, "vx");
532528

533529
// Now check the processor machine type.
534-
for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
535-
if (Lines[I].starts_with("processor ")) {
536-
size_t Pos = Lines[I].find("machine = ");
530+
for (StringRef Line : Lines) {
531+
if (Line.starts_with("processor ")) {
532+
size_t Pos = Line.find("machine = ");
537533
if (Pos != StringRef::npos) {
538534
Pos += sizeof("machine = ") - 1;
539535
unsigned int Id;
540-
if (!Lines[I].drop_front(Pos).getAsInteger(10, Id))
536+
if (!Line.drop_front(Pos).getAsInteger(10, Id))
541537
return getCPUNameFromS390Model(Id, HaveVectorSupport);
542538
}
543539
break;
@@ -554,9 +550,9 @@ StringRef sys::detail::getHostCPUNameForRISCV(StringRef ProcCpuinfoContent) {
554550

555551
// Look for uarch line to determine cpu name
556552
StringRef UArch;
557-
for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
558-
if (Lines[I].starts_with("uarch")) {
559-
UArch = Lines[I].substr(5).ltrim("\t :");
553+
for (StringRef Line : Lines) {
554+
if (Line.starts_with("uarch")) {
555+
UArch = Line.substr(5).ltrim("\t :");
560556
break;
561557
}
562558
}

0 commit comments

Comments
 (0)