• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_UNSWITCH_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_LOOP_UNSWITCH_H
18 
19 #include "optimizer/optimizations/loop_transform.h"
20 #include "compiler_options.h"
21 
22 namespace ark::compiler {
23 class LoopUnswitch : public LoopTransform<LoopExitPoint::LOOP_EXIT_BACKEDGE> {
24 public:
LoopUnswitch(Graph * graph,uint32_t maxLevel,uint32_t maxInsns)25     explicit LoopUnswitch(Graph *graph, uint32_t maxLevel, uint32_t maxInsns)
26         : LoopTransform(graph), loops_(graph->GetLocalAllocator()->Adapter()), maxLevel_(maxLevel), maxInsns_(maxInsns)
27     {
28     }
29     bool RunImpl() override;
GetPassName()30     const char *GetPassName() const override
31     {
32         return "LoopUnswitch";
33     }
34 
35     void InvalidateAnalyses() override;
IsEnable()36     bool IsEnable() const override
37     {
38         return g_options.IsCompilerLoopUnswitch();
39     }
40 
41 private:
42     bool TransformLoop(Loop *loop) override;
43     bool IsHoistable(Inst *inst, Loop *loop);
44     bool AllInputsConst(Inst *inst);
45     ArenaQueue<Loop *> loops_;
46     const uint32_t maxLevel_ {0};
47     const uint32_t maxInsns_ {0};
48     bool isApplied_ {false};
49 };
50 }  // namespace ark::compiler
51 
52 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_LOOP_UNSWITCH_H
53