1//==- AArch64RegisterInfo.h - AArch64 Register Information Impl --*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the AArch64 implementation of the MRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64REGISTERINFO_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64REGISTERINFO_H
15
16#define GET_REGINFO_HEADER
17#include "AArch64GenRegisterInfo.inc"
18
19namespace llvm {
20
21class MachineFunction;
22class RegScavenger;
23class TargetRegisterClass;
24class Triple;
25
26class AArch64RegisterInfo final : public AArch64GenRegisterInfo {
27 const Triple &TT;
28
29public:
30 AArch64RegisterInfo(const Triple &TT, unsigned HwMode);
31
32 // FIXME: This should be tablegen'd like getDwarfRegNum is
33 int getSEHRegNum(unsigned i) const {
34 return getEncodingValue(Reg: i);
35 }
36
37 bool isReservedReg(const MachineFunction &MF, MCRegister Reg) const;
38 bool isUserReservedReg(const MachineFunction &MF, MCRegister Reg) const;
39 bool isStrictlyReservedReg(const MachineFunction &MF, MCRegister Reg) const;
40 bool isAnyArgRegReserved(const MachineFunction &MF) const;
41 void emitReservedArgRegCallError(const MachineFunction &MF) const;
42
43 void UpdateCustomCalleeSavedRegs(MachineFunction &MF) const;
44 void UpdateCustomCallPreservedMask(MachineFunction &MF,
45 const uint32_t **Mask) const;
46
47 /// Code Generation virtual methods...
48 const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
49 const MCPhysReg *
50 getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
51 const uint32_t *getCallPreservedMask(const MachineFunction &MF,
52 CallingConv::ID) const override;
53 const uint32_t *getDarwinCallPreservedMask(const MachineFunction &MF,
54 CallingConv::ID) const;
55
56 unsigned getCSRCost() const override {
57 // The cost will be compared against BlockFrequency where entry has the
58 // value of 1 << 14. A value of 5 will choose to spill or split really
59 // cold path instead of using a callee-saved register.
60 return 5;
61 }
62 unsigned getCSRFirstUseCost() const override {
63 // The cost of 2 means push and pop for each CSR.
64 return 2;
65 }
66
67 const TargetRegisterClass *
68 getSubClassWithSubReg(const TargetRegisterClass *RC,
69 unsigned Idx) const override;
70
71 // Calls involved in thread-local variable lookup save more registers than
72 // normal calls, so they need a different mask to represent this.
73 const uint32_t *getTLSCallPreservedMask() const;
74
75 const uint32_t *getSMStartStopCallPreservedMask() const;
76 const uint32_t *SMEABISupportRoutinesCallPreservedMaskFromX0() const;
77
78 // Funclets on ARM64 Windows don't preserve any registers.
79 const uint32_t *getNoPreservedMask() const override;
80
81 // Unwinders may not preserve all Neon and SVE registers.
82 const uint32_t *
83 getCustomEHPadPreservedMask(const MachineFunction &MF) const override;
84
85 /// getThisReturnPreservedMask - Returns a call preserved mask specific to the
86 /// case that 'returned' is on an i64 first argument if the calling convention
87 /// is one that can (partially) model this attribute with a preserved mask
88 /// (i.e. it is a calling convention that uses the same register for the first
89 /// i64 argument and an i64 return value)
90 ///
91 /// Should return NULL in the case that the calling convention does not have
92 /// this property
93 const uint32_t *getThisReturnPreservedMask(const MachineFunction &MF,
94 CallingConv::ID) const;
95
96 /// Stack probing calls preserve different CSRs to the normal CC.
97 const uint32_t *getWindowsStackProbePreservedMask() const;
98
99 BitVector getStrictlyReservedRegs(const MachineFunction &MF) const;
100 BitVector getUserReservedRegs(const MachineFunction &MF) const;
101 BitVector getReservedRegs(const MachineFunction &MF) const override;
102 std::optional<std::string>
103 explainReservedReg(const MachineFunction &MF,
104 MCRegister PhysReg) const override;
105 bool isAsmClobberable(const MachineFunction &MF,
106 MCRegister PhysReg) const override;
107 const TargetRegisterClass *
108 getPointerRegClass(unsigned Kind = 0) const override;
109 const TargetRegisterClass *
110 getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
111
112 bool requiresRegisterScavenging(const MachineFunction &MF) const override;
113 bool useFPForScavengingIndex(const MachineFunction &MF) const override;
114 bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
115
116 bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
117 bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
118 int64_t Offset) const override;
119 Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx,
120 int64_t Offset) const override;
121 void resolveFrameIndex(MachineInstr &MI, Register BaseReg,
122 int64_t Offset) const override;
123 bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
124 unsigned FIOperandNum,
125 RegScavenger *RS = nullptr) const override;
126 bool cannotEliminateFrame(const MachineFunction &MF) const;
127
128 bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override;
129 bool hasBasePointer(const MachineFunction &MF) const;
130 MCRegister getBaseRegister() const;
131
132 bool isArgumentRegister(const MachineFunction &MF,
133 MCRegister Reg) const override;
134
135 // Debug information queries.
136 Register getFrameRegister(const MachineFunction &MF) const override;
137
138 unsigned getRegPressureLimit(const TargetRegisterClass *RC,
139 MachineFunction &MF) const override;
140
141 bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
142 SmallVectorImpl<MCPhysReg> &Hints,
143 const MachineFunction &MF, const VirtRegMap *VRM,
144 const LiveRegMatrix *Matrix) const override;
145
146 unsigned getLocalAddressRegister(const MachineFunction &MF) const;
147 bool regNeedsCFI(MCRegister Reg, MCRegister &RegToUseForCFI) const;
148
149 /// SrcRC and DstRC will be morphed into NewRC if this returns true
150 bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC,
151 unsigned SubReg, const TargetRegisterClass *DstRC,
152 unsigned DstSubReg, const TargetRegisterClass *NewRC,
153 LiveIntervals &LIS) const override;
154
155 void getOffsetOpcodes(const StackOffset &Offset,
156 SmallVectorImpl<uint64_t> &Ops) const override;
157
158 bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const override;
159
160 bool isIgnoredCVReg(MCRegister LLVMReg) const override;
161};
162
163} // end namespace llvm
164
165#endif
166