-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
compiler stack usage improvements #6239
Merged
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1a2289a
Reduce compiler stack usage, and grant more control over stack usage
abadams 773ecc4
Fixes for macos
abadams 325ccf8
Add test to cmake
abadams 39cec7d
Fix type of temporary
abadams 2f0749a
Reduce number of exprs in the mux
abadams b03a347
Fix quadratic memory usage in new test
abadams 0e24ddb
Better comment
abadams ea35bee
Variable name fix
abadams 0715979
Try giving windows a little more stack
abadams 1adb652
Clarify why we want a live Stmt in scope
abadams 32d4953
Review comments
abadams 6fe568e
Check some return values
abadams 76e020a
tickle buildbots
steven-johnson 72fc46c
Fixes for arm macos
abadams 748f87c
Remove stray character
abadams 46854ab
clang-tidy had some reasonable concerns
abadams 429c0e3
Comment fix
abadams 083d389
Maybe windows needs yet more stack
abadams d87c943
Merge remote-tracking branch 'origin/master' into abadams/stack_size
abadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,37 +78,48 @@ class PredicateFinder : public IRVisitor { | |
op->body.accept(this); | ||
if (should_pop) { | ||
varying.pop(op->name); | ||
//internal_assert(!expr_uses_var(predicate, op->name)); | ||
// internal_assert(!expr_uses_var(predicate, op->name)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should either remove this line or add a comment about why we aren't doing this check. |
||
} else if (expr_uses_var(predicate, op->name)) { | ||
predicate = Let::make(op->name, op->min, predicate); | ||
} | ||
} | ||
|
||
template<typename T> | ||
void visit_let(const std::string &name, const Expr &value, T body) { | ||
bool old_varies = varies; | ||
varies = false; | ||
value.accept(this); | ||
bool value_varies = varies; | ||
varies |= old_varies; | ||
if (value_varies) { | ||
varying.push(name); | ||
} | ||
void visit_let(const T *op) { | ||
struct Frame { | ||
const T *op; | ||
ScopedBinding<> binding; | ||
}; | ||
vector<Frame> frames; | ||
|
||
decltype(op->body) body; | ||
do { | ||
bool old_varies = varies; | ||
varies = false; | ||
op->value.accept(this); | ||
|
||
frames.push_back(Frame{op, ScopedBinding<>(varies, varying, op->name)}); | ||
|
||
varies |= old_varies; | ||
body = op->body; | ||
op = body.template as<T>(); | ||
} while (op); | ||
|
||
body.accept(this); | ||
if (value_varies) { | ||
varying.pop(name); | ||
} | ||
if (expr_uses_var(predicate, name)) { | ||
predicate = Let::make(name, value, predicate); | ||
|
||
for (auto it = frames.rbegin(); it != frames.rend(); it++) { | ||
if (expr_uses_var(predicate, it->op->name)) { | ||
predicate = Let::make(it->op->name, it->op->value, predicate); | ||
} | ||
} | ||
} | ||
|
||
void visit(const LetStmt *op) override { | ||
visit_let(op->name, op->value, op->body); | ||
visit_let(op); | ||
} | ||
|
||
void visit(const Let *op) override { | ||
visit_let(op->name, op->value, op->body); | ||
visit_let(op); | ||
} | ||
|
||
void visit(const ProducerConsumer *op) override { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,11 @@ class UnrollLoops : public IRMutator { | |
Stmt iters; | ||
for (int i = e->value - 1; i >= 0; i--) { | ||
Stmt iter = substitute(for_loop->name, for_loop->min + i, body); | ||
// It's necessary to simplify eagerly this iteration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "eagerly simplify" |
||
// here to resolve things like muxes down to a single | ||
// item before we go and make N copies of something of | ||
// size N. | ||
iter = simplify(iter); | ||
if (!iters.defined()) { | ||
iters = iter; | ||
} else { | ||
|
@@ -93,7 +98,7 @@ class UnrollLoops : public IRMutator { | |
} | ||
} | ||
|
||
return simplify(iters); | ||
return iters; | ||
|
||
} else { | ||
return IRMutator::visit(for_loop); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
but why is that necessary?
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.
Updated comment. It's because 'body' may be the only reference-counted Stmt keeping the first LetStmt alive, but we're mutating body to point to its innards. We don't want that first LetStmt to have its refcount hit zero and make our pointer dangle.