• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLEBE_INCLUDE_CG_LIVE_H
17 #define MAPLEBE_INCLUDE_CG_LIVE_H
18 
19 #include "cg_phase.h"
20 #include "insn.h"
21 #include "cgbb.h"
22 #include "sparse_datainfo.h"
23 #include "cgfunc.h"
24 
25 namespace maplebe {
26 class LiveAnalysis : public AnalysisResult {
27 public:
LiveAnalysis(CGFunc & func,MemPool & memPool)28     LiveAnalysis(CGFunc &func, MemPool &memPool)
29         : AnalysisResult(&memPool), cgFunc(&func), memPool(&memPool), alloc(&memPool), stackMp(func.GetStackMemPool())
30     {
31     }
32     ~LiveAnalysis() override = default;
33 
34     void AnalysisLive();
35     void Dump() const;
36     void DumpInfo(const SparseDataInfo &info) const;
37     void InitBB(BB &bb);
38     void InitAndGetDefUse();
39     bool GenerateLiveOut(BB &bb);
40     bool GenerateLiveIn(BB &bb);
41     void BuildInOutforFunc();
42     void DealWithInOutOfCleanupBB();
43     void InsertInOutOfCleanupBB();
44     void ResetLiveSet();
45     void ClearInOutDataInfo();
46     void EnlargeSpaceForLiveAnalysis(BB &currBB);
47     void GetBBDefUse(BB &bb);
48     void ProcessAsmListOpnd(BB &bb, Operand &opnd, uint32 idx) const;
49     void ProcessListOpnd(BB &bb, Operand &opnd, bool isDef) const;
50     void ProcessMemOpnd(BB &bb, Operand &opnd) const;
51     void ProcessCondOpnd(BB &bb) const;
52     void CollectLiveInfo(BB &bb, const Operand &opnd, bool isDef, bool isUse) const;
53     void MarkStackMapInsn(Insn &insn, BB &bb);
54     void GenerateStackMapLiveIn();
55     SparseDataInfo *GenerateLiveInByDefUse(SparseDataInfo &liveOut, SparseDataInfo &use, SparseDataInfo &def,
56                                            const MapleList<BB *> &ehSuccs);
57 
NewLiveIn(uint32 maxRegCount)58     SparseDataInfo *NewLiveIn(uint32 maxRegCount)
59     {
60         return memPool->New<SparseDataInfo>(maxRegCount, alloc);
61     }
62 
NewLiveOut(uint32 maxRegCount)63     SparseDataInfo *NewLiveOut(uint32 maxRegCount)
64     {
65         return memPool->New<SparseDataInfo>(maxRegCount, alloc);
66     }
67 
NewDef(uint32 maxRegCount)68     SparseDataInfo *NewDef(uint32 maxRegCount)
69     {
70         return memPool->New<SparseDataInfo>(maxRegCount, alloc);
71     }
72 
NewDef(const SparseDataInfo & def)73     SparseDataInfo *NewDef(const SparseDataInfo &def)
74     {
75         return memPool->New<SparseDataInfo>(def, alloc);
76     }
77 
NewUse(uint32 maxRegCount)78     SparseDataInfo *NewUse(uint32 maxRegCount)
79     {
80         return memPool->New<SparseDataInfo>(maxRegCount, alloc);
81     }
82 
NewUse(const SparseDataInfo & use)83     SparseDataInfo *NewUse(const SparseDataInfo &use)
84     {
85         return memPool->New<SparseDataInfo>(use, alloc);
86     }
87 
88     virtual void GenerateReturnBBDefUse(BB &bb) const = 0;
89     virtual void ProcessCallInsnParam(BB &bb, const Insn &insn) const = 0;
90     virtual bool CleanupBBIgnoreReg(regno_t reg) = 0;
91     virtual void InitEhDefine(BB &bb) = 0;
92 
93 protected:
94     int iteration = 0;
95     CGFunc *cgFunc;
96     MemPool *memPool;
97     MapleAllocator alloc;
98     StackMemPool &stackMp;
99 };
100 
MAPLE_FUNC_PHASE_DECLARE_BEGIN(CgLiveAnalysis,maplebe::CGFunc)101 MAPLE_FUNC_PHASE_DECLARE_BEGIN(CgLiveAnalysis, maplebe::CGFunc)
102 LiveAnalysis *GetResult()
103 {
104     return live;
105 }
106 LiveAnalysis *live = nullptr;
107 OVERRIDE_DEPENDENCE
108 MAPLE_FUNC_PHASE_DECLARE_END
109 } /* namespace maplebe */
110 #endif /* MAPLEBE_INCLUDE_CG_LIVE_H */
111