[llvm] [Scheduler][NFC] Don't use set to track visited nodes (PR #190480)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 4 12:05:00 PDT 2026


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/190480

The visited set can grow rather large and we can use an unused field in
SDNode to store the same information without the use of a hash set.


>From 0cd9c89bd24ec53a500888a462d884bf60a491db Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sat, 4 Apr 2026 19:04:20 +0000
Subject: [PATCH] [spr] initial version

Created using spr 1.3.8-wip
---
 llvm/include/llvm/CodeGen/SelectionDAGNodes.h      |  3 +++
 .../CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp    | 14 ++++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 3bbafe2d124e7..232a550983550 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -692,6 +692,9 @@ END_TWO_BYTE_PACK()
   /// Index in worklist of DAGCombiner, or negative if the node is not in the
   /// worklist. -1 = not in worklist; -2 = not in worklist, but has already been
   /// combined at least once.
+  ///
+  /// This field is also used to track the visited state in
+  /// ScheduleDAGSDNodes::BuildSchedUnits.
   int CombinerWorklistIndex = -1;
 
   uint32_t CFIType = 0;
diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
index 4f4fb9c759ad7..5a59deedbb5a5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
@@ -329,6 +329,9 @@ void ScheduleDAGSDNodes::BuildSchedUnits() {
   unsigned NumNodes = 0;
   for (SDNode &NI : DAG->allnodes()) {
     NI.setNodeId(-1);
+    // We re-use CominerWorklistIndex as to indicate whether we visited the
+    // node before. Initialize to zero.
+    NI.setCombinerWorklistIndex(0);
     ++NumNodes;
   }
 
@@ -343,16 +346,19 @@ void ScheduleDAGSDNodes::BuildSchedUnits() {
   SmallVector<SDNode*, 64> Worklist;
   SmallPtrSet<SDNode*, 32> Visited;
   Worklist.push_back(DAG->getRoot().getNode());
-  Visited.insert(DAG->getRoot().getNode());
+  DAG->getRoot().getNode()->setCombinerWorklistIndex(1);
 
   SmallVector<SUnit*, 8> CallSUnits;
   while (!Worklist.empty()) {
     SDNode *NI = Worklist.pop_back_val();
 
     // Add all operands to the worklist unless they've already been added.
-    for (const SDValue &Op : NI->op_values())
-      if (Visited.insert(Op.getNode()).second)
-        Worklist.push_back(Op.getNode());
+    for (const SDValue &Op : NI->op_values()) {
+      if (Op.getNode()->getCombinerWorklistIndex() != 0)
+        continue;
+      Op.getNode()->setCombinerWorklistIndex(1);
+      Worklist.push_back(Op.getNode());
+    }
 
     if (isPassiveNode(NI))  // Leaf node, e.g. a TargetImmediate.
       continue;



More information about the llvm-commits mailing list