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 #ifndef COMPILER_OPTIMIZER_ANALYSIS_MONITOR_ANALYSIS_H 16 #define COMPILER_OPTIMIZER_ANALYSIS_MONITOR_ANALYSIS_H 17 18 #include "optimizer/ir/graph.h" 19 #include "optimizer/ir/marker.h" 20 #include "optimizer/pass.h" 21 22 namespace ark::compiler { 23 /* 24 * The analysis checks MonitorEntry and MonitorExit in the Graph and set properties for blocks: 25 * 1. BlockMonitorEntry for blocks with MonitorEntry 26 * 2. BlockMonitorExit for blocks with MonitorExit 27 * 3. BlockMonitor for blocks between BlockMonitorEntry and BlockMonitorExit 28 * The analysis returns false if there is way with MonitorEntry and without MonitorExit or Vice versa 29 * For this case the analysis return false: 30 * bb 1 31 * | \ 32 * bb 2 bb 3 33 * | MonitorEntry 34 * | / 35 * bb 4 - Conditional is equal to bb 1 36 * | \ 37 * bb 5 bb 6 38 * | MonitorExit 39 * | / 40 * bb 7 41 */ 42 class MonitorAnalysis final : public Analysis { 43 public: 44 using Analysis::Analysis; 45 GetPassName()46 const char *GetPassName() const override 47 { 48 return "MonitorAnalysis"; 49 } 50 51 bool RunImpl() override; 52 SetCheckNonCatchOnly(bool checkNonCatchOnly)53 void SetCheckNonCatchOnly(bool checkNonCatchOnly) 54 { 55 checkNonCatchOnly_ = checkNonCatchOnly; 56 } 57 58 private: 59 void MarkedMonitorRec(BasicBlock *bb, int32_t numMonitors); 60 61 Marker marker_ {UNDEF_MARKER}; 62 bool incorrectMonitors_ {false}; 63 ArenaVector<uint32_t> *enteredMonitorsCount_ {nullptr}; 64 bool checkNonCatchOnly_ {false}; 65 }; 66 } // namespace ark::compiler 67 #endif // COMPILER_OPTIMIZER_ANALYSIS_MONITOR_ANALYSIS_H 68