Skip to content

Commit

Permalink
[ir][refactor] First step to move Frontend IR to its own file (#914)
Browse files Browse the repository at this point in the history
* [ir][refactor] First step to move Frontendd IR to its own file

* [skip ci] enforce code format

Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
  • Loading branch information
k-ye and taichi-gardener committed May 3, 2020
1 parent 92b6dfc commit ad6fcbf
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
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"
#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

0 comments on commit ad6fcbf

Please sign in to comment.