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_REDUNDANTLOOPELIMINATIONS_H_ 17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_REDUNDANTLOOPELIMINATIONS_H_ 18 19 #include "optimizer/pass.h" 20 #include "optimizer/optimizations/loop_transform.h" 21 22 namespace panda::compiler { 23 class RedundantLoopElimination : public LoopTransform<LoopExitPoint::ALL_LOOP> { 24 public: RedundantLoopElimination(Graph * graph)25 explicit RedundantLoopElimination(Graph *graph) : LoopTransform(graph) {} 26 27 NO_MOVE_SEMANTIC(RedundantLoopElimination); 28 NO_COPY_SEMANTIC(RedundantLoopElimination); 29 ~RedundantLoopElimination() override = default; 30 31 bool RunImpl() override; 32 GetPassName()33 const char *GetPassName() const override 34 { 35 return "RedundantLoopElimination"; 36 } 37 IsApplied()38 bool IsApplied() const 39 { 40 return is_applied_; 41 } 42 43 void InvalidateAnalyses() override; 44 45 private: 46 bool TransformLoop(Loop *loop) override; 47 BasicBlock *IsRedundant(Loop *loop) const; 48 void DeleteLoop(Loop *loop, BasicBlock *outside_succ) const; 49 50 bool is_applied_ {false}; 51 }; 52 } // namespace panda::compiler 53 54 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_REDUNDANTLOOPELIMINATIONS_H_ 55