LLVM: lib/CodeGen/MachineFrameInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
22#include "llvm/Config/llvm-config.h"
25#include
26
27#define DEBUG_TYPE "codegen"
28
29using namespace llvm;
30
32 if (!StackRealignable)
33 assert(Alignment <= StackAlignment &&
34 "For targets without stack realignment, Alignment is out of limit!");
35 if (MaxAlignment < Alignment)
36 MaxAlignment = Alignment;
37}
38
39
41 Align StackAlignment) {
42 if (!ShouldClamp || Alignment <= StackAlignment)
43 return Alignment;
45 << " exceeds the stack alignment "
47 << " when stack realignment is off" << '\n');
48 return StackAlignment;
49}
50
52 bool IsSpillSlot,
55 assert(Size != 0 && "Cannot allocate zero size stack objects!");
56 Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment);
57 Objects.push_back(StackObject(Size, Alignment, 0, false, IsSpillSlot, Alloca,
58 !IsSpillSlot, StackID));
59 int Index = (int)Objects.size() - NumFixedObjects - 1;
60 assert(Index >= 0 && "Bad frame index!");
63 return Index;
64}
65
67 Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment);
69 int Index = (int)Objects.size() - NumFixedObjects - 1;
71 return Index;
72}
73
76 HasVarSizedObjects = true;
77 Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment);
78 Objects.push_back(StackObject(0, Alignment, 0, false, false, Alloca, true));
80 return (int)Objects.size()-NumFixedObjects-1;
81}
82
84 bool IsImmutable, bool IsAliased) {
85 assert(Size != 0 && "Cannot allocate zero size fixed stack objects!");
86
87
88
89
90
91
94 Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment);
95 Objects.insert(Objects.begin(),
96 StackObject(Size, Alignment, SPOffset, IsImmutable,
97 false, nullptr,
98 IsAliased));
99 return -++NumFixedObjects;
100}
101
103 int64_t SPOffset,
104 bool IsImmutable) {
105 Align Alignment =
107 Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment);
108 Objects.insert(Objects.begin(),
109 StackObject(Size, Alignment, SPOffset, IsImmutable,
110 true, nullptr,
111 false));
112 return -++NumFixedObjects;
113}
114
118
119
120
122 return BV;
123
125 for (const MCPhysReg *CSR = MRI.getCalleeSavedRegs(); CSR && *CSR;
126 ++CSR)
127 BV.set(*CSR);
128
129
131 for (MCPhysReg S : TRI->subregs_inclusive(I.getReg()))
133
134 return BV;
135}
136
142
143
144
145
146
148
150 continue;
153 }
155
157 continue;
160
162
163 MaxAlign = std::max(Alignment, MaxAlign);
164 }
165
168
169
170
171
172
173
174 Align StackAlign;
178 else
180
181
182
183 StackAlign = std::max(StackAlign, MaxAlign);
185}
186
188 MachineFunction &MF, std::vectorMachineBasicBlock::iterator *FrameSDOps) {
190 unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
191 unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
192 assert(FrameSetupOpcode != ~0u && FrameDestroyOpcode != ~0u &&
193 "Can only compute MaxCallFrameSize if Setup/Destroy opcode are known");
194
195 MaxCallFrameSize = 0;
198 unsigned Opcode = MI.getOpcode();
199 if (Opcode == FrameSetupOpcode || Opcode == FrameDestroyOpcode) {
201 MaxCallFrameSize = std::max(MaxCallFrameSize, Size);
202 if (FrameSDOps != nullptr)
203 FrameSDOps->push_back(&MI);
204 }
205 }
206 }
207}
208
210 if (Objects.empty()) return;
211
214
215 OS << "Frame Objects:\n";
216
217 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
218 const StackObject &SO = Objects[i];
219 OS << " fi#" << (int)(i-NumFixedObjects) << ": ";
220
221 if (SO.StackID != 0)
222 OS << "id=" << static_cast<unsigned>(SO.StackID) << ' ';
223
224 if (SO.Size == ~0ULL) {
225 OS << "dead\n";
226 continue;
227 }
228 if (SO.Size == 0)
229 OS << "variable sized";
230 else
231 OS << "size=" << SO.Size;
232 OS << ", align=" << SO.Alignment.value();
233
234 if (i < NumFixedObjects)
235 OS << ", fixed";
236 if (i < NumFixedObjects || SO.SPOffset != -1) {
237 int64_t Off = SO.SPOffset - ValOffset;
238 OS << ", at location [SP";
239 if (Off > 0)
240 OS << "+" << Off;
241 else if (Off < 0)
242 OS << Off;
243 OS << "]";
244 }
245 OS << "\n";
246 }
247 OS << "save/restore points:\n";
248
249 if (!SavePoints.empty()) {
250 OS << "save points:\n";
251
252 for (auto &item : SavePoints)
254 } else
255 OS << "save points are empty\n";
256
257 if (!RestorePoints.empty()) {
258 OS << "restore points:\n";
259 for (auto &item : RestorePoints)
261 } else
262 OS << "restore points are empty\n";
263}
264
265#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
269#endif
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
This file implements the BitVector class.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static Align clampStackAlignment(bool ShouldClamp, Align Alignment, Align StackAlignment)
Clamp the alignment if requested and emit a warning.
Definition MachineFrameInfo.cpp:40
Register const TargetRegisterInfo * TRI
an instruction to allocate memory on the stack
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
Definition MachineFrameInfo.cpp:83
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
LLVM_ABI void computeMaxCallFrameSize(MachineFunction &MF, std::vector< MachineBasicBlock::iterator > *FrameSDOps=nullptr)
Computes the maximum size of a callframe.
Definition MachineFrameInfo.cpp:187
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Definition MachineFrameInfo.cpp:51
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
Definition MachineFrameInfo.cpp:31
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
bool contributesToMaxAlignment(uint8_t StackID)
Should this stack ID be considered in MaxAlignment.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
Definition MachineFrameInfo.cpp:66
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Definition MachineFrameInfo.cpp:137
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
Definition MachineFrameInfo.cpp:115
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
LLVM_ABI void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
Definition MachineFrameInfo.cpp:209
LLVM_ABI int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
Definition MachineFrameInfo.cpp:74
LLVM_ABI void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
Definition MachineFrameInfo.cpp:266
int getObjectIndexEnd() const
Return one past the maximum frame object index.
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
Definition MachineFrameInfo.cpp:102
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Information about stack frame layout on the target.
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.