Skip to content
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

Only use the nodes-visited set for nodes with multiple refs #8547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/IRVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,27 @@ void IRVisitor::visit(const HoistedStorage *op) {
}

void IRGraphVisitor::include(const Expr &e) {
auto r = visited.insert(e.get());
if (r.second) {
// Was newly inserted
if (e.is_sole_reference()) {
// We can't have visited it before, and won't visit it again.
e.accept(this);
} else {
auto r = visited.insert(e.get());
if (r.second) {
// Was newly inserted
e.accept(this);
}
}
}

void IRGraphVisitor::include(const Stmt &s) {
auto r = visited.insert(s.get());
if (r.second) {
// Was newly inserted
if (s.is_sole_reference()) {
s.accept(this);
} else {
auto r = visited.insert(s.get());
if (r.second) {
// Was newly inserted
s.accept(this);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/IRVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class IRGraphVisitor : public IRVisitor {
// @}

private:
/** The nodes visited so far */
std::set<IRHandle> visited;
/** The nodes visited so far. Only includes nodes with a ref count greater
* than one, because we know that nodes with a ref count of 1 will only be
* visited once if their parents are only visited once. */
std::set<const IRNode *> visited;

protected:
/** These methods should call 'include' on the children to only
Expand Down