xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZFrameLowering.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- SystemZFrameLowering.h - Frame lowering for SystemZ -----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZFRAMELOWERING_H
100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZFRAMELOWERING_H
110b57cec5SDimitry Andric 
12*e8d8bef9SDimitry Andric #include "MCTargetDesc/SystemZMCTargetDesc.h"
130b57cec5SDimitry Andric #include "llvm/ADT/IndexedMap.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h"
15*e8d8bef9SDimitry Andric #include "llvm/Support/TypeSize.h"
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric namespace llvm {
180b57cec5SDimitry Andric class SystemZTargetMachine;
190b57cec5SDimitry Andric class SystemZSubtarget;
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric class SystemZFrameLowering : public TargetFrameLowering {
220b57cec5SDimitry Andric   IndexedMap<unsigned> RegSpillOffsets;
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric public:
250b57cec5SDimitry Andric   SystemZFrameLowering();
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric   // Override TargetFrameLowering.
280b57cec5SDimitry Andric   bool isFPCloseToIncomingSP() const override { return false; }
29480093f4SDimitry Andric   bool
30480093f4SDimitry Andric   assignCalleeSavedSpillSlots(MachineFunction &MF,
31480093f4SDimitry Andric                               const TargetRegisterInfo *TRI,
32480093f4SDimitry Andric                               std::vector<CalleeSavedInfo> &CSI) const override;
330b57cec5SDimitry Andric   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
340b57cec5SDimitry Andric                             RegScavenger *RS) const override;
350b57cec5SDimitry Andric   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
360b57cec5SDimitry Andric                                  MachineBasicBlock::iterator MBBI,
375ffd83dbSDimitry Andric                                  ArrayRef<CalleeSavedInfo> CSI,
380b57cec5SDimitry Andric                                  const TargetRegisterInfo *TRI) const override;
395ffd83dbSDimitry Andric   bool
405ffd83dbSDimitry Andric   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
410b57cec5SDimitry Andric                               MachineBasicBlock::iterator MBBII,
425ffd83dbSDimitry Andric                               MutableArrayRef<CalleeSavedInfo> CSI,
435ffd83dbSDimitry Andric                               const TargetRegisterInfo *TRI) const override;
440b57cec5SDimitry Andric   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
450b57cec5SDimitry Andric                                            RegScavenger *RS) const override;
460b57cec5SDimitry Andric   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
470b57cec5SDimitry Andric   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
485ffd83dbSDimitry Andric   void inlineStackProbe(MachineFunction &MF,
495ffd83dbSDimitry Andric                         MachineBasicBlock &PrologMBB) const override;
500b57cec5SDimitry Andric   bool hasFP(const MachineFunction &MF) const override;
510b57cec5SDimitry Andric   bool hasReservedCallFrame(const MachineFunction &MF) const override;
52*e8d8bef9SDimitry Andric   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
535ffd83dbSDimitry Andric                                      Register &FrameReg) const override;
540b57cec5SDimitry Andric   MachineBasicBlock::iterator
550b57cec5SDimitry Andric   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
560b57cec5SDimitry Andric                                 MachineBasicBlock::iterator MI) const override;
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   // Return the byte offset from the incoming stack pointer of Reg's
595ffd83dbSDimitry Andric   // ABI-defined save slot.  Return 0 if no slot is defined for Reg.  Adjust
605ffd83dbSDimitry Andric   // the offset in case MF has packed-stack.
615ffd83dbSDimitry Andric   unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const;
62480093f4SDimitry Andric 
63480093f4SDimitry Andric   // Get or create the frame index of where the old frame pointer is stored.
64480093f4SDimitry Andric   int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const;
655ffd83dbSDimitry Andric 
665ffd83dbSDimitry Andric   bool usePackedStack(MachineFunction &MF) const;
67*e8d8bef9SDimitry Andric 
68*e8d8bef9SDimitry Andric   // Return the offset of the backchain.
69*e8d8bef9SDimitry Andric   unsigned getBackchainOffset(MachineFunction &MF) const {
70*e8d8bef9SDimitry Andric     // The back chain is stored topmost with packed-stack.
71*e8d8bef9SDimitry Andric     return usePackedStack(MF) ? SystemZMC::CallFrameSize - 8 : 0;
72*e8d8bef9SDimitry Andric   }
730b57cec5SDimitry Andric };
740b57cec5SDimitry Andric } // end namespace llvm
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric #endif
77