-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[SelectionDAG] Add support to dump DAGs with sorted nodes #161097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4f59ec0
a61f8d7
9e0da50
343ae09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
|
||
getTopologicallyOrderedNodes(SortedNodes); | ||
for (const SDNode *N : SortedNodes) | ||
dumpEachNode(*N); | ||
} else { | ||
for (const SDNode &N : allnodes()) | ||
dumpEachNode(N); | ||
} | ||
|
||
if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this vector have any compile time cost on large DAGs?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the very least, it'll be slower to not reserving enough space for all nodes ahead of time. But other than that, yeah the heap allocation time might add up if we're going to create this vector every time we dump a DAG. One solution is allowing users of this API to pass in a pre-allocated (auxiliary) vector to avoid the problem we're discussing here, what do you think?
EDIT: I thought this is the dump API, but I think having a pre-allocated space might still be an option.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that this added a vector to the non-dumping path too. Directly related to the downside you listed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also leave AssignTopologicalOrder untouched and only use getTopologicallyOrderedNodes in SelectionDAG::dump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I've reverted the code of AssignTopologicalOrder to its original one.