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;
31
33 MachineBasicBlock &MBB) const override;
35 MachineBasicBlock &MBB) const override;
37 Register &FrameReg) const override;
38
40 RegScavenger *RS = nullptr) const override;
42 RegScavenger *RS = nullptr) const;
44 bool NeedExecCopyReservedReg) const;
47 LiveRegUnits &LiveUnits, Register FrameReg,
48 Register FramePtrRegScratchCopy,
49 const bool NeedsFrameMoves) const;
52 const DebugLoc &DL, LiveRegUnits &LiveUnits,
53 Register FrameReg,
54 Register FramePtrRegScratchCopy) const;
55 bool
58 std::vector<CalleeSavedInfo> &CSI) const override;
59
62 std::vector<CalleeSavedInfo> &CSI) const;
63
64private:
65 /// Spill a single CSR according to @p CS
66 ///
67 /// This is a separate method so it an be shared between the block-ops enabled
68 /// and disabled paths. Even when block-ops are enabled we may not have a
69 /// viable block for a specific register, so it will fall back to this
70 /// implementation.
71 ///
72 /// @p LiveInRoots conveys whether we are tracking liveness, and if we are
73 /// it captures the original live-ins before spilling in a way that can be
74 /// (relatively) efficiently checked without enumerating all register aliases.
75 /// See @c buildLiveInRoots in the implementation.
76 void spillCalleeSavedRegisterWithoutBlockOps(
78 const CalleeSavedInfo &CS, const SIInstrInfo *TII,
79 const SIRegisterInfo &TRI,
80 const std::optional<SparseBitVector<>> &LiveInRoots) const;
81
82public:
86 const TargetRegisterInfo *TRI) const override;
87
88 bool
92 const TargetRegisterInfo *TRI) const override;
93
95 const MachineFunction &MF) const override;
96
97 bool isSupportedStackID(TargetStackID::Value ID) const override;
98
100 MachineFunction &MF,
101 RegScavenger *RS = nullptr) const override;
102
104 MachineFunction &MF, RegScavenger *RS = nullptr) const override;
105
109 MachineBasicBlock::iterator MI) const override;
110
111protected:
112 bool hasFPImpl(const MachineFunction &MF) const override;
113
114private:
115 void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
118 const DebugLoc &DL,
119 Register ScratchWaveOffsetReg) const;
120
121 Register getEntryFunctionReservedScratchRsrcReg(MachineFunction &MF) const;
122
123 void emitEntryFunctionScratchRsrcRegSetup(
126 Register PreloadedPrivateBufferReg, Register ScratchRsrcReg,
127 Register ScratchWaveOffsetReg) const;
128
129 void emitPrologueEntryCFI(MachineBasicBlock &MBB,
131 const DebugLoc &DL) const;
132
134 DebugLoc const &DL, MCRegister StackPtrReg,
135 bool AspaceAlreadyDefined,
137
138public:
140
141 /// Create a CFI index for CFIInst and build a MachineInstr around it.
144 const DebugLoc &DL, const MCCFIInstruction &CFIInst,
146
147 /// Create a CFI index describing a spill of the VGPR/AGPR \p Reg to another
148 /// VGPR/AGPR \p RegCopy and build a MachineInstr around it.
151 const DebugLoc &DL,
152 const MCRegister Reg,
153 const MCRegister RegCopy) const;
154 /// Create a CFI index describing a spill of an SGPR to a single lane of
155 /// a VGPR and build a MachineInstr around it.
158 const DebugLoc &DL,
159 const MCRegister SGPR,
160 const MCRegister VGPR,
161 const int Lane) const;
162 /// Create a CFI index describing a spill of an SGPR to multiple lanes of
163 /// VGPRs and build a MachineInstr around it.
166 const DebugLoc &DL, MCRegister SGPR,
167 ArrayRef<SIRegisterInfo::SpilledReg> VGPRSpills) const;
168 /// Create a CFI index describing a spill of a SGPR to VMEM and
169 /// build a MachineInstr around it.
172 const DebugLoc &DL, MCRegister SGPR,
173 int64_t Offset) const;
174 /// Create a CFI index describing a spill of a VGPR to VMEM and
175 /// build a MachineInstr around it.
178 const DebugLoc &DL, MCRegister VGPR,
179 int64_t Offset) const;
182 const DebugLoc &DL, MCRegister Reg,
183 MCRegister CopyReg) const;
184 /// Create a CFI index describing a copy of the 32-bit \p SGPR to \p VCCHalf
185 /// (vcc_lo or vcc_hi) in wave64 and build a MachineInstr around it.
188 const DebugLoc &DL,
189 MCRegister SGPR,
190 MCRegister VCCHalf) const;
193 const DebugLoc &DL, MCRegister Reg) const;
194 // Returns true if the function may need to reserve space on the stack for the
195 // CWSR trap handler.
196 bool mayReserveScratchForCWSR(const MachineFunction &MF) const;
197};
198
199} // end namespace llvm
200
201#endif // LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
const AArch64InstrInfo & TII
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")
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 buildCFIForSRegToSRegSpill(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister Reg, MCRegister CopyReg) const
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
MachineInstr * buildCFIForSGPRToVCCHalfCopy(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister SGPR, MCRegister VCCHalf) const
Create a CFI index describing a copy of the 32-bit SGPR to VCCHalf (vcc_lo or vcc_hi) in wave64 and b...
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 * 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.
void emitEntryFunctionEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const
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:31
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