From 19e3f03a2ebbc6e1ab757c77dbe8a597ea4d82d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 26 Aug 2019 11:38:24 +0900 Subject: [PATCH] [logo] Introduce Pass (#6889) * [logo] Introduce Pass This will introduce logo project with Pass base class to provide loco graph trasformations Signed-off-by: SaeHie Park * change test group --- compiler/logo/CMakeLists.txt | 21 +++++++++++++++++ compiler/logo/README.md | 3 +++ compiler/logo/include/logo/Pass.h | 48 +++++++++++++++++++++++++++++++++++++++ compiler/logo/requires.cmake | 1 + compiler/logo/src/Pass.cpp | 32 ++++++++++++++++++++++++++ compiler/logo/src/Pass.test.cpp | 46 +++++++++++++++++++++++++++++++++++++ 6 files changed, 151 insertions(+) create mode 100644 compiler/logo/CMakeLists.txt create mode 100644 compiler/logo/README.md create mode 100644 compiler/logo/include/logo/Pass.h create mode 100644 compiler/logo/requires.cmake create mode 100644 compiler/logo/src/Pass.cpp create mode 100644 compiler/logo/src/Pass.test.cpp diff --git a/compiler/logo/CMakeLists.txt b/compiler/logo/CMakeLists.txt new file mode 100644 index 0000000..c632fbf --- /dev/null +++ b/compiler/logo/CMakeLists.txt @@ -0,0 +1,21 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(logo STATIC ${SOURCES}) +set_target_properties(logo PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(logo PRIVATE src) +target_include_directories(logo PUBLIC include) +target_link_libraries(logo PUBLIC loco) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +nncc_find_package(GTest REQUIRED) + +add_executable(logo_test ${TESTS}) +target_include_directories(logo_test PRIVATE src) +target_link_libraries(logo_test gtest_main) +target_link_libraries(logo_test logo) +add_test(logo_test logo_test) diff --git a/compiler/logo/README.md b/compiler/logo/README.md new file mode 100644 index 0000000..67f764c --- /dev/null +++ b/compiler/logo/README.md @@ -0,0 +1,3 @@ +# logo + +_logo_ privides _loco_ General Graph Passes for Transformation and Optimization diff --git a/compiler/logo/include/logo/Pass.h b/compiler/logo/include/logo/Pass.h new file mode 100644 index 0000000..4f667f1 --- /dev/null +++ b/compiler/logo/include/logo/Pass.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LOGO_PASS_H__ +#define __LOGO_PASS_H__ + +#include + +#include + +namespace logo +{ + +class Pass +{ +public: + virtual ~Pass() = default; + +public: + virtual const char *name(void) const { return nullptr; } + +public: + /** + * @brief Run the pass + * + * @return false if there was nothing changed + */ + virtual bool run(loco::Graph *graph) = 0; +}; + +std::string pass_name(const Pass *); + +} // namespace logo + +#endif // __LOGO_PASS_H__ diff --git a/compiler/logo/requires.cmake b/compiler/logo/requires.cmake new file mode 100644 index 0000000..44f6870 --- /dev/null +++ b/compiler/logo/requires.cmake @@ -0,0 +1 @@ +require("loco") diff --git a/compiler/logo/src/Pass.cpp b/compiler/logo/src/Pass.cpp new file mode 100644 index 0000000..a440107 --- /dev/null +++ b/compiler/logo/src/Pass.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace logo +{ + +std::string pass_name(const Pass *t) +{ + if (t->name() == nullptr) + { + return "(unknown)"; + } + + return t->name(); +} + +} // namespace logo diff --git a/compiler/logo/src/Pass.test.cpp b/compiler/logo/src/Pass.test.cpp new file mode 100644 index 0000000..b6bebff --- /dev/null +++ b/compiler/logo/src/Pass.test.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include + +TEST(LogoPassTests, pass_name_over_unnamed_pass) +{ + struct Bumblebee final : public logo::Pass + { + bool run(loco::Graph *) final { return false; } + }; + + Bumblebee bumblebee; + + ASSERT_EQ(logo::pass_name(&bumblebee), "(unknown)"); +} + +TEST(LogoPassTests, pass_name_over_named_pass) +{ + struct Bumblebee final : public logo::Pass + { + const char *name(void) const final { return "Bee"; } + bool run(loco::Graph *) final { return false; } + }; + + Bumblebee bumblebee; + + ASSERT_EQ(logo::pass_name(&bumblebee), "Bee"); +} -- 2.7.4