• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "optimizer/analysis/catch_inputs.h"
17 #include "optimizer/ir/basicblock.h"
18 #include "optimizer/ir/inst.h"
19 #include "optimizer/ir/graph.h"
20 
21 namespace ark::compiler {
22 namespace {
IsCatch(BasicBlock * bb)23 bool IsCatch(BasicBlock *bb)
24 {
25     return bb->IsCatch() || bb->IsCatchBegin();
26 }
27 
ProcessInst(Inst * inst,Marker visited)28 void ProcessInst(Inst *inst, Marker visited)
29 {
30     for (auto &input : inst->GetInputs()) {
31         auto inputInst = inst->GetDataFlowInput(input.GetInst());
32         // mark only instructions defined in non-catch blocks
33         auto bb = inputInst->GetBasicBlock();
34         if (!IsCatch(bb)) {
35             inputInst->SetFlag(inst_flags::Flags::CATCH_INPUT);
36         }
37         if (inputInst->IsPhi() && !inputInst->SetMarker(visited)) {
38             ProcessInst(inputInst, visited);
39         }
40     }
41 }
42 
ProcessBlock(BasicBlock * block,Marker visited)43 void ProcessBlock(BasicBlock *block, Marker visited)
44 {
45     for (auto inst : block->AllInstsSafe()) {
46         ProcessInst(inst, visited);
47     }
48 }
49 }  // namespace
50 
RunImpl()51 bool CatchInputs::RunImpl()
52 {
53     MarkerHolder holder {GetGraph()};
54     Marker visited = holder.GetMarker();
55     for (auto block : GetGraph()->GetVectorBlocks()) {
56         if (block == nullptr || !IsCatch(block)) {
57             continue;
58         }
59 
60         ProcessBlock(block, visited);
61     }
62     return true;
63 }
64 }  // namespace ark::compiler
65