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/Nodes/CircleInput.h"
19 #include "luci/IR/Nodes/CircleOutput.h"
21 #include <loco/IR/Graph.h>
22 #include <loco/IR/GraphInputIndex.h>
23 #include <loco/IR/GraphOutputIndex.h>
25 #include "DeadNodeQueryService.h"
33 struct GiiQueryServiceImpl final : public loco::GraphInputIndexQueryService
35 bool associated(const loco::Node *node) const final
37 if (auto circleinput = dynamic_cast<const luci::CircleInput *>(node))
39 return circleinput->indexed();
44 loco::GraphOutputIndex index(const loco::Node *node) const final
46 assert(associated(node));
47 auto circleinput = loco::must_cast<const luci::CircleInput *>(node);
48 return circleinput->index();
52 struct GoiQueryServiceImpl final : public loco::GraphOutputIndexQueryService
54 bool associated(const loco::Node *node) const final
56 if (auto circleoutput = dynamic_cast<const luci::CircleOutput *>(node))
58 return circleoutput->indexed();
63 loco::GraphOutputIndex index(const loco::Node *node) const final
65 assert(associated(node));
66 auto circleoutput = loco::must_cast<const luci::CircleOutput *>(node);
67 return circleoutput->index();
76 CircleDialect::CircleDialect()
78 service<loco::GraphInputIndexQueryService>(std::make_unique<GiiQueryServiceImpl>());
79 service<loco::GraphOutputIndexQueryService>(std::make_unique<GoiQueryServiceImpl>());
80 service<logo::DeadNodeQueryService>(std::make_unique<DeadNodeQueryServiceImpl>());
83 loco::Dialect *CircleDialect::get(void)
85 static CircleDialect d;