[llvm] [Scheduler][NFC] Don't use set to track visited nodes (PR #190480)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 12:05:35 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/190480.diff
2 Files Affected:
- (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3)
- (modified) llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp (+10-4)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/190480
More information about the llvm-commits
mailing list