LLVM 24.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"
15
16namespace llvm {
17
18class SIInstrInfo;
19
21public:
23 Align TransAl = Align(1))
24 : AMDGPUFrameLowering(D, StackAl, LAO, TransAl) {}
25 ~SIFrameLowering() override = default;
26
28 MachineBasicBlock &MBB) const;
30 MachineBasicBlock &MBB) const override;
32 MachineBasicBlock &MBB) const override;
34 Register &FrameReg) const override;
35
37 RegScavenger *RS = nullptr) const override;
39 RegScavenger *RS = nullptr) const;
41 bool NeedExecCopyReservedReg) const;
44 LiveRegUnits &LiveUnits, Register FrameReg,
45 Register FramePtrRegScratchCopy,
46 const bool NeedsFrameMoves) const;
49 const DebugLoc &DL, LiveRegUnits &LiveUnits,
50 Register FrameReg,
51 Register FramePtrRegScratchCopy) const;
52 bool
55 std::vector<CalleeSavedInfo> &CSI) const override;
56
59 std::vector<CalleeSavedInfo> &CSI) const;
60
61private:
62 /// Spill a single CSR according to @p CS
63 ///
64 /// This is a separate method so it an be shared between the block-ops enabled
65 /// and disabled paths. Even when block-ops are enabled we may not have a
66 /// viable block for a specific register, so it will fall back to this
67 /// implementation.
68 ///
69 /// @p LiveInRoots conveys whether we are tracking liveness, and if we are
70 /// it captures the original live-ins before spilling in a way that can be
71 /// (relatively) efficiently checked without enumerating all register aliases.
72 /// See @c buildLiveInRoots in the implementation.
73 void spillCalleeSavedRegisterWithoutBlockOps(
75 const CalleeSavedInfo &CS, const SIInstrInfo *TII,
76 const SIRegisterInfo &TRI,
77 const std::optional<SparseBitVector<>> &LiveInRoots) const;
78
79public:
83 const TargetRegisterInfo *TRI) const override;
84
85 bool
89 const TargetRegisterInfo *TRI) const override;
90
92 const MachineFunction &MF) const override;
93
94 bool isSupportedStackID(TargetStackID::Value ID) const override;
95
98 RegScavenger *RS = nullptr) const override;
99
101 MachineFunction &MF, RegScavenger *RS = nullptr) const override;
102
106 MachineBasicBlock::iterator MI) const override;
107
108protected:
109 bool hasFPImpl(const MachineFunction &MF) const override;
110
111private:
112 void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
115 const DebugLoc &DL,
116 Register ScratchWaveOffsetReg) const;
117
118 Register getEntryFunctionReservedScratchRsrcReg(MachineFunction &MF) const;
119
120 void emitEntryFunctionScratchRsrcRegSetup(
123 Register PreloadedPrivateBufferReg, Register ScratchRsrcReg,
124 Register ScratchWaveOffsetReg) const;
125
126 void emitPrologueEntryCFI(MachineBasicBlock &MBB,
128 const DebugLoc &DL) const;
129
131 DebugLoc const &DL, MCRegister StackPtrReg,
132 bool AspaceAlreadyDefined,
134
135public:
137
138 /// Create a CFI index for CFIInst and build a MachineInstr around it.
141 const DebugLoc &DL, const MCCFIInstruction &CFIInst,
143
144 /// Create a CFI index describing a spill of the VGPR/AGPR \p Reg to another
145 /// VGPR/AGPR \p RegCopy and build a MachineInstr around it.
148 const DebugLoc &DL,
149 const MCRegister Reg,
150 const MCRegister RegCopy) const;
151 /// Create a CFI index describing a spill of an SGPR to a single lane of
152 /// a VGPR and build a MachineInstr around it.
155 const DebugLoc &DL,
156 const MCRegister SGPR,
157 const MCRegister VGPR,
158 const int Lane) const;
159 /// Create a CFI index describing a spill of an SGPR to multiple lanes of
160 /// VGPRs and build a MachineInstr around it.
163 const DebugLoc &DL, MCRegister SGPR,
164 ArrayRef<SIRegisterInfo::SpilledReg> VGPRSpills) const;
165 /// Create a CFI index describing a spill of a SGPR to VMEM and
166 /// build a MachineInstr around it.
169 const DebugLoc &DL, MCRegister SGPR,
170 int64_t Offset) const;
171 /// Create a CFI index describing a spill of a VGPR to VMEM and
172 /// build a MachineInstr around it.
175 const DebugLoc &DL, MCRegister VGPR,
176 int64_t Offset) const;
179 const DebugLoc &DL,
181 MCRegister SGPRPair) const;
184 const DebugLoc &DL, MCRegister Reg) const;
185 // Returns true if the function may need to reserve space on the stack for the
186 // CWSR trap handler.
187 bool mayReserveScratchForCWSR(const MachineFunction &MF) const;
188};
189
190} // end namespace llvm
191
192#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.
This file defines the SparseBitVector class.
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:126
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...
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39