From ad6fcbf1b2f357bed6534f28fd63f5d4552dbe72 Mon Sep 17 00:00:00 2001 From: Ye Kuang Date: Sun, 3 May 2020 10:58:59 +0900 Subject: [PATCH] [ir][refactor] First step to move Frontend IR to its own file (#914) * [ir][refactor] First step to move Frontendd IR to its own file * [skip ci] enforce code format Co-authored-by: Taichi Gardener --- taichi/ir/frontend.h | 1 + taichi/ir/frontend_ir.h | 20 ++++++++++++++++++++ taichi/ir/ir.cpp | 1 + taichi/ir/ir.h | 11 ----------- taichi/program/compile_config.h | 2 ++ taichi/python/export_lang.cpp | 4 +++- taichi/transforms/ir_printer.cpp | 6 ++++-- taichi/transforms/lower_ast.cpp | 5 +++-- 8 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 taichi/ir/frontend_ir.h diff --git a/taichi/ir/frontend.h b/taichi/ir/frontend.h index 078a750887610..ac176463a07a2 100644 --- a/taichi/ir/frontend.h +++ b/taichi/ir/frontend.h @@ -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( diff --git a/taichi/ir/frontend_ir.h b/taichi/ir/frontend_ir.h new file mode 100644 index 0000000000000..90786c4506e81 --- /dev/null +++ b/taichi/ir/frontend_ir.h @@ -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 diff --git a/taichi/ir/ir.cpp b/taichi/ir/ir.cpp index 34981d97fc7ff..19cbb14e07340 100644 --- a/taichi/ir/ir.cpp +++ b/taichi/ir/ir.cpp @@ -7,6 +7,7 @@ #include #include "taichi/ir/frontend.h" +#include "taichi/ir/frontend_ir.h" #include "taichi/ir/statements.h" TLANG_NAMESPACE_BEGIN diff --git a/taichi/ir/ir.h b/taichi/ir/ir.h index 42dd6943fb040..d6b6765e853de 100644 --- a/taichi/ir/ir.h +++ b/taichi/ir/ir.h @@ -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) { diff --git a/taichi/program/compile_config.h b/taichi/program/compile_config.h index 125834485bfb9..b0df7ed5e72b3 100644 --- a/taichi/program/compile_config.h +++ b/taichi/program/compile_config.h @@ -1,3 +1,5 @@ +#pragma once + #include "taichi/lang_util.h" #include "arch.h" diff --git a/taichi/python/export_lang.cpp b/taichi/python/export_lang.cpp index 106418bf6a648..c9eceeac17d22 100644 --- a/taichi/python/export_lang.cpp +++ b/taichi/python/export_lang.cpp @@ -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" @@ -326,7 +327,8 @@ void export_lang(py::module &m) { m.def("layout", layout); m.def("value_cast", static_cast(cast)); - m.def("bits_cast", static_cast(bit_cast)); + m.def("bits_cast", + static_cast(bit_cast)); m.def("expr_atomic_add", [&](const Expr &a, const Expr &b) { return Expr::make(AtomicOpType::add, ptr_if_global(a), diff --git a/taichi/transforms/ir_printer.cpp b/taichi/transforms/ir_printer.cpp index 0a0c525f6b137..9f39547b354bc 100644 --- a/taichi/transforms/ir_printer.cpp +++ b/taichi/transforms/ir_printer.cpp @@ -1,7 +1,9 @@ // The IRPrinter prints the IR in a human-readable format #include + #include "taichi/ir/ir.h" +#include "taichi/ir/frontend_ir.h" TLANG_NAMESPACE_BEGIN @@ -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()); diff --git a/taichi/transforms/lower_ast.cpp b/taichi/transforms/lower_ast.cpp index 1d134ffad7f77..27bb19bb3da82 100644 --- a/taichi/transforms/lower_ast.cpp +++ b/taichi/transforms/lower_ast.cpp @@ -1,7 +1,8 @@ -#include "taichi/ir/ir.h" - #include +#include "taichi/ir/ir.h" +#include "taichi/ir/frontend_ir.h" + TLANG_NAMESPACE_BEGIN namespace {