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 #ifndef COMPILER_OPTIMIZER_ANALYSIS_CATCH_INPUT_H 17 #define COMPILER_OPTIMIZER_ANALYSIS_CATCH_INPUT_H 18 19 #include "optimizer/pass.h" 20 21 namespace ark::compiler { 22 /** 23 * Mark all instructions that are used within catch blocks (i.e. catch block inputs) 24 * with CATCH_INPUT flag. 25 * Analysis is aimed to help optimization passes to decide whether or not an instruction 26 * could be safely removed from a method having catch block (as catch block will be 27 * removed from the CFG after try-catch resolution). 28 * For example, scalar replacement optimization may eliminate allocation of 29 * objects that don't escape a method. In case of an exception a catch block is yet 30 * another escapement site and EscapeAnalysis pass is relying on CATCH_INPUT flag to 31 * check if an allocation can escape through a catch. 32 */ 33 class CatchInputs : public Analysis { 34 public: 35 using Analysis::Analysis; 36 NO_MOVE_SEMANTIC(CatchInputs); 37 NO_COPY_SEMANTIC(CatchInputs); 38 ~CatchInputs() override = default; 39 40 bool RunImpl() override; GetPassName()41 const char *GetPassName() const override 42 { 43 return "Catch Inputs"; 44 } 45 }; 46 } // namespace ark::compiler 47 48 #endif // COMPILER_OPTIMIZER_ANALYSIS_CATCH_INPUT_H 49