Skip to content

Commit

Permalink
[Opt] [ir] [refactor] Remove exceptions from DIE pass (#1262)
Browse files Browse the repository at this point in the history
* remove IRModified exception from die

* change die's return signature to bool
  • Loading branch information
TH3CHARLie authored Jun 17, 2020
1 parent c8636bc commit b2f4bfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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

0 comments on commit b2f4bfc

Please sign in to comment.