-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[opt] Eliminate useless local stores and atomics (#858)
* eliminate useless local stores * handle IfStmt properly * fix test * eliminate atomics * add irpass::analysis::gather_used_atomics for better eliminating atomics * [skip ci] enforce code format * [skip ci] avoid confusing "for" * add a test Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
- Loading branch information
1 parent
0940e9a
commit 50ad29a
Showing
4 changed files
with
183 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "taichi/ir/ir.h" | ||
#include <unordered_set> | ||
|
||
TLANG_NAMESPACE_BEGIN | ||
|
||
class UsedAtomicsSearcher : public BasicStmtVisitor { | ||
private: | ||
std::unordered_set<AtomicOpStmt *> used_atomics; | ||
|
||
public: | ||
UsedAtomicsSearcher() { | ||
allow_undefined_visitor = true; | ||
invoke_default_visitor = true; | ||
} | ||
|
||
void search_operands(Stmt *stmt) { | ||
for (auto &op : stmt->get_operands()) { | ||
if (op != nullptr && op->is<AtomicOpStmt>()) { | ||
used_atomics.insert(op->as<AtomicOpStmt>()); | ||
} | ||
} | ||
} | ||
|
||
void preprocess_container_stmt(Stmt *stmt) override { | ||
search_operands(stmt); | ||
} | ||
|
||
void visit(Stmt *stmt) override { | ||
search_operands(stmt); | ||
} | ||
|
||
static std::unordered_set<AtomicOpStmt *> run(IRNode *root) { | ||
UsedAtomicsSearcher searcher; | ||
root->accept(&searcher); | ||
return searcher.used_atomics; | ||
} | ||
}; | ||
|
||
namespace irpass::analysis { | ||
std::unordered_set<AtomicOpStmt *> gather_used_atomics(IRNode *root) { | ||
return UsedAtomicsSearcher::run(root); | ||
} | ||
} // namespace irpass::analysis | ||
|
||
TLANG_NAMESPACE_END |
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