• 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_REG_INFO_H
17 #define MAPLEBE_INCLUDE_CG_REG_INFO_H
18 
19 #include <map>
20 #include <stack>
21 #include "isa.h"
22 #include "insn.h"
23 
24 namespace maplebe {
25 
26 class RegisterInfo {
27 public:
RegisterInfo(MapleAllocator & mallocator)28     explicit RegisterInfo(MapleAllocator &mallocator)
29         : allIntRegs(mallocator.Adapter()), allFpRegs(mallocator.Adapter()), allregs(mallocator.Adapter())
30     {
31     }
32 
~RegisterInfo()33     virtual ~RegisterInfo()
34     {
35         cgFunc = nullptr;
36     }
37 
38     virtual void Init() = 0;
39     virtual void Fini() = 0;
AddToAllRegs(regno_t regNo)40     void AddToAllRegs(regno_t regNo)
41     {
42         (void)allregs.insert(regNo);
43     }
GetAllRegs()44     const MapleSet<regno_t> &GetAllRegs() const
45     {
46         return allregs;
47     }
AddToIntRegs(regno_t regNo)48     void AddToIntRegs(regno_t regNo)
49     {
50         (void)allIntRegs.insert(regNo);
51     }
GetIntRegs()52     const MapleSet<regno_t> &GetIntRegs() const
53     {
54         return allIntRegs;
55     }
AddToFpRegs(regno_t regNo)56     void AddToFpRegs(regno_t regNo)
57     {
58         (void)allFpRegs.insert(regNo);
59     }
GetFpRegs()60     const MapleSet<regno_t> &GetFpRegs() const
61     {
62         return allFpRegs;
63     }
SetCurrFunction(CGFunc & func)64     void SetCurrFunction(CGFunc &func)
65     {
66         cgFunc = &func;
67     }
GetCurrFunction()68     CGFunc *GetCurrFunction() const
69     {
70         return cgFunc;
71     }
72     virtual RegOperand *GetOrCreatePhyRegOperand(regno_t regNO, uint32 size, RegType kind, uint32 flag = 0) = 0;
73     virtual ListOperand *CreateListOperand() = 0;
74     virtual Insn *BuildMovInstruction(Operand &opnd0, Operand &opnd1) = 0;
75     virtual bool IsGPRegister(regno_t regNO) const = 0;
76     virtual bool IsPreAssignedReg(regno_t regNO) const = 0;
77     virtual uint32 GetIntParamRegIdx(regno_t regNO) const = 0;
78     virtual uint32 GetFpParamRegIdx(regno_t regNO) const = 0;
79     virtual bool IsSpecialReg(regno_t regno) const = 0;
80     virtual bool IsAvailableReg(regno_t regNO) const = 0;
81     virtual bool IsCalleeSavedReg(regno_t regno) const = 0;
82     virtual bool IsYieldPointReg(regno_t regNO) const = 0;
83     virtual bool IsUntouchableReg(uint32 regNO) const = 0;
84     virtual bool IsUnconcernedReg(regno_t regNO) const = 0;
85     virtual bool IsUnconcernedReg(const RegOperand &regOpnd) const = 0;
86     virtual bool IsVirtualRegister(const RegOperand &regOpnd) = 0;
87     virtual bool IsVirtualRegister(regno_t regno) = 0;
88     virtual void SaveCalleeSavedReg(MapleSet<regno_t> savedRegs) = 0;
89     virtual uint32 GetIntRegsParmsNum() = 0;
90     virtual uint32 GetIntRetRegsNum() = 0;
91     virtual uint32 GetFpRetRegsNum() = 0;
92     virtual uint32 GetFloatRegsParmsNum() = 0;
93     virtual regno_t GetLastParamsIntReg() = 0;
94     virtual regno_t GetLastParamsFpReg() = 0;
95     virtual regno_t GetIntRetReg(uint32 idx) = 0;
96     virtual regno_t GetFpRetReg(uint32 idx) = 0;
97     virtual uint32 GetReservedSpillReg() = 0;
98     virtual uint32 GetSecondReservedSpillReg() = 0;
99     virtual uint32 GetAllRegNum() = 0;
100     virtual uint32 GetNormalUseOperandNum() = 0;
101     virtual regno_t GetInvalidReg() = 0;
102     virtual bool IsSpillRegInRA(regno_t regNO, bool has3RegOpnd) = 0;
103     virtual Insn *BuildStrInsn(uint32 regSize, PrimType stype, RegOperand &phyOpnd, MemOperand &memOpnd) = 0;
104     virtual Insn *BuildLdrInsn(uint32 regSize, PrimType stype, RegOperand &phyOpnd, MemOperand &memOpnd) = 0;
105     virtual Insn *BuildCommentInsn(const std::string &comment) = 0;
106     virtual MemOperand *GetOrCreatSpillMem(regno_t vrNum, uint32 bitSize) = 0;
107     virtual MemOperand *AdjustMemOperandIfOffsetOutOfRange(MemOperand *memOpnd, regno_t vrNum, bool isDest, Insn &insn,
108                                                            regno_t regNum, bool &isOutOfRange) = 0;
109     virtual void FreeSpillRegMem(regno_t vrNum) = 0;
110 
111 private:
112     MapleSet<regno_t> allIntRegs;
113     MapleSet<regno_t> allFpRegs;
114     MapleSet<regno_t> allregs;
115     CGFunc *cgFunc = nullptr;
116 };
117 } /* namespace maplebe */
118 
119 #endif /* MAPLEBE_INCLUDE_CG_REG_INFO_H */
120