Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Mar 6, 2025

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

- Eliminate use of `ConstRecIter` from `expandProcResources` by using
  `all_of()` to simplify the code.
@jurahul jurahul marked this pull request as ready for review March 7, 2025 16:40
@jurahul jurahul requested review from s-barannikov and topperc March 7, 2025 16:40
@llvmbot
Copy link
Member

llvmbot commented Mar 7, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

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

Full diff: https://github.com/llvm/llvm-project/pull/130162.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/SubtargetEmitter.cpp (+7-9)
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]);

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jurahul jurahul merged commit 8f02936 into llvm:main Mar 10, 2025
15 checks passed
@jurahul jurahul deleted the eliminate_const_rec_iter_subtarget branch March 10, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants