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