• 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_OPTIMIZATIONS_BRANCH_ELIMINATION_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_BRANCH_ELIMINATION_H
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/pass.h"
21 #include "utils/arena_containers.h"
22 
23 namespace panda::compiler {
24 class BranchElimination : public Optimization {
25 public:
26     explicit BranchElimination(Graph *graph);
27 
28     NO_MOVE_SEMANTIC(BranchElimination);
29     NO_COPY_SEMANTIC(BranchElimination);
30     ~BranchElimination() override = default;
31 
32     bool RunImpl() override;
33 
IsEnable()34     bool IsEnable() const override
35     {
36         return options.IsCompilerBranchElimination();
37     }
38 
GetPassName()39     const char *GetPassName() const override
40     {
41         return "BranchElimination";
42     }
43     void InvalidateAnalyses() override;
44 
45 private:
46     void VisitBlock(BasicBlock *ifBlock);
47     void EliminateBranch(BasicBlock *ifBlock, BasicBlock *eliminatedBlock);
48     void MarkUnreachableBlocks(BasicBlock *block);
49     void DisconnectBlocks();
50     void BranchEliminationConst(BasicBlock *ifBlock);
51     void BranchEliminationIntrinsic(BasicBlock *ifBlock);
52 
53 private:
54     bool isApplied_ {false};
55     Marker rmBlockMarker_ {UNDEF_MARKER};
56 };
57 
58 }  // namespace panda::compiler
59 
60 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_BRANCH_ELIMINATION_H
61