• 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_OPTIMIZATIONS_REGALLOC_SPLIT_RESOLVER_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_REGALLOC_SPLIT_RESOLVER_H
18 
19 #include "compiler/optimizer/analysis/liveness_analyzer.h"
20 #include "compiler/optimizer/ir/graph.h"
21 
22 namespace panda::compiler {
23 class SplitResolver {
24 public:
SplitResolver(Graph * graph)25     explicit SplitResolver(Graph *graph) : SplitResolver(graph, &graph->GetAnalysis<LivenessAnalyzer>()) {}
SplitResolver(Graph * graph,LivenessAnalyzer * liveness)26     explicit SplitResolver(Graph *graph, LivenessAnalyzer *liveness) : graph_(graph), liveness_(liveness) {}
27 
28     DEFAULT_COPY_SEMANTIC(SplitResolver);
29     DEFAULT_MOVE_SEMANTIC(SplitResolver);
30 
31     ~SplitResolver() = default;
32 
33     void Run();
34 
35 private:
36     void ConnectSiblings(LifeIntervals *interval);
37     void ProcessBlock(BasicBlock *block);
38     SpillFillInst *CreateSpillFillForSiblings(Inst *connect_at);
39     SpillFillInst *CreateSpillFillForSplitMove(BasicBlock *source_block);
40     void ConnectSpiltFromPredBlock(BasicBlock *src_bb, LifeIntervals *src_interval, BasicBlock *target_bb,
41                                    LifeIntervals *target_split);
42 
43     template <SpillFillType expected_type>
Is(Inst * inst)44     static bool Is(Inst *inst)
45     {
46         ASSERT(inst != nullptr);
47         if (!inst->IsSpillFill()) {
48             return false;
49         }
50         auto sf = inst->CastToSpillFill();
51         ASSERT(sf->GetSpillFillType() != SpillFillType::UNKNOWN);
52         return sf->GetSpillFillType() == expected_type;
53     }
54 
55 private:
56     Graph *graph_;
57     LivenessAnalyzer *liveness_;
58 };
59 }  // namespace panda::compiler
60 
61 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_REGALLOC_SPLIT_RESOLVER_H
62