LLVM 20.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 {
20class SystemZSubtarget;
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
57private:
58 unsigned PointerSize;
59};
60
62 IndexedMap<unsigned> RegSpillOffsets;
63
64public:
65 SystemZELFFrameLowering(unsigned PointerSize);
66
67 // Override TargetFrameLowering.
68 bool
71 std::vector<CalleeSavedInfo> &CSI) const override;
73 RegScavenger *RS) const override;
77 const TargetRegisterInfo *TRI) const override;
78 bool
82 const TargetRegisterInfo *TRI) const override;
84 RegScavenger *RS) const override;
85 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
86 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
88 MachineBasicBlock &PrologMBB) const override;
89 bool hasFP(const MachineFunction &MF) const override;
91 Register &FrameReg) const override;
92 void
94 SmallVectorImpl<int> &ObjectsToAllocate) const override;
95
96 // Return the byte offset from the incoming stack pointer of Reg's
97 // ABI-defined save slot. Return 0 if no slot is defined for Reg. Adjust
98 // the offset in case MF has packed-stack.
99 unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const;
100
101 bool usePackedStack(MachineFunction &MF) const;
102
103 // Return the offset of the backchain.
104 unsigned getBackchainOffset(MachineFunction &MF) const override {
105 // The back chain is stored topmost with packed-stack.
106 return usePackedStack(MF) ? SystemZMC::ELFCallFrameSize - 8 : 0;
107 }
108
109 // Return the offset of the return address.
110 int getReturnAddressOffset(MachineFunction &MF) const override {
111 return (usePackedStack(MF) ? -2 : 14) * getPointerSize();
112 }
113
114 // Get or create the frame index of where the old frame pointer is stored.
116};
117
119 IndexedMap<unsigned> RegSpillOffsets;
120
121public:
122 SystemZXPLINKFrameLowering(unsigned PointerSize);
123
124 bool
126 const TargetRegisterInfo *TRI,
127 std::vector<CalleeSavedInfo> &CSI) const override;
128
130 RegScavenger *RS) const override;
131
135 const TargetRegisterInfo *TRI) const override;
136
137 bool
141 const TargetRegisterInfo *TRI) const override;
142
143 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
144
145 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
146
148 MachineBasicBlock &PrologMBB) const override;
149
150 bool hasFP(const MachineFunction &MF) const override;
151
153 RegScavenger *RS) const override;
154
156
157 // Return the offset of the backchain.
158 unsigned getBackchainOffset(MachineFunction &MF) const override {
159 // The back chain is always the first element of the frame.
160 return 0;
161 }
162
163 // Return the offset of the return address.
164 int getReturnAddressOffset(MachineFunction &MF) const override {
165 return 3 * getPointerSize();
166 }
167
168 // Get or create the frame index of where the old frame pointer is stored.
170};
171} // end namespace llvm
172
173#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file implements an indexed map.
unsigned const TargetRegisterInfo * TRI
unsigned Reg
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:33
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
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 hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
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...
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)
virtual int getReturnAddressOffset(MachineFunction &MF) const =0
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
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
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
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
Information about stack frame layout on the target.
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.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39