xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86RegisterInfo.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===-- X86RegisterInfo.h - X86 Register Information Impl -------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file contains the X86 implementation of the TargetRegisterInfo class.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
14*0b57cec5SDimitry Andric #define LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric #define GET_REGINFO_HEADER
19*0b57cec5SDimitry Andric #include "X86GenRegisterInfo.inc"
20*0b57cec5SDimitry Andric 
21*0b57cec5SDimitry Andric namespace llvm {
22*0b57cec5SDimitry Andric   class Triple;
23*0b57cec5SDimitry Andric 
24*0b57cec5SDimitry Andric class X86RegisterInfo final : public X86GenRegisterInfo {
25*0b57cec5SDimitry Andric private:
26*0b57cec5SDimitry Andric   /// Is64Bit - Is the target 64-bits.
27*0b57cec5SDimitry Andric   ///
28*0b57cec5SDimitry Andric   bool Is64Bit;
29*0b57cec5SDimitry Andric 
30*0b57cec5SDimitry Andric   /// IsWin64 - Is the target on of win64 flavours
31*0b57cec5SDimitry Andric   ///
32*0b57cec5SDimitry Andric   bool IsWin64;
33*0b57cec5SDimitry Andric 
34*0b57cec5SDimitry Andric   /// SlotSize - Stack slot size in bytes.
35*0b57cec5SDimitry Andric   ///
36*0b57cec5SDimitry Andric   unsigned SlotSize;
37*0b57cec5SDimitry Andric 
38*0b57cec5SDimitry Andric   /// StackPtr - X86 physical register used as stack ptr.
39*0b57cec5SDimitry Andric   ///
40*0b57cec5SDimitry Andric   unsigned StackPtr;
41*0b57cec5SDimitry Andric 
42*0b57cec5SDimitry Andric   /// FramePtr - X86 physical register used as frame ptr.
43*0b57cec5SDimitry Andric   ///
44*0b57cec5SDimitry Andric   unsigned FramePtr;
45*0b57cec5SDimitry Andric 
46*0b57cec5SDimitry Andric   /// BasePtr - X86 physical register used as a base ptr in complex stack
47*0b57cec5SDimitry Andric   /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
48*0b57cec5SDimitry Andric   /// variable size stack objects.
49*0b57cec5SDimitry Andric   unsigned BasePtr;
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric public:
52*0b57cec5SDimitry Andric   explicit X86RegisterInfo(const Triple &TT);
53*0b57cec5SDimitry Andric 
54*0b57cec5SDimitry Andric   // FIXME: This should be tablegen'd like getDwarfRegNum is
55*0b57cec5SDimitry Andric   int getSEHRegNum(unsigned i) const;
56*0b57cec5SDimitry Andric 
57*0b57cec5SDimitry Andric   /// Code Generation virtual methods...
58*0b57cec5SDimitry Andric   ///
59*0b57cec5SDimitry Andric   bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
60*0b57cec5SDimitry Andric 
61*0b57cec5SDimitry Andric   /// getMatchingSuperRegClass - Return a subclass of the specified register
62*0b57cec5SDimitry Andric   /// class A so that each register in it has a sub-register of the
63*0b57cec5SDimitry Andric   /// specified sub-register index which is in the specified register class B.
64*0b57cec5SDimitry Andric   const TargetRegisterClass *
65*0b57cec5SDimitry Andric   getMatchingSuperRegClass(const TargetRegisterClass *A,
66*0b57cec5SDimitry Andric                            const TargetRegisterClass *B,
67*0b57cec5SDimitry Andric                            unsigned Idx) const override;
68*0b57cec5SDimitry Andric 
69*0b57cec5SDimitry Andric   const TargetRegisterClass *
70*0b57cec5SDimitry Andric   getSubClassWithSubReg(const TargetRegisterClass *RC,
71*0b57cec5SDimitry Andric                         unsigned Idx) const override;
72*0b57cec5SDimitry Andric 
73*0b57cec5SDimitry Andric   const TargetRegisterClass *
74*0b57cec5SDimitry Andric   getLargestLegalSuperClass(const TargetRegisterClass *RC,
75*0b57cec5SDimitry Andric                             const MachineFunction &MF) const override;
76*0b57cec5SDimitry Andric 
77*0b57cec5SDimitry Andric   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
78*0b57cec5SDimitry Andric                             unsigned DefSubReg,
79*0b57cec5SDimitry Andric                             const TargetRegisterClass *SrcRC,
80*0b57cec5SDimitry Andric                             unsigned SrcSubReg) const override;
81*0b57cec5SDimitry Andric 
82*0b57cec5SDimitry Andric   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
83*0b57cec5SDimitry Andric   /// values.
84*0b57cec5SDimitry Andric   const TargetRegisterClass *
85*0b57cec5SDimitry Andric   getPointerRegClass(const MachineFunction &MF,
86*0b57cec5SDimitry Andric                      unsigned Kind = 0) const override;
87*0b57cec5SDimitry Andric 
88*0b57cec5SDimitry Andric   /// getCrossCopyRegClass - Returns a legal register class to copy a register
89*0b57cec5SDimitry Andric   /// in the specified class to or from. Returns NULL if it is possible to copy
90*0b57cec5SDimitry Andric   /// between a two registers of the specified class.
91*0b57cec5SDimitry Andric   const TargetRegisterClass *
92*0b57cec5SDimitry Andric   getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
93*0b57cec5SDimitry Andric 
94*0b57cec5SDimitry Andric   /// getGPRsForTailCall - Returns a register class with registers that can be
95*0b57cec5SDimitry Andric   /// used in forming tail calls.
96*0b57cec5SDimitry Andric   const TargetRegisterClass *
97*0b57cec5SDimitry Andric   getGPRsForTailCall(const MachineFunction &MF) const;
98*0b57cec5SDimitry Andric 
99*0b57cec5SDimitry Andric   unsigned getRegPressureLimit(const TargetRegisterClass *RC,
100*0b57cec5SDimitry Andric                                MachineFunction &MF) const override;
101*0b57cec5SDimitry Andric 
102*0b57cec5SDimitry Andric   /// getCalleeSavedRegs - Return a null-terminated list of all of the
103*0b57cec5SDimitry Andric   /// callee-save registers on this target.
104*0b57cec5SDimitry Andric   const MCPhysReg *
105*0b57cec5SDimitry Andric   getCalleeSavedRegs(const MachineFunction* MF) const override;
106*0b57cec5SDimitry Andric   const MCPhysReg *
107*0b57cec5SDimitry Andric   getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
108*0b57cec5SDimitry Andric   const uint32_t *getCallPreservedMask(const MachineFunction &MF,
109*0b57cec5SDimitry Andric                                        CallingConv::ID) const override;
110*0b57cec5SDimitry Andric   const uint32_t *getNoPreservedMask() const override;
111*0b57cec5SDimitry Andric 
112*0b57cec5SDimitry Andric   // Calls involved in thread-local variable lookup save more registers than
113*0b57cec5SDimitry Andric   // normal calls, so they need a different mask to represent this.
114*0b57cec5SDimitry Andric   const uint32_t *getDarwinTLSCallPreservedMask() const;
115*0b57cec5SDimitry Andric 
116*0b57cec5SDimitry Andric   /// getReservedRegs - Returns a bitset indexed by physical register number
117*0b57cec5SDimitry Andric   /// indicating if a register is a special register that has particular uses and
118*0b57cec5SDimitry Andric   /// should be considered unavailable at all times, e.g. SP, RA. This is used by
119*0b57cec5SDimitry Andric   /// register scavenger to determine what registers are free.
120*0b57cec5SDimitry Andric   BitVector getReservedRegs(const MachineFunction &MF) const override;
121*0b57cec5SDimitry Andric 
122*0b57cec5SDimitry Andric   void adjustStackMapLiveOutMask(uint32_t *Mask) const override;
123*0b57cec5SDimitry Andric 
124*0b57cec5SDimitry Andric   bool hasBasePointer(const MachineFunction &MF) const;
125*0b57cec5SDimitry Andric 
126*0b57cec5SDimitry Andric   bool canRealignStack(const MachineFunction &MF) const override;
127*0b57cec5SDimitry Andric 
128*0b57cec5SDimitry Andric   bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg,
129*0b57cec5SDimitry Andric                             int &FrameIdx) const override;
130*0b57cec5SDimitry Andric 
131*0b57cec5SDimitry Andric   void eliminateFrameIndex(MachineBasicBlock::iterator MI,
132*0b57cec5SDimitry Andric                            int SPAdj, unsigned FIOperandNum,
133*0b57cec5SDimitry Andric                            RegScavenger *RS = nullptr) const override;
134*0b57cec5SDimitry Andric 
135*0b57cec5SDimitry Andric   // Debug information queries.
136*0b57cec5SDimitry Andric   Register getFrameRegister(const MachineFunction &MF) const override;
137*0b57cec5SDimitry Andric   unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const;
138*0b57cec5SDimitry Andric   unsigned getPtrSizedStackRegister(const MachineFunction &MF) const;
139*0b57cec5SDimitry Andric   Register getStackRegister() const { return StackPtr; }
140*0b57cec5SDimitry Andric   Register getBaseRegister() const { return BasePtr; }
141*0b57cec5SDimitry Andric   /// Returns physical register used as frame pointer.
142*0b57cec5SDimitry Andric   /// This will always returns the frame pointer register, contrary to
143*0b57cec5SDimitry Andric   /// getFrameRegister() which returns the "base pointer" in situations
144*0b57cec5SDimitry Andric   /// involving a stack, frame and base pointer.
145*0b57cec5SDimitry Andric   Register getFramePtr() const { return FramePtr; }
146*0b57cec5SDimitry Andric   // FIXME: Move to FrameInfok
147*0b57cec5SDimitry Andric   unsigned getSlotSize() const { return SlotSize; }
148*0b57cec5SDimitry Andric };
149*0b57cec5SDimitry Andric 
150*0b57cec5SDimitry Andric } // End llvm namespace
151*0b57cec5SDimitry Andric 
152*0b57cec5SDimitry Andric #endif
153