xref: /llvm-project/llvm/lib/Target/AMDGPU/SIFrameLowering.h (revision ad4a582fd938c933e784f0052bd773676b37b690)
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 
15 namespace llvm {
16 
17 class SIFrameLowering final : public AMDGPUFrameLowering {
18 public:
19   SIFrameLowering(StackDirection D, Align StackAl, int LAO,
20                   Align TransAl = Align(1))
21       : AMDGPUFrameLowering(D, StackAl, LAO, TransAl) {}
22   ~SIFrameLowering() override = default;
23 
24   void emitEntryFunctionPrologue(MachineFunction &MF,
25                                  MachineBasicBlock &MBB) const;
26   void emitPrologue(MachineFunction &MF,
27                     MachineBasicBlock &MBB) const override;
28   void emitEpilogue(MachineFunction &MF,
29                     MachineBasicBlock &MBB) const override;
30   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
31                                      Register &FrameReg) const override;
32 
33   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
34                             RegScavenger *RS = nullptr) const override;
35   void determineCalleeSavesSGPR(MachineFunction &MF, BitVector &SavedRegs,
36                                 RegScavenger *RS = nullptr) const;
37   void determinePrologEpilogSGPRSaves(MachineFunction &MF, BitVector &SavedRegs,
38                                       bool NeedExecCopyReservedReg) const;
39   void emitCSRSpillStores(MachineFunction &MF, MachineBasicBlock &MBB,
40                           MachineBasicBlock::iterator MBBI, DebugLoc &DL,
41                           LiveRegUnits &LiveUnits, Register FrameReg,
42                           Register FramePtrRegScratchCopy) const;
43   void emitCSRSpillRestores(MachineFunction &MF, MachineBasicBlock &MBB,
44                             MachineBasicBlock::iterator MBBI, DebugLoc &DL,
45                             LiveRegUnits &LiveUnits, Register FrameReg,
46                             Register FramePtrRegScratchCopy) const;
47   bool
48   assignCalleeSavedSpillSlots(MachineFunction &MF,
49                               const TargetRegisterInfo *TRI,
50                               std::vector<CalleeSavedInfo> &CSI) const override;
51 
52   bool allocateScavengingFrameIndexesNearIncomingSP(
53     const MachineFunction &MF) const override;
54 
55   bool isSupportedStackID(TargetStackID::Value ID) const override;
56 
57   void processFunctionBeforeFrameFinalized(
58     MachineFunction &MF,
59     RegScavenger *RS = nullptr) const override;
60 
61   void processFunctionBeforeFrameIndicesReplaced(
62       MachineFunction &MF, RegScavenger *RS = nullptr) const override;
63 
64   MachineBasicBlock::iterator
65   eliminateCallFramePseudoInstr(MachineFunction &MF,
66                                 MachineBasicBlock &MBB,
67                                 MachineBasicBlock::iterator MI) const override;
68 
69 protected:
70   bool hasFPImpl(const MachineFunction &MF) const override;
71 
72 private:
73   void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
74                                         MachineBasicBlock &MBB,
75                                         MachineBasicBlock::iterator I,
76                                         const DebugLoc &DL,
77                                         Register ScratchWaveOffsetReg) const;
78 
79   Register getEntryFunctionReservedScratchRsrcReg(MachineFunction &MF) const;
80 
81   void emitEntryFunctionScratchRsrcRegSetup(
82       MachineFunction &MF, MachineBasicBlock &MBB,
83       MachineBasicBlock::iterator I, const DebugLoc &DL,
84       Register PreloadedPrivateBufferReg, Register ScratchRsrcReg,
85       Register ScratchWaveOffsetReg) const;
86 
87 public:
88   bool requiresStackPointerReference(const MachineFunction &MF) const;
89 };
90 
91 } // end namespace llvm
92 
93 #endif // LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
94