2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "luci/IR/CircleDialect.h"
18 #include "luci/IR/CircleNodes.h"
21 #include <logo/DeadNodeQueryService.h>
23 #include <gtest/gtest.h>
25 TEST(CircleDialectTest, get_P)
27 auto d = luci::CircleDialect::get();
29 // get() SHOULD return a valid(non-null) pointer
30 ASSERT_NE(d, nullptr);
31 // The return value SHOULD be stable across multiple invocations
32 ASSERT_EQ(luci::CircleDialect::get(), d);
35 TEST(CircleDialectTest, check_if_dead_node_service)
38 * [CircleInput1] [CircleInput2] [CircleInput3]
39 * \ / (dangling input)
41 * [CircleAdd] [CircleBatchMatMul]
44 * [CircleOutput1] [CircleOutput2]
47 auto g = loco::make_graph();
49 auto graph_input1 = g->inputs()->create();
50 auto circle_input1 = g->nodes()->create<luci::CircleInput>();
51 circle_input1->index(graph_input1->index());
53 auto graph_input2 = g->inputs()->create();
54 auto circle_input2 = g->nodes()->create<luci::CircleInput>();
55 circle_input2->index(graph_input2->index());
58 auto graph_input3 = g->inputs()->create();
59 auto dangling_input = g->nodes()->create<luci::CircleInput>();
60 dangling_input->index(graph_input3->index());
62 auto active_node = g->nodes()->create<luci::CircleAdd>();
63 active_node->x(circle_input1);
64 active_node->y(circle_input2);
66 auto dangling_node = g->nodes()->create<luci::CircleBatchMatMul>();
68 auto graph_output1 = g->outputs()->create();
69 auto circle_output1 = g->nodes()->create<luci::CircleOutput>();
70 circle_output1->index(graph_output1->index());
71 circle_output1->from(active_node);
74 auto graph_output2 = g->outputs()->create();
75 auto circle_output2 = g->nodes()->create<luci::CircleOutput>();
76 circle_output2->index(graph_output2->index());
78 auto service = active_node->dialect()->service<logo::DeadNodeQueryService>();
80 ASSERT_TRUE(service->isDeadNode(dangling_node));
81 ASSERT_FALSE(service->isDeadNode(dangling_input));
82 ASSERT_FALSE(service->isDeadNode(active_node));
83 ASSERT_FALSE(service->isDeadNode(circle_input1));
84 ASSERT_FALSE(service->isDeadNode(circle_input2));
85 ASSERT_FALSE(service->isDeadNode(circle_output1));
86 ASSERT_FALSE(service->isDeadNode(circle_output2));