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 "ConstantLoweringPass.h"
19 #include "backend/Backend.h"
21 #include <ir/operand/PermuteFactor.h>
22 #include <util/Utils.h>
31 void ConstantLoweringPass::callback(const OperationIndex &node_index, Operation &node)
33 const auto &op_sequence_index = _lowered_graph.op_seqs().getOperation(node_index);
34 const auto op_seq_lower_info = _lowered_graph.getLowerInfo(op_sequence_index);
35 const auto backend = op_seq_lower_info->backend();
36 const auto layout = op_seq_lower_info->layout();
37 const auto factor = operand::PermuteFactor{backend, layout};
39 // Now this runtime does not support the node making output of operation as constant
40 for (const auto input : node.getInputs() | Remove::DUPLICATED | ir::Remove::UNDEFINED)
42 auto &object = _graph.operands().at(input);
43 if (object.isConstant())
45 // All constant operand are already assinged at each backend by ContantInsertionPass. So a
46 // constant has `def` and `use` as the same PermuteFactor
47 _lowered_graph.setLowerInfo(input, std::make_unique<operand::LowerInfo>());
48 _lowered_graph.getLowerInfo(input)->addDefPermuteFactor(factor);
49 _lowered_graph.getLowerInfo(input)->addUsePermuteFactor(factor);