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

[IR] Fix illegal intermediate IRs #806

Merged
merged 1 commit into from
Apr 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion taichi/transforms/compile_to_offloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,55 @@ void compile_to_offloads(IRNode *ir,

irpass::typecheck(ir);
print("Typechecked");
irpass::analysis::verify(ir);

if (vectorize) {
irpass::slp_vectorize(ir);
print("SLP");

irpass::loop_vectorize(ir);
print("Loop Vectorized");
irpass::analysis::verify(ir);

irpass::vector_split(ir, config.max_vector_width, config.serial_schedule);
print("Loop Split");
irpass::analysis::verify(ir);
}
irpass::simplify(ir);
print("Simplified I");
irpass::analysis::verify(ir);

if (grad) {
irpass::demote_atomics(ir);
irpass::full_simplify(ir, config);
irpass::make_adjoint(ir, ad_use_stack);
irpass::full_simplify(ir, config);
print("Adjoint");
irpass::analysis::verify(ir);
}

if (config.demote_dense_struct_fors) {
irpass::demote_dense_struct_fors(ir);
irpass::typecheck(ir);
print("Dense struct-for demoted");
irpass::analysis::verify(ir);
}

if (config.check_out_of_bound) {
irpass::check_out_of_bound(ir);
print("Bound checked");
irpass::analysis::verify(ir);
}

irpass::lower_access(ir, true);
print("Access lowered");
irpass::die(ir);
print("DIE");
irpass::analysis::verify(ir);

irpass::full_simplify(ir, config);
print("Simplified II");
irpass::analysis::verify(ir);

irpass::flag_access(ir);
print("Access flagged");
Expand All @@ -81,6 +90,7 @@ void compile_to_offloads(IRNode *ir,

irpass::offload(ir);
print("Offloaded");
irpass::analysis::verify(ir);

irpass::demote_atomics(ir);
print("Atomics demoted");
Expand All @@ -90,7 +100,6 @@ void compile_to_offloads(IRNode *ir,

// Final field registration correctness & type checking
irpass::typecheck(ir);
irpass::fix_block_parents(ir); // hot fix
irpass::analysis::verify(ir);
}

Expand Down
3 changes: 2 additions & 1 deletion taichi/transforms/demote_dense_struct_fors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ void demote_dense_struct_fors(IRNode *root) {
}
}
}
irpass::re_id(root);
re_id(root);
fix_block_parents(root);
}

} // namespace irpass
Expand Down
1 change: 0 additions & 1 deletion taichi/transforms/fix_block_parents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class FixBlockParents : public IRVisitor {
}

void visit(OffloadedStmt *stmt) override {
stmt->parent = current_block; // hot fix
if (stmt->body)
stmt->body->accept(this);
}
Expand Down
6 changes: 3 additions & 3 deletions taichi/transforms/offload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ void insert_gc(IRNode *root) {
auto snodes = gc_statements[i].second;
for (auto *snode : snodes) {
if (is_gc_able(snode->type)) {
b->statements.insert(
b->statements.begin() + i + 1,
Stmt::make<OffloadedStmt>(OffloadedStmt::TaskType::gc, snode));
b->insert(Stmt::make<OffloadedStmt>(OffloadedStmt::TaskType::gc, snode),
i + 1);
Comment on lines -492 to +493
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying Block::statements directly without setting parent was really bad...

If we set Block::statements to be private to prevent code fragments like this, we may need some functions like Block::get_statements() to keep code fragments like for (auto &stmt : b->statements) neat?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, probably something like Block::get_statements() const.

}
}
}
Expand Down Expand Up @@ -585,6 +584,7 @@ OffloadedResult offload(IRNode *root) {
AssociateContinueScope::run(root);
typecheck(root);
re_id(root);
fix_block_parents(root);
return result;
}

Expand Down