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

[Opt] [ir] [refactor] Remove exceptions from DIE pass #1262

Merged
merged 2 commits into from
Jun 17, 2020
Merged
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
2 changes: 1 addition & 1 deletion taichi/ir/transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool use_fast_math(IRNode *root);

void re_id(IRNode *root);
void flag_access(IRNode *root);
void die(IRNode *root);
bool die(IRNode *root);
bool simplify(IRNode *root, Kernel *kernel = nullptr);
void cfg_optimization(IRNode *root);
bool alg_simp(IRNode *root);
Expand Down
19 changes: 11 additions & 8 deletions taichi/transforms/die.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ class DIE : public IRVisitor {
public:
std::unordered_set<int> used;
int phase; // 0: mark usage 1: eliminate
DelayedIRModifier modifier;
bool modified_ir;

DIE(IRNode *node) {
allow_undefined_visitor = true;
invoke_default_visitor = true;
while (1) {
modified_ir = false;
while (true) {
bool modified = false;
phase = 0;
used.clear();
node->accept(this);
phase = 1;
while (1) {
try {
node->accept(this);
} catch (IRModified) {
while (true) {
node->accept(this);
if (modifier.modify_ir()) {
modified = true;
modified_ir = true;
continue;
}
break;
Expand All @@ -53,8 +56,7 @@ class DIE : public IRVisitor {
} else {
if (stmt->dead_instruction_eliminable() &&
used.find(stmt->instance_id) == used.end()) {
stmt->parent->erase(stmt);
throw IRModified();
modifier.erase(stmt);
}
}
}
Expand Down Expand Up @@ -97,9 +99,10 @@ class DIE : public IRVisitor {

namespace irpass {

void die(IRNode *root) {
bool die(IRNode *root) {
TI_AUTO_PROF;
DIE instance(root);
return instance.modified_ir;
}

} // namespace irpass
Expand Down