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_LOOP_PEELING_H_ 17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_LOOP_PEELING_H_ 18 19 #include "optimizer/optimizations/loop_transform.h" 20 #include "compiler_options.h" 21 22 namespace panda::compiler { 23 class LoopPeeling : public LoopTransform<LoopExitPoint::LOOP_EXIT_HEADER> { 24 public: LoopPeeling(Graph * graph)25 explicit LoopPeeling(Graph *graph) : LoopTransform(graph) {} 26 NO_COPY_SEMANTIC(LoopPeeling); 27 NO_MOVE_SEMANTIC(LoopPeeling); 28 ~LoopPeeling() override = default; 29 30 bool RunImpl() override; 31 IsEnable()32 bool IsEnable() const override 33 { 34 return options.IsCompilerLoopPeeling(); 35 } 36 GetPassName()37 const char *GetPassName() const override 38 { 39 return "LoopPeeling"; 40 } 41 42 void InvalidateAnalyses() override; 43 44 private: 45 bool TransformLoop(Loop *loop) override; 46 void InsertPreLoop(Loop *loop); 47 size_t MoveLoopExitToBackEdge(BasicBlock *header, BasicBlock *back_edge); 48 void UpdateClonedInstInputs(Inst *inst, BasicBlock *header, BasicBlock *back_edge); 49 bool is_appied_ {false}; 50 }; 51 } // namespace panda::compiler 52 53 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_LOOP_PEELING_H_ 54