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][refactor] First step to move Frontend IR to its own file #914

Merged
merged 2 commits into from
May 3, 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
1 change: 1 addition & 0 deletions taichi/ir/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "taichi/common/util.h"
#include "taichi/common/dict.h"
#include "taichi/util/io.h"
#include "taichi/ir/frontend_ir.h"

namespace taichi {
static_assert(
Expand Down
20 changes: 20 additions & 0 deletions taichi/ir/frontend_ir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "taichi/lang_util.h"
#include "taichi/ir/ir.h"
#include "taichi/ir/expr.h"

TLANG_NAMESPACE_BEGIN

class FrontendAllocaStmt : public Stmt {
public:
Identifier ident;

FrontendAllocaStmt(const Identifier &lhs, DataType type) : ident(lhs) {
ret_type = VectorType(1, type);
}

DEFINE_ACCEPT
};

TLANG_NAMESPACE_END
1 change: 1 addition & 0 deletions taichi/ir/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unordered_map>

#include "taichi/ir/frontend.h"
#include "taichi/ir/frontend_ir.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this is necessary after we move all Frontend*Stmts to their own file.

Copy link
Member Author

@k-ye k-ye May 4, 2020

Choose a reason for hiding this comment

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

I guess they have to be around for a while, since currently there are some legacy stuff referring to the Frontend stmts, e.g.

taichi/taichi/ir/ir.cpp

Lines 933 to 941 in 4d228b9

For::For(const ExprGroup &i,
const Expr &global,
const std::function<void()> &func) {
auto stmt_unique = std::make_unique<FrontendForStmt>(i, global);
auto stmt = stmt_unique.get();
current_ast_builder().insert(std::move(stmt_unique));
auto _ = current_ast_builder().create_scope(stmt->body);
func();
}

I think once these legacy constructs are removed, then it should be fine to remove this dependency..

#include "taichi/ir/statements.h"

TLANG_NAMESPACE_BEGIN
Expand Down
11 changes: 0 additions & 11 deletions taichi/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,17 +828,6 @@ inline ExprGroup operator,(const ExprGroup &a, const Expr &b) {
return ExprGroup(a, b);
}

class FrontendAllocaStmt : public Stmt {
public:
Identifier ident;

FrontendAllocaStmt(const Identifier &lhs, DataType type) : ident(lhs) {
ret_type = VectorType(1, type);
}

DEFINE_ACCEPT
};

class AllocaStmt : public Stmt {
public:
AllocaStmt(DataType type) {
Expand Down
2 changes: 2 additions & 0 deletions taichi/program/compile_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include "taichi/lang_util.h"
#include "arch.h"

Expand Down
4 changes: 3 additions & 1 deletion taichi/python/export_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pybind11/pybind11.h"

#include "taichi/ir/frontend.h"
#include "taichi/ir/frontend_ir.h"
#include "taichi/program/extension.h"
#include "taichi/common/interface.h"
#include "taichi/python/export.h"
Expand Down Expand Up @@ -326,7 +327,8 @@ void export_lang(py::module &m) {
m.def("layout", layout);

m.def("value_cast", static_cast<Expr (*)(const Expr &expr, DataType)>(cast));
m.def("bits_cast", static_cast<Expr (*)(const Expr &expr, DataType)>(bit_cast));
m.def("bits_cast",
static_cast<Expr (*)(const Expr &expr, DataType)>(bit_cast));

m.def("expr_atomic_add", [&](const Expr &a, const Expr &b) {
return Expr::make<AtomicOpExpression>(AtomicOpType::add, ptr_if_global(a),
Expand Down
6 changes: 4 additions & 2 deletions taichi/transforms/ir_printer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// The IRPrinter prints the IR in a human-readable format

#include <typeinfo>

#include "taichi/ir/ir.h"
#include "taichi/ir/frontend_ir.h"

TLANG_NAMESPACE_BEGIN

Expand Down Expand Up @@ -127,8 +129,8 @@ class IRPrinter : public IRVisitor {

void visit(UnaryOpStmt *stmt) override {
if (stmt->is_cast()) {
std::string reint = stmt->op_type == UnaryOpType::cast_value ?
"" : "reinterpret_";
std::string reint =
stmt->op_type == UnaryOpType::cast_value ? "" : "reinterpret_";
print("{}{} = {}{}<{}> {}", stmt->type_hint(), stmt->name(), reint,
unary_op_type_name(stmt->op_type),
data_type_short_name(stmt->cast_type), stmt->operand->name());
Expand Down
5 changes: 3 additions & 2 deletions taichi/transforms/lower_ast.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "taichi/ir/ir.h"

#include <unordered_set>

#include "taichi/ir/ir.h"
#include "taichi/ir/frontend_ir.h"

TLANG_NAMESPACE_BEGIN

namespace {
Expand Down