[llvm] [NFC][TableGen] Eliminate use of `ConstRecIter` from SubtargetEmitter (PR #130162)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 6 11:27:44 PST 2025


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/130162

- Eliminate use of `ConstRecIter` from `expandProcResources` by using `all_of()` to simplify the code.

>From 05e1dc8b1ae872fcb280a735541cfef0546c6df6 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 6 Mar 2025 11:23:30 -0800
Subject: [PATCH] [NFC][TableGen] Eliminate use of `ConstRecIter` from
 SubtargetEmitter

- Eliminate use of `ConstRecIter` from `expandProcResources` by using
  `all_of()` to simplify the code.
---
 llvm/utils/TableGen/SubtargetEmitter.cpp | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index d4510f2757349..c398b6f9bf7cd 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1029,9 +1029,9 @@ void SubtargetEmitter::expandProcResources(
   for (unsigned I = 0, E = PRVec.size(); I != E; ++I) {
     const Record *PRDef = PRVec[I];
     ConstRecVec SubResources;
-    if (PRDef->isSubClassOf("ProcResGroup"))
+    if (PRDef->isSubClassOf("ProcResGroup")) {
       SubResources = PRDef->getValueAsListOfDefs("Resources");
-    else {
+    } else {
       SubResources.push_back(PRDef);
       PRDef = SchedModels.findProcResUnits(PRDef, PM, PRDef->getLoc());
       for (const Record *SubDef = PRDef;
@@ -1053,13 +1053,11 @@ void SubtargetEmitter::expandProcResources(
       if (PR == PRDef || !PR->isSubClassOf("ProcResGroup"))
         continue;
       ConstRecVec SuperResources = PR->getValueAsListOfDefs("Resources");
-      ConstRecIter SubI = SubResources.begin(), SubE = SubResources.end();
-      for (; SubI != SubE; ++SubI) {
-        if (!is_contained(SuperResources, *SubI)) {
-          break;
-        }
-      }
-      if (SubI == SubE) {
+      bool AllContained =
+          all_of(SubResources, [SuperResources](const Record *SubResource) {
+            return is_contained(SuperResources, SubResource);
+          });
+      if (AllContained) {
         PRVec.push_back(PR);
         ReleaseAtCycles.push_back(ReleaseAtCycles[I]);
         AcquireAtCycles.push_back(AcquireAtCycles[I]);



More information about the llvm-commits mailing list