[llvm] [TargetParser] Use range-based for loops (PR #168296)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 16 15:07:50 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/168296
While I am at it, this patch converts one of the loops to use
llvm::is_contained.
Identified with modernize-loop-convert.
>From f2ff182f6d9eb6624c52fa126a428c7443abeec9 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 16 Nov 2025 14:41:15 -0800
Subject: [PATCH] [TargetParser] Use range-based for loops
While I am at it, this patch converts one of the loops to use
llvm::is_contained.
Identified with modernize-loop-convert.
---
llvm/lib/TargetParser/Host.cpp | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
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