xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/X86/X86RegisterInfo.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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 
54*5f757f3fSDimitry Andric   /// Return the number of registers for the function.
55*5f757f3fSDimitry Andric   unsigned getNumSupportedRegs(const MachineFunction &MF) const override;
56*5f757f3fSDimitry Andric 
570b57cec5SDimitry Andric   // FIXME: This should be tablegen'd like getDwarfRegNum is
580b57cec5SDimitry Andric   int getSEHRegNum(unsigned i) const;
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric   /// getMatchingSuperRegClass - Return a subclass of the specified register
610b57cec5SDimitry Andric   /// class A so that each register in it has a sub-register of the
620b57cec5SDimitry Andric   /// specified sub-register index which is in the specified register class B.
630b57cec5SDimitry Andric   const TargetRegisterClass *
640b57cec5SDimitry Andric   getMatchingSuperRegClass(const TargetRegisterClass *A,
650b57cec5SDimitry Andric                            const TargetRegisterClass *B,
660b57cec5SDimitry Andric                            unsigned Idx) const override;
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   const TargetRegisterClass *
690b57cec5SDimitry Andric   getSubClassWithSubReg(const TargetRegisterClass *RC,
700b57cec5SDimitry Andric                         unsigned Idx) const override;
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   const TargetRegisterClass *
730b57cec5SDimitry Andric   getLargestLegalSuperClass(const TargetRegisterClass *RC,
740b57cec5SDimitry Andric                             const MachineFunction &MF) const override;
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
770b57cec5SDimitry Andric                             unsigned DefSubReg,
780b57cec5SDimitry Andric                             const TargetRegisterClass *SrcRC,
790b57cec5SDimitry Andric                             unsigned SrcSubReg) const override;
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
820b57cec5SDimitry Andric   /// values.
830b57cec5SDimitry Andric   const TargetRegisterClass *
840b57cec5SDimitry Andric   getPointerRegClass(const MachineFunction &MF,
850b57cec5SDimitry Andric                      unsigned Kind = 0) const override;
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   /// getCrossCopyRegClass - Returns a legal register class to copy a register
880b57cec5SDimitry Andric   /// in the specified class to or from. Returns NULL if it is possible to copy
890b57cec5SDimitry Andric   /// between a two registers of the specified class.
900b57cec5SDimitry Andric   const TargetRegisterClass *
910b57cec5SDimitry Andric   getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   /// getGPRsForTailCall - Returns a register class with registers that can be
940b57cec5SDimitry Andric   /// used in forming tail calls.
950b57cec5SDimitry Andric   const TargetRegisterClass *
960b57cec5SDimitry Andric   getGPRsForTailCall(const MachineFunction &MF) const;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   unsigned getRegPressureLimit(const TargetRegisterClass *RC,
990b57cec5SDimitry Andric                                MachineFunction &MF) const override;
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   /// getCalleeSavedRegs - Return a null-terminated list of all of the
1020b57cec5SDimitry Andric   /// callee-save registers on this target.
1030b57cec5SDimitry Andric   const MCPhysReg *
1040b57cec5SDimitry Andric   getCalleeSavedRegs(const MachineFunction* MF) const override;
1050b57cec5SDimitry Andric   const MCPhysReg *
1060b57cec5SDimitry Andric   getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
1070b57cec5SDimitry Andric   const uint32_t *getCallPreservedMask(const MachineFunction &MF,
1080b57cec5SDimitry Andric                                        CallingConv::ID) const override;
1090b57cec5SDimitry Andric   const uint32_t *getNoPreservedMask() const override;
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric   // Calls involved in thread-local variable lookup save more registers than
1120b57cec5SDimitry Andric   // normal calls, so they need a different mask to represent this.
1130b57cec5SDimitry Andric   const uint32_t *getDarwinTLSCallPreservedMask() const;
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric   /// getReservedRegs - Returns a bitset indexed by physical register number
1160b57cec5SDimitry Andric   /// indicating if a register is a special register that has particular uses and
1170b57cec5SDimitry Andric   /// should be considered unavailable at all times, e.g. SP, RA. This is used by
1180b57cec5SDimitry Andric   /// register scavenger to determine what registers are free.
1190b57cec5SDimitry Andric   BitVector getReservedRegs(const MachineFunction &MF) const override;
1200b57cec5SDimitry Andric 
12181ad6265SDimitry Andric   /// isArgumentReg - Returns true if Reg can be used as an argument to a
12281ad6265SDimitry Andric   /// function.
12381ad6265SDimitry Andric   bool isArgumentRegister(const MachineFunction &MF,
12481ad6265SDimitry Andric                           MCRegister Reg) const override;
12581ad6265SDimitry Andric 
12681ad6265SDimitry Andric   /// Return true if it is tile register class.
12781ad6265SDimitry Andric   bool isTileRegisterClass(const TargetRegisterClass *RC) const;
12881ad6265SDimitry Andric 
12981ad6265SDimitry Andric   /// Returns true if PhysReg is a fixed register.
13081ad6265SDimitry Andric   bool isFixedRegister(const MachineFunction &MF,
13181ad6265SDimitry Andric                        MCRegister PhysReg) const override;
13281ad6265SDimitry Andric 
1330b57cec5SDimitry Andric   void adjustStackMapLiveOutMask(uint32_t *Mask) const override;
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   bool hasBasePointer(const MachineFunction &MF) const;
1360b57cec5SDimitry Andric 
1370b57cec5SDimitry Andric   bool canRealignStack(const MachineFunction &MF) const override;
1380b57cec5SDimitry Andric 
13906c3fb27SDimitry Andric   bool shouldRealignStack(const MachineFunction &MF) const override;
14006c3fb27SDimitry Andric 
14106c3fb27SDimitry Andric   void eliminateFrameIndex(MachineBasicBlock::iterator II,
14206c3fb27SDimitry Andric                            unsigned FIOperandNum, Register BaseReg,
14306c3fb27SDimitry Andric                            int FIOffset) const;
14406c3fb27SDimitry Andric 
145bdd1243dSDimitry Andric   bool eliminateFrameIndex(MachineBasicBlock::iterator MI,
1460b57cec5SDimitry Andric                            int SPAdj, unsigned FIOperandNum,
1470b57cec5SDimitry Andric                            RegScavenger *RS = nullptr) const override;
1480b57cec5SDimitry Andric 
149*5f757f3fSDimitry Andric   /// Process frame indices in forwards block order because
150*5f757f3fSDimitry Andric   /// X86InstrInfo::getSPAdjust relies on it when searching for the
151*5f757f3fSDimitry Andric   /// ADJCALLSTACKUP pseudo following a call.
152*5f757f3fSDimitry Andric   /// TODO: Fix this and return true like all other targets.
eliminateFrameIndicesBackwards()153*5f757f3fSDimitry Andric   bool eliminateFrameIndicesBackwards() const override { return false; }
154*5f757f3fSDimitry Andric 
155e8d8bef9SDimitry Andric   /// findDeadCallerSavedReg - Return a caller-saved register that isn't live
156e8d8bef9SDimitry Andric   /// when it reaches the "return" instruction. We can then pop a stack object
157e8d8bef9SDimitry Andric   /// to this register without worry about clobbering it.
158e8d8bef9SDimitry Andric   unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB,
159e8d8bef9SDimitry Andric                                   MachineBasicBlock::iterator &MBBI) const;
160e8d8bef9SDimitry Andric 
1610b57cec5SDimitry Andric   // Debug information queries.
1620b57cec5SDimitry Andric   Register getFrameRegister(const MachineFunction &MF) const override;
1630b57cec5SDimitry Andric   unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const;
1640b57cec5SDimitry Andric   unsigned getPtrSizedStackRegister(const MachineFunction &MF) const;
getStackRegister()1650b57cec5SDimitry Andric   Register getStackRegister() const { return StackPtr; }
getBaseRegister()1660b57cec5SDimitry Andric   Register getBaseRegister() const { return BasePtr; }
1670b57cec5SDimitry Andric   /// Returns physical register used as frame pointer.
1680b57cec5SDimitry Andric   /// This will always returns the frame pointer register, contrary to
1690b57cec5SDimitry Andric   /// getFrameRegister() which returns the "base pointer" in situations
1700b57cec5SDimitry Andric   /// involving a stack, frame and base pointer.
getFramePtr()1710b57cec5SDimitry Andric   Register getFramePtr() const { return FramePtr; }
1720b57cec5SDimitry Andric   // FIXME: Move to FrameInfok
getSlotSize()1730b57cec5SDimitry Andric   unsigned getSlotSize() const { return SlotSize; }
174e8d8bef9SDimitry Andric 
175e8d8bef9SDimitry Andric   bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
176e8d8bef9SDimitry Andric                              SmallVectorImpl<MCPhysReg> &Hints,
177e8d8bef9SDimitry Andric                              const MachineFunction &MF, const VirtRegMap *VRM,
178e8d8bef9SDimitry Andric                              const LiveRegMatrix *Matrix) const override;
1790b57cec5SDimitry Andric };
1800b57cec5SDimitry Andric 
1810b57cec5SDimitry Andric } // End llvm namespace
1820b57cec5SDimitry Andric 
1830b57cec5SDimitry Andric #endif
184