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_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 #include "optimizer/ir/analysis.h" 22 23 namespace ark::compiler { 24 class LoopPeeling : public LoopTransform<LoopExitPoint::LOOP_EXIT_HEADER> { 25 public: LoopPeeling(Graph * graph)26 explicit LoopPeeling(Graph *graph) : LoopTransform(graph) {} 27 NO_COPY_SEMANTIC(LoopPeeling); 28 NO_MOVE_SEMANTIC(LoopPeeling); 29 ~LoopPeeling() override = default; 30 31 bool RunImpl() override; 32 IsEnable()33 bool IsEnable() const override 34 { 35 return g_options.IsCompilerLoopPeeling(); 36 } 37 GetPassName()38 const char *GetPassName() const override 39 { 40 return "LoopPeeling"; 41 } 42 43 void InvalidateAnalyses() override; 44 45 private: 46 bool TransformLoop(Loop *loop) override; 47 void InsertPreLoop(Loop *loop); 48 size_t MoveLoopExitToBackEdge(BasicBlock *header, BasicBlock *backEdge); 49 void UpdateClonedInstInputs(Inst *inst, BasicBlock *header, BasicBlock *backEdge); 50 bool isAppied_ {false}; 51 SaveStateBridgesBuilder ssb_; 52 }; 53 } // namespace ark::compiler 54 55 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_LOOP_PEELING_H 56