• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IR_LOOP_UNSWITCHER_H
17 #define COMPILER_OPTIMIZER_IR_LOOP_UNSWITCHER_H
18 
19 #include "graph_cloner.h"
20 
21 namespace ark::compiler {
22 /**
23  * Class unswitchs loop:
24  * - Clone loop;
25  * - Fix control & data flow;
26  */
27 class LoopUnswitcher : public GraphCloner {
28 public:
29     static Inst *FindUnswitchInst(Loop *loop);
30     static bool IsSmallLoop(Loop *loop);
31     static void EstimateInstructionsCount(const Loop *loop, const Inst *unswitchInst, int64_t *loopSize,
32                                           int64_t *trueCount, int64_t *falseCount);
33     explicit LoopUnswitcher(Graph *graph, ArenaAllocator *allocator, ArenaAllocator *localAllocator);
34     Loop *UnswitchLoop(Loop *loop, Inst *inst);
35 
36 private:
37     void BuildLoopUnswitchControlFlow(LoopClonerData *unswitchData);
38     void BuildLoopUnswitchDataFlow(LoopClonerData *unswitchData, Inst *ifInst);
39     void ReplaceWithConstantCondition(Inst *ifInst);
40     ArenaVector<Inst *> conditions_;
41 };
42 }  // namespace ark::compiler
43 
44 #endif  // COMPILER_OPTIMIZER_IR_LOOP_UNSWITCHER_H
45