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

[Lang] Migrate irpass::scalarize() after irpass::detect_read_only() #7939

Merged
merged 8 commits into from
May 8, 2023
16 changes: 8 additions & 8 deletions taichi/transforms/compile_to_offloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ void compile_to_offloads(IRNode *ir,
print("Offloaded");
irpass::analysis::verify(ir);

if (config.real_matrix_scalarize) {
irpass::scalarize(ir);

// Remove redundant MatrixInitStmt inserted during scalarization
irpass::die(ir);
print("Scalarized");
}

// TODO: This pass may be redundant as cfg_optimization() is already called
// in full_simplify().
if (config.opt_level > 0 && config.cfg_optimization) {
Expand Down Expand Up @@ -187,6 +179,14 @@ void offload_to_executable(IRNode *ir,
print("Detect read-only accesses");
}

if (config.real_matrix_scalarize) {
irpass::scalarize(ir);

// Remove redundant MatrixInitStmt inserted during scalarization
irpass::full_simplify(ir, config, {false, /*autodiff_enabled*/ false});
print("Scalarized");
}

irpass::demote_atomics(ir, config);
print("Atomics demoted I");
irpass::analysis::verify(ir);
Expand Down
8 changes: 6 additions & 2 deletions taichi/transforms/scalarize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,12 @@ class ExtractLocalPointers : public BasicStmtVisitor {
Block *top_level_;

explicit ExtractLocalPointers(IRNode *root) : immediate_modifier_(root) {
TI_ASSERT(root->is<Block>());
top_level_ = root->as<Block>();
if (root->is<OffloadedStmt>()) {
top_level_ = root->as<OffloadedStmt>()->body.get();
} else {
TI_ASSERT(root->is<Block>());
top_level_ = root->as<Block>();
}
root->accept(this);
delayed_modifier_.modify_ir();
}
Expand Down