[llvm] 99bf41c - [TargetParser] Use range-based for loops (#168296)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 17 07:59:49 PST 2025
Author: Kazu Hirata
Date: 2025-11-17T07:59:45-08:00
New Revision: 99bf41cd11daa3ee32431c12ff5084fc90f1f91d
URL: https://github.com/llvm/llvm-project/commit/99bf41cd11daa3ee32431c12ff5084fc90f1f91d
DIFF: https://github.com/llvm/llvm-project/commit/99bf41cd11daa3ee32431c12ff5084fc90f1f91d.diff
LOG: [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.
Added:
Modified:
llvm/lib/TargetParser/Host.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index c164762de2966..3f9f69549f2db 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -512,11 +512,11 @@ StringRef sys::detail::getHostCPUNameForS390x(StringRef ProcCpuinfoContent) {
// Look for the CPU features.
SmallVector<StringRef, 32> CPUFeatures;
- for (unsigned I = 0, E = Lines.size(); I != E; ++I)
- if (Lines[I].starts_with("features")) {
- size_t Pos = Lines[I].find(':');
+ for (StringRef Line : Lines)
+ if (Line.starts_with("features")) {
+ size_t Pos = Line.find(':');
if (Pos != StringRef::npos) {
- Lines[I].drop_front(Pos + 1).split(CPUFeatures, ' ');
+ Line.drop_front(Pos + 1).split(CPUFeatures, ' ');
break;
}
}
@@ -524,20 +524,16 @@ StringRef sys::detail::getHostCPUNameForS390x(StringRef ProcCpuinfoContent) {
// We need to check for the presence of vector support independently of
// the machine type, since we may only use the vector register set when
// supported by the kernel (and hypervisor).
- bool HaveVectorSupport = false;
- for (unsigned I = 0, E = CPUFeatures.size(); I != E; ++I) {
- if (CPUFeatures[I] == "vx")
- HaveVectorSupport = true;
- }
+ bool HaveVectorSupport = llvm::is_contained(CPUFeatures, "vx");
// Now check the processor machine type.
- for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
- if (Lines[I].starts_with("processor ")) {
- size_t Pos = Lines[I].find("machine = ");
+ for (StringRef Line : Lines) {
+ if (Line.starts_with("processor ")) {
+ size_t Pos = Line.find("machine = ");
if (Pos != StringRef::npos) {
Pos += sizeof("machine = ") - 1;
unsigned int Id;
- if (!Lines[I].drop_front(Pos).getAsInteger(10, Id))
+ if (!Line.drop_front(Pos).getAsInteger(10, Id))
return getCPUNameFromS390Model(Id, HaveVectorSupport);
}
break;
@@ -554,9 +550,9 @@ StringRef sys::detail::getHostCPUNameForRISCV(StringRef ProcCpuinfoContent) {
// Look for uarch line to determine cpu name
StringRef UArch;
- for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
- if (Lines[I].starts_with("uarch")) {
- UArch = Lines[I].substr(5).ltrim("\t :");
+ for (StringRef Line : Lines) {
+ if (Line.starts_with("uarch")) {
+ UArch = Line.substr(5).ltrim("\t :");
break;
}
}
More information about the llvm-commits
mailing list