Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 16, 2022
1 parent 9d86070 commit 77a8434
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions taichi/transforms/cache_loop_invariant_global_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class CacheLoopInvariantGlobalVars : public LoopInvariantDetector {

enum class CacheStatus { Read = 1, Write = 2, ReadWrite = 3 };

typedef std::unordered_map<Stmt *, std::pair<AllocaStmt *, CacheStatus>> CacheMap;
typedef std::unordered_map<Stmt *, std::pair<AllocaStmt *, CacheStatus>>
CacheMap;
std::stack<CacheMap> cached_maps;

DelayedIRModifier modifier;
Expand Down Expand Up @@ -42,12 +43,10 @@ class CacheLoopInvariantGlobalVars : public LoopInvariantDetector {
/*
*
*/
AllocaStmt *cache_global_to_local(Stmt *stmt,
CacheStatus status) {
AllocaStmt *cache_global_to_local(Stmt *stmt, CacheStatus status) {
if (auto &[cached, cached_status] = cached_maps.top()[stmt]; cached) {
// The global variable has already been cached.
if (cached_status == CacheStatus::Read &&
status == CacheStatus::Write) {
if (cached_status == CacheStatus::Read && status == CacheStatus::Write) {
// If the
add_writeback(cached, stmt);
cached_status = CacheStatus::ReadWrite;
Expand All @@ -58,7 +57,8 @@ class CacheLoopInvariantGlobalVars : public LoopInvariantDetector {
auto alloca_unique =
std::make_unique<AllocaStmt>(stmt->ret_type.ptr_removed());
auto alloca_stmt = alloca_unique.get();
modifier.insert_before(loop_blocks.top()->parent_stmt, std::move(alloca_unique));
modifier.insert_before(loop_blocks.top()->parent_stmt,
std::move(alloca_unique));
cached_maps.top()[stmt] = {alloca_stmt, status};

if (status == CacheStatus::Read) {
Expand All @@ -73,8 +73,7 @@ class CacheLoopInvariantGlobalVars : public LoopInvariantDetector {

void visit(GlobalLoadStmt *stmt) override {
if (is_operand_loop_invariant(stmt->src, stmt->parent)) {
auto alloca_stmt = cache_global_to_local(
stmt->src, CacheStatus::Read);
auto alloca_stmt = cache_global_to_local(stmt->src, CacheStatus::Read);
auto local_load = std::make_unique<LocalLoadStmt>(alloca_stmt);
stmt->replace_usages_with(local_load.get());
modifier.insert_before(stmt, std::move(local_load));
Expand All @@ -84,8 +83,7 @@ class CacheLoopInvariantGlobalVars : public LoopInvariantDetector {

void visit(GlobalStoreStmt *stmt) override {
if (is_operand_loop_invariant(stmt->dest, stmt->parent)) {
auto alloca_stmt = cache_global_to_local(
stmt->dest, CacheStatus::Write);
auto alloca_stmt = cache_global_to_local(stmt->dest, CacheStatus::Write);
auto local_store =
std::make_unique<LocalStoreStmt>(alloca_stmt, stmt->val);
stmt->replace_usages_with(local_store.get());
Expand Down

0 comments on commit 77a8434

Please sign in to comment.