LLVM 23.0.0git
SystemZFrameLowering.h
Go to the documentation of this file.
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
13#include "SystemZInstrBuilder.h"
15#include "llvm/ADT/IndexedMap.h"
18
19namespace llvm {
21
23public:
24 SystemZFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl,
25 bool StackReal, unsigned PointerSize);
26
27 static std::unique_ptr<SystemZFrameLowering>
28 create(const SystemZSubtarget &STI);
29
30 // Override TargetFrameLowering.
32 const MachineFunction &MF) const override {
33 // SystemZ wants normal register scavenging slots, as close to the stack or
34 // frame pointer as possible.
35 // The default implementation assumes an x86-like layout, where the frame
36 // pointer is at the opposite end of the frame from the stack pointer.
37 // This meant that when frame pointer elimination was disabled,
38 // the slots ended up being as close as possible to the incoming
39 // stack pointer, which is the opposite of what we want on SystemZ.
40 return false;
41 }
42
43 bool hasReservedCallFrame(const MachineFunction &MF) const override;
44
45 // Return the offset of the backchain.
46 virtual unsigned getBackchainOffset(MachineFunction &MF) const = 0;
47
48 // Return the offset of the return address.
49 virtual int getReturnAddressOffset(MachineFunction &MF) const = 0;
50
51 // Get or create the frame index of where the old frame pointer is stored.
53
54 // Return the size of a pointer (in bytes).
55 unsigned getPointerSize() const { return PointerSize; }
56
57 // Emit instructions before MBBI (in MBB) to add NumBytes to Reg.
59 const DebugLoc &DL, Register Reg, int64_t NumBytes,
60 const TargetInstrInfo *TII) const;
61
62private:
63 unsigned PointerSize;
64};
65
67 IndexedMap<unsigned> RegSpillOffsets;
68
69public:
70 SystemZELFFrameLowering(unsigned PointerSize);
71
72 // Override TargetFrameLowering.
73 bool
76 std::vector<CalleeSavedInfo> &CSI) const override;
78 RegScavenger *RS) const override;
82 const TargetRegisterInfo *TRI) const override;
83 bool
87 const TargetRegisterInfo *TRI) const override;
89 RegScavenger *RS) const override;
90 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
91 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
93 MachineBasicBlock &PrologMBB) const override;
95 Register &FrameReg) const override;
96 void
98 SmallVectorImpl<int> &ObjectsToAllocate) const override;
99
100 // Return the byte offset from the incoming stack pointer of Reg's
101 // ABI-defined save slot. Return 0 if no slot is defined for Reg. Adjust
102 // the offset in case MF has packed-stack.
103 unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const;
104
105 bool usePackedStack(MachineFunction &MF) const;
106
107 // Return the offset of the backchain.
108 unsigned getBackchainOffset(MachineFunction &MF) const override {
109 // The back chain is stored topmost with packed-stack.
110 return usePackedStack(MF) ? SystemZMC::ELFCallFrameSize - 8 : 0;
111 }
112
113 // Return the offset of the return address.
114 int getReturnAddressOffset(MachineFunction &MF) const override {
115 return (usePackedStack(MF) ? -2 : 14) * getPointerSize();
116 }
117
118 // Get or create the frame index of where the old frame pointer is stored.
120
121protected:
122 bool hasFPImpl(const MachineFunction &MF) const override;
123};
124
126 IndexedMap<unsigned> RegSpillOffsets;
127
128public:
129 SystemZXPLINKFrameLowering(unsigned PointerSize);
130
131 bool
133 const TargetRegisterInfo *TRI,
134 std::vector<CalleeSavedInfo> &CSI) const override;
135
137 RegScavenger *RS) const override;
138
142 const TargetRegisterInfo *TRI) const override;
143
144 bool
148 const TargetRegisterInfo *TRI) const override;
149
150 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
151
152 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
153
155 MachineBasicBlock &PrologMBB) const override;
156
158 RegScavenger *RS) const override;
159
161
162 // Return the offset of the backchain.
163 unsigned getBackchainOffset(MachineFunction &MF) const override {
164 // The back chain is always the first element of the frame.
165 return 0;
166 }
167
168 // Return the offset of the return address.
169 int getReturnAddressOffset(MachineFunction &MF) const override {
170 return 3 * getPointerSize();
171 }
172
173 // Get or create the frame index of where the old frame pointer is stored.
175
176protected:
177 bool hasFPImpl(const MachineFunction &MF) const override;
178};
179} // end namespace llvm
180
181#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const HexagonInstrInfo * TII
This file implements an indexed map.
Register Reg
Register const TargetRegisterInfo * TRI
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:123
MachineInstrBundleIterator< MachineInstr > iterator
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBII, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
unsigned getBackchainOffset(MachineFunction &MF) const override
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
bool hasFPImpl(const MachineFunction &MF) const override
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
int getReturnAddressOffset(MachineFunction &MF) const override
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool usePackedStack(MachineFunction &MF) const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
SystemZELFFrameLowering(unsigned PointerSize)
unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
virtual int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const =0
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
virtual unsigned getBackchainOffset(MachineFunction &MF) const =0
static std::unique_ptr< SystemZFrameLowering > create(const SystemZSubtarget &STI)
void emitIncrement(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, Register Reg, int64_t NumBytes, const TargetInstrInfo *TII) const
virtual int getReturnAddressOffset(MachineFunction &MF) const =0
SystemZFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl, bool StackReal, unsigned PointerSize)
bool allocateScavengingFrameIndexesNearIncomingSP(const MachineFunction &MF) const override
Control the placement of special register scavenging spill slots when allocating a stack frame.
unsigned getBackchainOffset(MachineFunction &MF) const override
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBII, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void determineFrameLayout(MachineFunction &MF) const
SystemZXPLINKFrameLowering(unsigned PointerSize)
bool hasFPImpl(const MachineFunction &MF) const override
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
int getReturnAddressOffset(MachineFunction &MF) const override
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const int64_t ELFCallFrameSize
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39