Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZFrameLowering.h
35268 views
//===-- SystemZFrameLowering.h - Frame lowering for SystemZ -----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZFRAMELOWERING_H9#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZFRAMELOWERING_H1011#include "MCTargetDesc/SystemZMCTargetDesc.h"12#include "SystemZInstrBuilder.h"13#include "SystemZMachineFunctionInfo.h"14#include "llvm/ADT/IndexedMap.h"15#include "llvm/CodeGen/TargetFrameLowering.h"16#include "llvm/Support/TypeSize.h"1718namespace llvm {19class SystemZSubtarget;2021class SystemZFrameLowering : public TargetFrameLowering {22public:23SystemZFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl,24bool StackReal, unsigned PointerSize);2526static std::unique_ptr<SystemZFrameLowering>27create(const SystemZSubtarget &STI);2829// Override TargetFrameLowering.30bool allocateScavengingFrameIndexesNearIncomingSP(31const MachineFunction &MF) const override {32// SystemZ wants normal register scavenging slots, as close to the stack or33// frame pointer as possible.34// The default implementation assumes an x86-like layout, where the frame35// pointer is at the opposite end of the frame from the stack pointer.36// This meant that when frame pointer elimination was disabled,37// the slots ended up being as close as possible to the incoming38// stack pointer, which is the opposite of what we want on SystemZ.39return false;40}4142bool hasReservedCallFrame(const MachineFunction &MF) const override;4344// Return the offset of the backchain.45virtual unsigned getBackchainOffset(MachineFunction &MF) const = 0;4647// Return the offset of the return address.48virtual int getReturnAddressOffset(MachineFunction &MF) const = 0;4950// Get or create the frame index of where the old frame pointer is stored.51virtual int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const = 0;5253// Return the size of a pointer (in bytes).54unsigned getPointerSize() const { return PointerSize; }5556private:57unsigned PointerSize;58};5960class SystemZELFFrameLowering : public SystemZFrameLowering {61IndexedMap<unsigned> RegSpillOffsets;6263public:64SystemZELFFrameLowering(unsigned PointerSize);6566// Override TargetFrameLowering.67bool68assignCalleeSavedSpillSlots(MachineFunction &MF,69const TargetRegisterInfo *TRI,70std::vector<CalleeSavedInfo> &CSI) const override;71void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,72RegScavenger *RS) const override;73bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,74MachineBasicBlock::iterator MBBI,75ArrayRef<CalleeSavedInfo> CSI,76const TargetRegisterInfo *TRI) const override;77bool78restoreCalleeSavedRegisters(MachineBasicBlock &MBB,79MachineBasicBlock::iterator MBBII,80MutableArrayRef<CalleeSavedInfo> CSI,81const TargetRegisterInfo *TRI) const override;82void processFunctionBeforeFrameFinalized(MachineFunction &MF,83RegScavenger *RS) const override;84void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;85void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;86void inlineStackProbe(MachineFunction &MF,87MachineBasicBlock &PrologMBB) const override;88bool hasFP(const MachineFunction &MF) const override;89StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,90Register &FrameReg) const override;91void92orderFrameObjects(const MachineFunction &MF,93SmallVectorImpl<int> &ObjectsToAllocate) const override;9495// Return the byte offset from the incoming stack pointer of Reg's96// ABI-defined save slot. Return 0 if no slot is defined for Reg. Adjust97// the offset in case MF has packed-stack.98unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const;99100bool usePackedStack(MachineFunction &MF) const;101102// Return the offset of the backchain.103unsigned getBackchainOffset(MachineFunction &MF) const override {104// The back chain is stored topmost with packed-stack.105return usePackedStack(MF) ? SystemZMC::ELFCallFrameSize - 8 : 0;106}107108// Return the offset of the return address.109int getReturnAddressOffset(MachineFunction &MF) const override {110return (usePackedStack(MF) ? -2 : 14) * getPointerSize();111}112113// Get or create the frame index of where the old frame pointer is stored.114int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override;115};116117class SystemZXPLINKFrameLowering : public SystemZFrameLowering {118IndexedMap<unsigned> RegSpillOffsets;119120public:121SystemZXPLINKFrameLowering(unsigned PointerSize);122123bool124assignCalleeSavedSpillSlots(MachineFunction &MF,125const TargetRegisterInfo *TRI,126std::vector<CalleeSavedInfo> &CSI) const override;127128void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,129RegScavenger *RS) const override;130131bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,132MachineBasicBlock::iterator MBBI,133ArrayRef<CalleeSavedInfo> CSI,134const TargetRegisterInfo *TRI) const override;135136bool137restoreCalleeSavedRegisters(MachineBasicBlock &MBB,138MachineBasicBlock::iterator MBBII,139MutableArrayRef<CalleeSavedInfo> CSI,140const TargetRegisterInfo *TRI) const override;141142void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;143144void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;145146void inlineStackProbe(MachineFunction &MF,147MachineBasicBlock &PrologMBB) const override;148149bool hasFP(const MachineFunction &MF) const override;150151void processFunctionBeforeFrameFinalized(MachineFunction &MF,152RegScavenger *RS) const override;153154void determineFrameLayout(MachineFunction &MF) const;155156// Return the offset of the backchain.157unsigned getBackchainOffset(MachineFunction &MF) const override {158// The back chain is always the first element of the frame.159return 0;160}161162// Return the offset of the return address.163int getReturnAddressOffset(MachineFunction &MF) const override {164return 3 * getPointerSize();165}166167// Get or create the frame index of where the old frame pointer is stored.168int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override;169};170} // end namespace llvm171172#endif173174175