1 /** 2 * Copyright (c) 2021-2022 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/pass.h" 21 22 namespace panda::compiler { 23 class TryCatchResolving : public Optimization { 24 public: 25 explicit TryCatchResolving(Graph *graph); 26 NO_MOVE_SEMANTIC(TryCatchResolving); 27 NO_COPY_SEMANTIC(TryCatchResolving); 28 ~TryCatchResolving() override = default; 29 30 bool RunImpl() override; 31 GetPassName()32 const char *GetPassName() const override 33 { 34 return "TryCatchResolving"; 35 } 36 void InvalidateAnalyses() override; 37 38 private: 39 void VisitTry(TryInst *try_inst); 40 BasicBlock *TryFindResolvedCatchHandler(BasicBlock *try_begin, BasicBlock *try_end); 41 void DeleteTryCatchEdges(BasicBlock *try_begin, BasicBlock *try_end); 42 void ConnectCatchHandlerAfterThrow(BasicBlock *try_end, BasicBlock *catch_block); 43 void RemoveCatchPhis(BasicBlock *block, Inst *throw_inst); 44 std::optional<uint32_t> TryGetObjectId(const Inst *inst); 45 bool DFS(BasicBlock *block, Marker marker, uint32_t try_id); 46 47 private: 48 Marker marker_ {UNDEF_MARKER}; 49 }; 50 } // namespace panda::compiler 51 52 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_TRY_CATCH_RESOLVING_H 53