1//===-- X86RegisterInfo.h - X86 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 X86 implementation of the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
14#define LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
15
16#include "llvm/CodeGen/GlobalISel/Utils.h"
17#include "llvm/CodeGen/MachineFunction.h"
18#include "llvm/CodeGen/TargetRegisterInfo.h"
19
20#define GET_REGINFO_HEADER
21#include "X86GenRegisterInfo.inc"
22
23namespace llvm {
24 class Triple;
25
26class X86RegisterInfo final : public X86GenRegisterInfo {
27private:
28 /// Is64Bit - Is the target 64-bits.
29 ///
30 bool Is64Bit;
31
32 /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
33 bool IsTarget64BitLP64;
34
35 /// IsWin64 - Is the target on of win64 flavours
36 ///
37 bool IsWin64;
38
39 /// IsUEFI64 - Is UEFI 64 bit target.
40 ///
41 bool IsUEFI64;
42
43 /// SlotSize - Stack slot size in bytes.
44 ///
45 unsigned SlotSize;
46
47 /// StackPtr - X86 physical register used as stack ptr.
48 ///
49 unsigned StackPtr;
50
51 /// FramePtr - X86 physical register used as frame ptr.
52 ///
53 unsigned FramePtr;
54
55 /// BasePtr - X86 physical register used as a base ptr in complex stack
56 /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
57 /// variable size stack objects.
58 unsigned BasePtr;
59
60public:
61 explicit X86RegisterInfo(const Triple &TT);
62
63 /// Return the number of registers for the function.
64 unsigned getNumSupportedRegs(const MachineFunction &MF) const override;
65
66 /// getMatchingSuperRegClass - Return a subclass of the specified register
67 /// class A so that each register in it has a sub-register of the
68 /// specified sub-register index which is in the specified register class B.
69 const TargetRegisterClass *
70 getMatchingSuperRegClass(const TargetRegisterClass *A,
71 const TargetRegisterClass *B,
72 unsigned Idx) const override;
73
74 const TargetRegisterClass *
75 getSubClassWithSubReg(const TargetRegisterClass *RC,
76 unsigned Idx) const override;
77
78 const TargetRegisterClass *
79 getLargestLegalSuperClass(const TargetRegisterClass *RC,
80 const MachineFunction &MF) const override;
81
82 /// getCrossCopyRegClass - Returns a legal register class to copy a register
83 /// in the specified class to or from. Returns NULL if it is possible to copy
84 /// between a two registers of the specified class.
85 const TargetRegisterClass *
86 getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
87
88 unsigned getRegPressureLimit(const TargetRegisterClass *RC,
89 MachineFunction &MF) const override;
90
91 /// getCalleeSavedRegs - Return a null-terminated list of all of the
92 /// callee-save registers on this target.
93 const MCPhysReg *
94 getCalleeSavedRegs(const MachineFunction* MF) const override;
95 /// getIPRACSRegs - This API can be removed when rbp is safe to optimized out
96 /// when IPRA is on.
97 const MCPhysReg *getIPRACSRegs(const MachineFunction *MF) const override;
98 const MCPhysReg *
99 getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
100 const uint32_t *getCallPreservedMask(const MachineFunction &MF,
101 CallingConv::ID) const override;
102 const uint32_t *getNoPreservedMask() const override;
103
104 // Calls involved in thread-local variable lookup save more registers than
105 // normal calls, so they need a different mask to represent this.
106 const uint32_t *getDarwinTLSCallPreservedMask() const;
107
108 /// getReservedRegs - Returns a bitset indexed by physical register number
109 /// indicating if a register is a special register that has particular uses and
110 /// should be considered unavailable at all times, e.g. SP, RA. This is used by
111 /// register scavenger to determine what registers are free.
112 BitVector getReservedRegs(const MachineFunction &MF) const override;
113
114 /// isArgumentReg - Returns true if Reg can be used as an argument to a
115 /// function.
116 bool isArgumentRegister(const MachineFunction &MF,
117 MCRegister Reg) const override;
118
119 /// Return true if it is tile register class.
120 bool isTileRegisterClass(const TargetRegisterClass *RC) const;
121
122 /// Returns true if PhysReg is a fixed register.
123 bool isFixedRegister(const MachineFunction &MF,
124 MCRegister PhysReg) const override;
125
126 void adjustStackMapLiveOutMask(uint32_t *Mask) const override;
127
128 bool hasBasePointer(const MachineFunction &MF) const;
129
130 bool canRealignStack(const MachineFunction &MF) const override;
131
132 bool shouldRealignStack(const MachineFunction &MF) const override;
133
134 void eliminateFrameIndex(MachineBasicBlock::iterator II,
135 unsigned FIOperandNum, Register BaseReg,
136 int FIOffset) const;
137
138 bool eliminateFrameIndex(MachineBasicBlock::iterator MI,
139 int SPAdj, unsigned FIOperandNum,
140 RegScavenger *RS = nullptr) const override;
141
142 /// Process frame indices in forwards block order because
143 /// X86InstrInfo::getSPAdjust relies on it when searching for the
144 /// ADJCALLSTACKUP pseudo following a call.
145 /// TODO: Fix this and return true like all other targets.
146 bool eliminateFrameIndicesBackwards() const override { return false; }
147
148 /// findDeadCallerSavedReg - Return a caller-saved register that isn't live
149 /// when it reaches the "return" instruction. We can then pop a stack object
150 /// to this register without worry about clobbering it.
151 unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB,
152 MachineBasicBlock::iterator &MBBI) const;
153
154 // Debug information queries.
155 Register getFrameRegister(const MachineFunction &MF) const override;
156 Register getPtrSizedFrameRegister(const MachineFunction &MF) const;
157 Register getPtrSizedStackRegister(const MachineFunction &MF) const;
158 Register getStackRegister() const { return StackPtr; }
159 Register getBaseRegister() const { return BasePtr; }
160 /// Returns physical register used as frame pointer.
161 /// This will always returns the frame pointer register, contrary to
162 /// getFrameRegister() which returns the "base pointer" in situations
163 /// involving a stack, frame and base pointer.
164 Register getFramePtr() const { return FramePtr; }
165 // FIXME: Move to FrameInfok
166 unsigned getSlotSize() const { return SlotSize; }
167
168 bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
169 SmallSetVector<MCPhysReg, 16> &Hints,
170 const MachineFunction &MF, const VirtRegMap *VRM,
171 const LiveRegMatrix *Matrix) const override;
172
173 const TargetRegisterClass *
174 constrainRegClassToNonRex2(const TargetRegisterClass *RC) const;
175
176 bool isNonRex2RegClass(const TargetRegisterClass *RC) const;
177
178 bool requiresRegisterScavenging(const MachineFunction &MF) const override {
179 return true;
180 }
181
182 unsigned getCSRFirstUseCost(const MachineFunction &MF) const override;
183 unsigned getCSRCostScale(const MachineFunction &MF) const override {
184 return 30;
185 }
186
187 const TargetRegisterClass *
188 getRegClassToMinimizeDomainCrossings() const override {
189 return &X86::VR128XRegClass;
190 }
191};
192
193} // End llvm namespace
194
195#endif
196