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 <compiler/PermuteFactor.h>
22 #include <util/Utils.h>
23 #include "util/logging.h"
32 void ConstantLoweringPass::callback(const ir::OperationIndex &node_index, ir::IOperation &node)
34 const auto op_lower_info = _lowered_graph.lower_info().operation.getRawPtr(node_index);
35 const auto backend = op_lower_info->backend();
36 const auto layout = op_lower_info->layout();
37 const auto factor = 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() | ir::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 auto operand_li = std::make_unique<compiler::OperandLowerInfo>();
48 operand_li->addDefPermuteFactor(factor);
49 operand_li->addUsePermuteFactor(factor);
50 _lowered_graph.lower_info().operand.set(input, std::move(operand_li));
56 } // namespace compiler