1 //===-- SystemZFrameLowering.h - Frame lowering for SystemZ -----*- 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_SYSTEMZ_SYSTEMZFRAMELOWERING_H
10 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZFRAMELOWERING_H
11 
12 #include "MCTargetDesc/SystemZMCTargetDesc.h"
13 #include "llvm/ADT/IndexedMap.h"
14 #include "llvm/CodeGen/TargetFrameLowering.h"
15 #include "llvm/Support/TypeSize.h"
16 
17 namespace llvm {
18 class SystemZTargetMachine;
19 class SystemZSubtarget;
20 
21 class SystemZFrameLowering : public TargetFrameLowering {
22 
23 public:
24   SystemZFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl,
25                        bool StackReal);
26 
27   static std::unique_ptr<SystemZFrameLowering>
28   create(const SystemZSubtarget &STI);
29 
30   // Override TargetFrameLowering.
isFPCloseToIncomingSP()31   bool isFPCloseToIncomingSP() const override { return false; }
32   bool hasReservedCallFrame(const MachineFunction &MF) const override;
33   MachineBasicBlock::iterator
34   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
35                                 MachineBasicBlock::iterator MI) const override;
36 };
37 
38 class SystemZELFFrameLowering : public SystemZFrameLowering {
39   IndexedMap<unsigned> RegSpillOffsets;
40 
41 public:
42   SystemZELFFrameLowering();
43 
44   // Override TargetFrameLowering.
isFPCloseToIncomingSP()45   bool isFPCloseToIncomingSP() const override { return false; }
46   bool
47   assignCalleeSavedSpillSlots(MachineFunction &MF,
48                               const TargetRegisterInfo *TRI,
49                               std::vector<CalleeSavedInfo> &CSI) const override;
50   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
51                             RegScavenger *RS) const override;
52   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
53                                  MachineBasicBlock::iterator MBBI,
54                                  ArrayRef<CalleeSavedInfo> CSI,
55                                  const TargetRegisterInfo *TRI) const override;
56   bool
57   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
58                               MachineBasicBlock::iterator MBBII,
59                               MutableArrayRef<CalleeSavedInfo> CSI,
60                               const TargetRegisterInfo *TRI) const override;
61   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
62                                            RegScavenger *RS) const override;
63   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
64   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
65   void inlineStackProbe(MachineFunction &MF,
66                         MachineBasicBlock &PrologMBB) const override;
67   bool hasFP(const MachineFunction &MF) const override;
68   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
69                                      Register &FrameReg) const override;
70 
71   // Return the byte offset from the incoming stack pointer of Reg's
72   // ABI-defined save slot.  Return 0 if no slot is defined for Reg.  Adjust
73   // the offset in case MF has packed-stack.
74   unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const;
75 
76   bool usePackedStack(MachineFunction &MF) const;
77 
78   // Return the offset of the backchain.
getBackchainOffset(MachineFunction & MF)79   unsigned getBackchainOffset(MachineFunction &MF) const {
80     // The back chain is stored topmost with packed-stack.
81     return usePackedStack(MF) ? SystemZMC::ELFCallFrameSize - 8 : 0;
82   }
83 
84   // Get or create the frame index of where the old frame pointer is stored.
85   int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const;
86 };
87 
88 class SystemZXPLINKFrameLowering : public SystemZFrameLowering {
89 public:
90   SystemZXPLINKFrameLowering();
91 
92   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
93 
94   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
95 
96   bool hasFP(const MachineFunction &MF) const override;
97 };
98 } // end namespace llvm
99 
100 #endif
101