• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ANALYSIS_IF_CONVERSION_H_
17 #define COMPILER_OPTIMIZER_ANALYSIS_IF_CONVERSION_H_
18 
19 #include "optimizer/ir/graph.h"
20 #include "utils/arena_containers.h"
21 
22 namespace panda::compiler {
23 class BasicBlock;
24 class Graph;
25 
26 class IfConversion : public Optimization {
27 public:
Optimization(graph)28     explicit IfConversion(Graph *graph, uint32_t limit = 2) : Optimization(graph), limit_(limit) {}
29 
30     NO_MOVE_SEMANTIC(IfConversion);
31     NO_COPY_SEMANTIC(IfConversion);
32     ~IfConversion() override = default;
33 
34     bool RunImpl() override;
35 
IsEnable()36     bool IsEnable() const override
37     {
38         return options.IsCompilerIfConversion();
39     }
40 
GetPassName()41     const char *GetPassName() const override
42     {
43         return "IfConversion";
44     }
45 
46     void InvalidateAnalyses() override;
47 
48 private:
49     uint32_t limit_;
50     bool TryTriangle(BasicBlock *bb);
51     bool TryDiamond(BasicBlock *bb);
52     static bool IsConvertable(BasicBlock *bb, uint32_t *inst_count);
53     static bool IsPhisAllowed(BasicBlock *bb, BasicBlock *pred1, BasicBlock *pred2, uint32_t *phi_count);
54 };
55 }  // namespace panda::compiler
56 
57 #endif  // COMPILER_OPTIMIZER_ANALYSIS_IF_CONVERSION_H_
58