xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86RegisterInfo.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===-- X86RegisterInfo.h - X86 Register Information Impl -------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the X86 implementation of the TargetRegisterInfo class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_X86_X86REGISTERINFO_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #define GET_REGINFO_HEADER
190b57cec5SDimitry Andric #include "X86GenRegisterInfo.inc"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace llvm {
220b57cec5SDimitry Andric   class Triple;
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class X86RegisterInfo final : public X86GenRegisterInfo {
250b57cec5SDimitry Andric private:
260b57cec5SDimitry Andric   /// Is64Bit - Is the target 64-bits.
270b57cec5SDimitry Andric   ///
280b57cec5SDimitry Andric   bool Is64Bit;
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric   /// IsWin64 - Is the target on of win64 flavours
310b57cec5SDimitry Andric   ///
320b57cec5SDimitry Andric   bool IsWin64;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric   /// SlotSize - Stack slot size in bytes.
350b57cec5SDimitry Andric   ///
360b57cec5SDimitry Andric   unsigned SlotSize;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   /// StackPtr - X86 physical register used as stack ptr.
390b57cec5SDimitry Andric   ///
400b57cec5SDimitry Andric   unsigned StackPtr;
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric   /// FramePtr - X86 physical register used as frame ptr.
430b57cec5SDimitry Andric   ///
440b57cec5SDimitry Andric   unsigned FramePtr;
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   /// BasePtr - X86 physical register used as a base ptr in complex stack
470b57cec5SDimitry Andric   /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
480b57cec5SDimitry Andric   /// variable size stack objects.
490b57cec5SDimitry Andric   unsigned BasePtr;
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric public:
520b57cec5SDimitry Andric   explicit X86RegisterInfo(const Triple &TT);
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   // FIXME: This should be tablegen'd like getDwarfRegNum is
550b57cec5SDimitry Andric   int getSEHRegNum(unsigned i) const;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   /// getMatchingSuperRegClass - Return a subclass of the specified register
580b57cec5SDimitry Andric   /// class A so that each register in it has a sub-register of the
590b57cec5SDimitry Andric   /// specified sub-register index which is in the specified register class B.
600b57cec5SDimitry Andric   const TargetRegisterClass *
610b57cec5SDimitry Andric   getMatchingSuperRegClass(const TargetRegisterClass *A,
620b57cec5SDimitry Andric                            const TargetRegisterClass *B,
630b57cec5SDimitry Andric                            unsigned Idx) const override;
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   const TargetRegisterClass *
660b57cec5SDimitry Andric   getSubClassWithSubReg(const TargetRegisterClass *RC,
670b57cec5SDimitry Andric                         unsigned Idx) const override;
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   const TargetRegisterClass *
700b57cec5SDimitry Andric   getLargestLegalSuperClass(const TargetRegisterClass *RC,
710b57cec5SDimitry Andric                             const MachineFunction &MF) const override;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
740b57cec5SDimitry Andric                             unsigned DefSubReg,
750b57cec5SDimitry Andric                             const TargetRegisterClass *SrcRC,
760b57cec5SDimitry Andric                             unsigned SrcSubReg) const override;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
790b57cec5SDimitry Andric   /// values.
800b57cec5SDimitry Andric   const TargetRegisterClass *
810b57cec5SDimitry Andric   getPointerRegClass(const MachineFunction &MF,
820b57cec5SDimitry Andric                      unsigned Kind = 0) const override;
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   /// getCrossCopyRegClass - Returns a legal register class to copy a register
850b57cec5SDimitry Andric   /// in the specified class to or from. Returns NULL if it is possible to copy
860b57cec5SDimitry Andric   /// between a two registers of the specified class.
870b57cec5SDimitry Andric   const TargetRegisterClass *
880b57cec5SDimitry Andric   getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   /// getGPRsForTailCall - Returns a register class with registers that can be
910b57cec5SDimitry Andric   /// used in forming tail calls.
920b57cec5SDimitry Andric   const TargetRegisterClass *
930b57cec5SDimitry Andric   getGPRsForTailCall(const MachineFunction &MF) const;
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric   unsigned getRegPressureLimit(const TargetRegisterClass *RC,
960b57cec5SDimitry Andric                                MachineFunction &MF) const override;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   /// getCalleeSavedRegs - Return a null-terminated list of all of the
990b57cec5SDimitry Andric   /// callee-save registers on this target.
1000b57cec5SDimitry Andric   const MCPhysReg *
1010b57cec5SDimitry Andric   getCalleeSavedRegs(const MachineFunction* MF) const override;
1020b57cec5SDimitry Andric   const MCPhysReg *
1030b57cec5SDimitry Andric   getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
1040b57cec5SDimitry Andric   const uint32_t *getCallPreservedMask(const MachineFunction &MF,
1050b57cec5SDimitry Andric                                        CallingConv::ID) const override;
1060b57cec5SDimitry Andric   const uint32_t *getNoPreservedMask() const override;
1070b57cec5SDimitry Andric 
1080b57cec5SDimitry Andric   // Calls involved in thread-local variable lookup save more registers than
1090b57cec5SDimitry Andric   // normal calls, so they need a different mask to represent this.
1100b57cec5SDimitry Andric   const uint32_t *getDarwinTLSCallPreservedMask() const;
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric   /// getReservedRegs - Returns a bitset indexed by physical register number
1130b57cec5SDimitry Andric   /// indicating if a register is a special register that has particular uses and
1140b57cec5SDimitry Andric   /// should be considered unavailable at all times, e.g. SP, RA. This is used by
1150b57cec5SDimitry Andric   /// register scavenger to determine what registers are free.
1160b57cec5SDimitry Andric   BitVector getReservedRegs(const MachineFunction &MF) const override;
1170b57cec5SDimitry Andric 
118*81ad6265SDimitry Andric   /// isArgumentReg - Returns true if Reg can be used as an argument to a
119*81ad6265SDimitry Andric   /// function.
120*81ad6265SDimitry Andric   bool isArgumentRegister(const MachineFunction &MF,
121*81ad6265SDimitry Andric                           MCRegister Reg) const override;
122*81ad6265SDimitry Andric 
123*81ad6265SDimitry Andric   /// Return true if it is tile register class.
124*81ad6265SDimitry Andric   bool isTileRegisterClass(const TargetRegisterClass *RC) const;
125*81ad6265SDimitry Andric 
126*81ad6265SDimitry Andric   /// Returns true if PhysReg is a fixed register.
127*81ad6265SDimitry Andric   bool isFixedRegister(const MachineFunction &MF,
128*81ad6265SDimitry Andric                        MCRegister PhysReg) const override;
129*81ad6265SDimitry Andric 
1300b57cec5SDimitry Andric   void adjustStackMapLiveOutMask(uint32_t *Mask) const override;
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric   bool hasBasePointer(const MachineFunction &MF) const;
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric   bool canRealignStack(const MachineFunction &MF) const override;
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   void eliminateFrameIndex(MachineBasicBlock::iterator MI,
1370b57cec5SDimitry Andric                            int SPAdj, unsigned FIOperandNum,
1380b57cec5SDimitry Andric                            RegScavenger *RS = nullptr) const override;
1390b57cec5SDimitry Andric 
140e8d8bef9SDimitry Andric   /// findDeadCallerSavedReg - Return a caller-saved register that isn't live
141e8d8bef9SDimitry Andric   /// when it reaches the "return" instruction. We can then pop a stack object
142e8d8bef9SDimitry Andric   /// to this register without worry about clobbering it.
143e8d8bef9SDimitry Andric   unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB,
144e8d8bef9SDimitry Andric                                   MachineBasicBlock::iterator &MBBI) const;
145e8d8bef9SDimitry Andric 
1460b57cec5SDimitry Andric   // Debug information queries.
1470b57cec5SDimitry Andric   Register getFrameRegister(const MachineFunction &MF) const override;
1480b57cec5SDimitry Andric   unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const;
1490b57cec5SDimitry Andric   unsigned getPtrSizedStackRegister(const MachineFunction &MF) const;
1500b57cec5SDimitry Andric   Register getStackRegister() const { return StackPtr; }
1510b57cec5SDimitry Andric   Register getBaseRegister() const { return BasePtr; }
1520b57cec5SDimitry Andric   /// Returns physical register used as frame pointer.
1530b57cec5SDimitry Andric   /// This will always returns the frame pointer register, contrary to
1540b57cec5SDimitry Andric   /// getFrameRegister() which returns the "base pointer" in situations
1550b57cec5SDimitry Andric   /// involving a stack, frame and base pointer.
1560b57cec5SDimitry Andric   Register getFramePtr() const { return FramePtr; }
1570b57cec5SDimitry Andric   // FIXME: Move to FrameInfok
1580b57cec5SDimitry Andric   unsigned getSlotSize() const { return SlotSize; }
159e8d8bef9SDimitry Andric 
160e8d8bef9SDimitry Andric   bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
161e8d8bef9SDimitry Andric                              SmallVectorImpl<MCPhysReg> &Hints,
162e8d8bef9SDimitry Andric                              const MachineFunction &MF, const VirtRegMap *VRM,
163e8d8bef9SDimitry Andric                              const LiveRegMatrix *Matrix) const override;
1640b57cec5SDimitry Andric };
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric } // End llvm namespace
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric #endif
169