• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #ifndef COMPILER_OPTIMIZER_OPTIMIZATIONS_TRY_CATCH_RESOLVING_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_TRY_CATCH_RESOLVING_H
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/ir/inst.h"
21 #include "optimizer/pass.h"
22 
23 namespace panda::compiler {
24 class TryCatchResolving : public Optimization {
25 public:
26     explicit TryCatchResolving(Graph *graph);
27     NO_MOVE_SEMANTIC(TryCatchResolving);
28     NO_COPY_SEMANTIC(TryCatchResolving);
~TryCatchResolving()29     ~TryCatchResolving() override
30     {
31         tryBlocks_.clear();
32         throwInsts_.clear();
33         catchBlocks_.clear();
34         phiInsts_.clear();
35         cphi2phi_.clear();
36         catch2cphis_.clear();
37     }
38 
39     bool RunImpl() override;
40 
GetPassName()41     const char *GetPassName() const override
42     {
43         return "TryCatchResolving";
44     }
45     void InvalidateAnalyses() override;
46 
47 private:
48     void CollectCandidates();
49     BasicBlock *FindCatchBeginBlock(BasicBlock *bb);
50     void VisitTryInst(TryInst *tryInst);
51     void ConnectThrowCatch();
52     void ConnectThrowCatchImpl(BasicBlock *catchBlock, BasicBlock *throwBlock, uint32_t catchPc, Inst *newObj,
53                                Inst *thr0w);
54     void DeleteTryCatchEdges(BasicBlock *tryBegin, BasicBlock *tryEnd);
55     void RemoveCatchPhis(BasicBlock *cphisBlock, BasicBlock *catchBlock, Inst *throwInst, Inst *phiInst);
56     void RemoveCatchPhisImpl(CatchPhiInst *catchPhi, BasicBlock *catchBlock, Inst *throwInst);
57 
58 private:
59     Marker marker_ {UNDEF_MARKER};
60     ArenaVector<BasicBlock *> tryBlocks_;
61     ArenaVector<Inst *> throwInsts_;
62     ArenaMap<uint32_t, BasicBlock *> catchBlocks_;
63     ArenaMap<uint32_t, PhiInst *> phiInsts_;
64     ArenaMap<CatchPhiInst *, PhiInst *> cphi2phi_;
65     ArenaMap<BasicBlock *, BasicBlock *> catch2cphis_;
66 };
67 }  // namespace panda::compiler
68 
69 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_TRY_CATCH_RESOLVING_H
70