LLVM 23.0.0git
SIFrameLowering.h
Go to the documentation of this file.
1//===--------------------- SIFrameLowering.h --------------------*- 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#ifndef LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
10#define LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
11
12#include "AMDGPUFrameLowering.h"
13#include "SIRegisterInfo.h"
14
15namespace llvm {
16
17class SIInstrInfo;
18
20public:
22 Align TransAl = Align(1))
23 : AMDGPUFrameLowering(D, StackAl, LAO, TransAl) {}
24 ~SIFrameLowering() override = default;
25
27 MachineBasicBlock &MBB) const;
29 MachineBasicBlock &MBB) const override;
31 MachineBasicBlock &MBB) const override;
33 Register &FrameReg) const override;
34
36 RegScavenger *RS = nullptr) const override;
38 RegScavenger *RS = nullptr) const;
40 bool NeedExecCopyReservedReg) const;
43 LiveRegUnits &LiveUnits, Register FrameReg,
44 Register FramePtrRegScratchCopy,
45 const bool NeedsFrameMoves) const;
48 const DebugLoc &DL, LiveRegUnits &LiveUnits,
49 Register FrameReg,
50 Register FramePtrRegScratchCopy) const;
51 bool
54 std::vector<CalleeSavedInfo> &CSI) const override;
55
58 std::vector<CalleeSavedInfo> &CSI) const;
59
60private:
61 /// Spill a single CSR according to @p CS
62 ///
63 /// This is a separate method so it an be shared between the block-ops enabled
64 /// and disabled paths. Even when block-ops are enabled we may not have a
65 /// viable block for a specific register, so it will fall back to this
66 /// implementation.
67 ///
68 /// @p LiveInRoots conveys whether we are tracking liveness, and if we are
69 /// it captures the original live-ins before spilling in a way that can be
70 /// (relatively) efficiently checked without enumerating all register aliases.
71 /// See @c buildLiveInRoots in the implementation.
72 void spillCalleeSavedRegisterWithoutBlockOps(
74 const CalleeSavedInfo &CS, const SIInstrInfo *TII,
75 const SIRegisterInfo &TRI,
76 const std::optional<SparseBitVector<>> &LiveInRoots) const;
77
78public:
82 const TargetRegisterInfo *TRI) const override;
83
84 bool
88 const TargetRegisterInfo *TRI) const override;
89
91 const MachineFunction &MF) const override;
92
93 bool isSupportedStackID(TargetStackID::Value ID) const override;
94
97 RegScavenger *RS = nullptr) const override;
98
100 MachineFunction &MF, RegScavenger *RS = nullptr) const override;
101
105 MachineBasicBlock::iterator MI) const override;
106
107protected:
108 bool hasFPImpl(const MachineFunction &MF) const override;
109
110private:
111 void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
114 const DebugLoc &DL,
115 Register ScratchWaveOffsetReg) const;
116
117 Register getEntryFunctionReservedScratchRsrcReg(MachineFunction &MF) const;
118
119 void emitEntryFunctionScratchRsrcRegSetup(
122 Register PreloadedPrivateBufferReg, Register ScratchRsrcReg,
123 Register ScratchWaveOffsetReg) const;
124
125 void emitPrologueEntryCFI(MachineBasicBlock &MBB,
127 const DebugLoc &DL) const;
128
130 DebugLoc const &DL, MCRegister StackPtrReg,
131 bool AspaceAlreadyDefined,
133
134public:
136
137 /// Create a CFI index for CFIInst and build a MachineInstr around it.
140 const DebugLoc &DL, const MCCFIInstruction &CFIInst,
142
143 /// Create a CFI index describing a spill of the VGPR/AGPR \p Reg to another
144 /// VGPR/AGPR \p RegCopy and build a MachineInstr around it.
147 const DebugLoc &DL,
148 const MCRegister Reg,
149 const MCRegister RegCopy) const;
150 /// Create a CFI index describing a spill of an SGPR to a single lane of
151 /// a VGPR and build a MachineInstr around it.
154 const DebugLoc &DL,
155 const MCRegister SGPR,
156 const MCRegister VGPR,
157 const int Lane) const;
158 /// Create a CFI index describing a spill of an SGPR to multiple lanes of
159 /// VGPRs and build a MachineInstr around it.
162 const DebugLoc &DL, MCRegister SGPR,
163 ArrayRef<SIRegisterInfo::SpilledReg> VGPRSpills) const;
164 /// Create a CFI index describing a spill of a SGPR to VMEM and
165 /// build a MachineInstr around it.
168 const DebugLoc &DL, MCRegister SGPR,
169 int64_t Offset) const;
170 /// Create a CFI index describing a spill of a VGPR to VMEM and
171 /// build a MachineInstr around it.
174 const DebugLoc &DL, MCRegister VGPR,
175 int64_t Offset) const;
178 const DebugLoc &DL,
180 MCRegister SGPRPair) const;
183 const DebugLoc &DL, MCRegister Reg) const;
184 // Returns true if the function may need to reserve space on the stack for the
185 // CWSR trap handler.
186 bool mayReserveScratchForCWSR(const MachineFunction &MF) const;
187};
188
189} // end namespace llvm
190
191#endif // LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
Interface to describe a layout of a stack frame on an AMDGPU target.
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Interface definition for SIRegisterInfo.
AMDGPUFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1))
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
A debug info location.
Definition DebugLoc.h:124
A set of register units used to track register liveness.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
Wrapper class representing virtual and physical registers.
Definition Register.h:20
void determinePrologEpilogSGPRSaves(MachineFunction &MF, BitVector &SavedRegs, bool NeedExecCopyReservedReg) const
MachineInstr * buildCFIForSGPRToVMEMSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister SGPR, int64_t Offset) const
Create a CFI index describing a spill of a SGPR to VMEM and build a MachineInstr around it.
void emitCSRSpillRestores(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, LiveRegUnits &LiveUnits, Register FrameReg, Register FramePtrRegScratchCopy) const
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool mayReserveScratchForCWSR(const MachineFunction &MF) const
bool allocateScavengingFrameIndexesNearIncomingSP(const MachineFunction &MF) const override
Control the placement of special register scavenging spill slots when allocating a stack frame.
SIFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1))
bool requiresStackPointerReference(const MachineFunction &MF) const
void emitEntryFunctionPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool hasFPImpl(const MachineFunction &MF) const override
bool assignCalleeSavedSpillSlotsImpl(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const
MachineInstr * buildCFIForVRegToVRegSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCRegister Reg, const MCRegister RegCopy) const
Create a CFI index describing a spill of the VGPR/AGPR Reg to another VGPR/AGPR RegCopy and build a M...
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
MachineInstr * buildCFIForRegToSGPRPairSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister Reg, MCRegister SGPRPair) const
MachineInstr * buildCFIForVGPRToVMEMSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister VGPR, int64_t Offset) const
Create a CFI index describing a spill of a VGPR to VMEM and build a MachineInstr around it.
MachineInstr * buildCFIForSGPRToVGPRSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCRegister SGPR, const MCRegister VGPR, const int Lane) const
Create a CFI index describing a spill of an SGPR to a single lane of a VGPR and build a MachineInstr ...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void determineCalleeSavesSGPR(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
MachineInstr * buildCFIForSameValue(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister Reg) const
MachineInstr * buildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCCFIInstruction &CFIInst, MachineInstr::MIFlag flag=MachineInstr::FrameSetup) const
Create a CFI index for CFIInst and build a MachineInstr around it.
~SIFrameLowering() override=default
void emitCSRSpillStores(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, LiveRegUnits &LiveUnits, Register FrameReg, Register FramePtrRegScratchCopy, const bool NeedsFrameMoves) const
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
bool isSupportedStackID(TargetStackID::Value ID) const override
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39