From a105f27f611c2a51cb9a16c3af40488061acf947 Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Mon, 6 Apr 2026 20:37:26 +0200 Subject: [PATCH] [Scheduler][NFC] Don't use set to track visited nodes (#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. This improves compile times: stage2-O3 -0.14%. --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 20 +++++++++++++++---- .../SelectionDAG/ScheduleDAGSDNodes.cpp | 12 +++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index 3bbafe2d124e..2d5e92381ef6 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -689,10 +689,14 @@ private: /// Return a pointer to the specified value type. LLVM_ABI static const EVT *getValueTypeList(MVT VT); - /// 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. - int CombinerWorklistIndex = -1; + union { + /// 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. + int CombinerWorklistIndex = -1; + /// Visited state in ScheduleDAGSDNodes::BuildSchedUnits. + bool SchedulerWorklistVisited; + }; uint32_t CFIType = 0; @@ -795,6 +799,14 @@ public: /// Set worklist index for DAGCombiner void setCombinerWorklistIndex(int Index) { CombinerWorklistIndex = Index; } + /// Get visited state for ScheduleDAGSDNodes::BuildSchedUnits. + bool getSchedulerWorklistVisited() const { return SchedulerWorklistVisited; } + + /// Set visited state for ScheduleDAGSDNodes::BuildSchedUnits. + void setSchedulerWorklistVisited(bool Visited) { + SchedulerWorklistVisited = Visited; + } + /// Return the node ordering. unsigned getIROrder() const { return IROrder; } diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp index 4f4fb9c759ad..c51e2de30934 100644 --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp @@ -329,6 +329,7 @@ void ScheduleDAGSDNodes::BuildSchedUnits() { unsigned NumNodes = 0; for (SDNode &NI : DAG->allnodes()) { NI.setNodeId(-1); + NI.setSchedulerWorklistVisited(false); ++NumNodes; } @@ -343,16 +344,19 @@ void ScheduleDAGSDNodes::BuildSchedUnits() { SmallVector Worklist; SmallPtrSet Visited; Worklist.push_back(DAG->getRoot().getNode()); - Visited.insert(DAG->getRoot().getNode()); + DAG->getRoot().getNode()->setSchedulerWorklistVisited(true); SmallVector 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()->getSchedulerWorklistVisited()) + continue; + Op.getNode()->setSchedulerWorklistVisited(true); + Worklist.push_back(Op.getNode()); + } if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate. continue;