[llvm] [SelectionDAG] Add support to dump DAGs with sorted nodes (PR #161097)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 13:36:13 PDT 2025
================
@@ -1061,13 +1061,23 @@ static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
N->dump(G);
}
-LLVM_DUMP_METHOD void SelectionDAG::dump() const {
+LLVM_DUMP_METHOD void SelectionDAG::dump(bool Sorted) const {
dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
- for (const SDNode &N : allnodes()) {
+ auto dumpEachNode = [this](const SDNode &N) {
if (!N.hasOneUse() && &N != getRoot().getNode() &&
(!shouldPrintInline(N, this) || N.use_empty()))
DumpNodes(&N, 2, this);
+ };
+
+ if (Sorted) {
+ SmallVector<const SDNode *> SortedNodes(AllNodes.size());
----------------
topperc wrote:
This is initializing AllNodes.size() elements in the vector so it will perform a memset. `getTopologicallyOrderedNodes` will clear the vector which will change the size, but not the capacity back to 0. Should we use `reserve` instead to avoid the memset?
https://github.com/llvm/llvm-project/pull/161097
More information about the llvm-commits
mailing list