LLVM 24.0.0git
XtensaFrameLowering.cpp
Go to the documentation of this file.
1//===- XtensaFrameLowering.cpp - Xtensa Frame Information -----------------===//
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// This file contains the Xtensa implementation of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "XtensaFrameLowering.h"
15#include "XtensaInstrInfo.h"
17#include "XtensaSubtarget.h"
23#include "llvm/IR/Function.h"
24
25using namespace llvm;
26
27// Minimum frame = reg save area (4 words) plus static chain (1 word)
28// and the total number of words must be a multiple of 128 bits.
29// Width of a word, in units (bytes).
30#define UNITS_PER_WORD 4
31#define MIN_FRAME_SIZE (8 * UNITS_PER_WORD)
32
33// Both the windowed and the call0 ABI keep SP 16-byte aligned at calls, so
34// outgoing argument areas have to be a multiple of 16 bytes.
37 Align(4)),
38 STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {}
39
41 const MachineFrameInfo &MFI = MF.getFrameInfo();
43}
44
45// Return the size of the frame that emitPrologue() allocates given the stack
46// size that PEI computed. Round up to 16 bytes for both ABIs. Add 32 bytes and
47// realignment in windowed.
48static uint64_t getFrameSize(const MachineFunction &MF, uint64_t StackSize) {
49 uint64_t FrameSize = alignTo(StackSize, 16);
51 FrameSize += 32;
52 uint64_t MaxAlignment = MF.getFrameInfo().getMaxAlign().value();
53 if (MaxAlignment > 32)
54 FrameSize += MaxAlignment;
55 }
56 return FrameSize;
57}
58
60 MachineBasicBlock &MBB) const {
61 assert(&MBB == &MF.front() && "Shrink-wrapping not yet implemented");
64 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
65 MCRegister SP = Xtensa::SP;
66 MCRegister FP = TRI->getFrameRegister(MF);
69
70 // First, compute final stack size.
71 uint64_t PrevStackSize = MFI.getStackSize();
72 uint64_t StackSize = getFrameSize(MF, PrevStackSize);
73
74 if (STI.isWindowedABI()) {
75 uint64_t MaxAlignment = MFI.getMaxAlign().value();
76 if (StackSize <= 32760) {
77 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::ENTRY))
78 .addReg(SP)
79 .addImm(StackSize);
80 } else {
81 // Use a8 as a temporary since a0-a7 may be live.
82 MCRegister TmpReg = Xtensa::A8;
83
84 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::ENTRY))
85 .addReg(SP)
87 TII.loadImmediate(MBB, MBBI, &TmpReg, StackSize - MIN_FRAME_SIZE);
88 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::SUB), TmpReg)
89 .addReg(SP)
90 .addReg(TmpReg);
91 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::MOVSP), SP).addReg(TmpReg);
92 }
93
94 // Calculate how much is needed to have the correct alignment.
95 // Change offset to: alignment + difference.
96 // For example, in case of alignment of 128:
97 // diff_to_128_aligned_address = (128 - (SP & 127))
98 // new_offset = SP + diff_to_128_aligned_address
99 // This is safe to do because we increased the stack size by MaxAlignment.
100 MCRegister Reg, RegMisAlign;
101 if (MaxAlignment > 32) {
102 TII.loadImmediate(MBB, MBBI, &RegMisAlign, MaxAlignment - 1);
103 TII.loadImmediate(MBB, MBBI, &Reg, MaxAlignment);
104 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::AND))
105 .addReg(RegMisAlign, RegState::Define)
106 .addReg(FP)
107 .addReg(RegMisAlign);
108 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::SUB), RegMisAlign)
109 .addReg(Reg)
110 .addReg(RegMisAlign);
111 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::ADD), SP)
112 .addReg(SP)
113 .addReg(RegMisAlign, RegState::Kill);
114 }
115
116 // Store FP register in A8, because FP may be used to pass function
117 // arguments
118 if (XtensaFI->isSaveFrameRegister()) {
119 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::OR), Xtensa::A8)
120 .addReg(FP)
121 .addReg(FP);
122 }
123
124 // if framepointer enabled, set it to point to the stack pointer.
125 if (hasFP(MF)) {
126 // Insert instruction "move $fp, $sp" at this location.
127 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::OR), FP)
128 .addReg(SP)
129 .addReg(SP)
131
133 nullptr, MRI->getDwarfRegNum(FP, true), StackSize);
134 unsigned CFIIndex = MF.addFrameInst(Inst);
135 BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
136 .addCFIIndex(CFIIndex);
137 } else {
138 // emit ".cfi_def_cfa_offset StackSize"
139 unsigned CFIIndex = MF.addFrameInst(
140 MCCFIInstruction::cfiDefCfaOffset(nullptr, StackSize));
141 BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
142 .addCFIIndex(CFIIndex);
143 }
144 } else {
145 // No need to allocate space on the stack.
146 if (StackSize == 0 && !MFI.adjustsStack())
147 return;
148
149 // Adjust stack.
150 TII.adjustStackPtr(SP, -StackSize, MBB, MBBI);
151
152 // emit ".cfi_def_cfa_offset StackSize"
153 unsigned CFIIndex =
154 MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, StackSize));
155 BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
156 .addCFIIndex(CFIIndex);
157
158 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
159
160 if (!CSI.empty()) {
161 // Find the instruction past the last instruction that saves a
162 // callee-saved register to the stack. The callee-saved store
163 // instructions are placed at the begin of basic block, so
164 // iterate over instruction sequence and check that
165 // save instructions are placed correctly.
166 for (unsigned i = 0, e = CSI.size(); i < e; ++i) {
167#ifndef NDEBUG
168 const CalleeSavedInfo &Info = CSI[i];
169 int FI = Info.getFrameIdx();
170 int StoreFI = 0;
171
172 // Checking that the instruction is exactly as expected
173 bool IsStoreInst = false;
174 if (MBBI->getOpcode() == TargetOpcode::COPY && Info.isSpilledToReg()) {
175 Register DstReg = MBBI->getOperand(0).getReg();
176 Register Reg = MBBI->getOperand(1).getReg();
177 IsStoreInst = Info.getDstReg() == DstReg.asMCReg() &&
178 Info.getReg() == Reg.asMCReg();
179 } else {
180 Register Reg = TII.isStoreToStackSlot(*MBBI, StoreFI);
181 IsStoreInst = Reg.asMCReg() == Info.getReg() && StoreFI == FI;
182 }
183 assert(IsStoreInst &&
184 "Unexpected callee-saved register store instruction");
185#endif
186 ++MBBI;
187 }
188
189 // Iterate over list of callee-saved registers and emit .cfi_offset
190 // directives.
191 for (const auto &I : CSI) {
192 int64_t Offset = MFI.getObjectOffset(I.getFrameIdx());
193 MCRegister Reg = I.getReg();
194
195 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
196 nullptr, MRI->getDwarfRegNum(Reg, 1), Offset));
197 BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
198 .addCFIIndex(CFIIndex);
199 }
200 }
201
202 // if framepointer enabled, set it to point to the stack pointer.
203 if (hasFP(MF)) {
204 // Insert instruction "move $fp, $sp" at this location.
205 BuildMI(MBB, MBBI, DL, TII.get(Xtensa::OR), FP)
206 .addReg(SP)
207 .addReg(SP)
209
210 // emit ".cfi_def_cfa_register $fp"
211 unsigned CFIIndex =
213 nullptr, MRI->getDwarfRegNum(FP, true)));
214 BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
215 .addCFIIndex(CFIIndex);
216 }
217 }
218
219 if (StackSize != PrevStackSize) {
220 MFI.setStackSize(StackSize);
221
222 for (int i = MFI.getObjectIndexBegin(); i < MFI.getObjectIndexEnd(); i++) {
223 if (!MFI.isDeadObjectIndex(i)) {
224 int64_t SPOffset = MFI.getObjectOffset(i);
225
226 if (SPOffset < 0)
227 MFI.setObjectOffset(i, SPOffset - StackSize + PrevStackSize);
228 }
229 }
230 }
231}
232
234 MachineBasicBlock &MBB) const {
235 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
236 MachineFrameInfo &MFI = MF.getFrameInfo();
237 DebugLoc DL = MBBI->getDebugLoc();
238 MCRegister SP = Xtensa::SP;
239 MCRegister FP = TRI->getFrameRegister(MF);
240
241 // if framepointer enabled, restore the stack pointer.
242 if (hasFP(MF)) {
243 // We should place restore stack pointer instruction just before
244 // sequence of instructions which restores callee-saved registers.
245 // This sequence is placed at the end of the basic block,
246 // so we should find first instruction of the sequence.
248
249 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
250
251 // Find the first instruction at the end that restores a callee-saved
252 // register.
253 for (unsigned i = 0, e = CSI.size(); i < e; ++i) {
254 --I;
255#ifndef NDEBUG
256 const CalleeSavedInfo &Info = CSI[i];
257 int FI = Info.getFrameIdx();
258 int LoadFI = 0;
259
260 // Checking that the instruction is exactly as expected
261 bool IsRestoreInst = false;
262 if (I->getOpcode() == TargetOpcode::COPY && Info.isSpilledToReg()) {
263 Register Reg = I->getOperand(0).getReg();
264 Register DstReg = I->getOperand(1).getReg();
265 IsRestoreInst = Info.getDstReg() == DstReg.asMCReg() &&
266 Info.getReg() == Reg.asMCReg();
267 } else {
268 Register Reg = TII.isLoadFromStackSlot(*I, LoadFI);
269 IsRestoreInst = Info.getReg() == Reg.asMCReg() && LoadFI == FI;
270 }
271 assert(IsRestoreInst &&
272 "Unexpected callee-saved register restore instruction");
273#endif
274 }
275 if (STI.isWindowedABI()) {
276 // In most architectures, we need to explicitly restore the stack pointer
277 // before returning.
278 //
279 // For Xtensa Windowed Register option, it is not needed to explicitly
280 // restore the stack pointer. Reason being is that on function return,
281 // the window of the caller (including the old stack pointer) gets
282 // restored anyways.
283 } else {
284 BuildMI(MBB, I, DL, TII.get(Xtensa::OR), SP).addReg(FP).addReg(FP);
285 }
286 }
287
288 if (STI.isWindowedABI())
289 return;
290
291 // Get the number of bytes from FrameInfo
292 uint64_t StackSize = MFI.getStackSize();
293
294 if (!StackSize)
295 return;
296
297 // Adjust stack.
298 TII.adjustStackPtr(SP, StackSize, MBB, MBBI);
299}
300
303 ArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
304 MachineFunction *MF = MBB.getParent();
305 MachineBasicBlock &EntryBlock = *(MF->begin());
306
307 if (STI.isWindowedABI())
308 return true;
309
310 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
311 // Add the callee-saved register as live-in. Do not add if the register is
312 // A0 and return address is taken, because it will be implemented in
313 // method XtensaTargetLowering::LowerRETURNADDR.
314 // It's killed at the spill, unless the register is RA and return address
315 // is taken.
316 MCRegister Reg = CSI[i].getReg();
317 bool IsA0AndRetAddrIsTaken =
318 (Reg == Xtensa::A0) && MF->getFrameInfo().isReturnAddressTaken();
319 if (!IsA0AndRetAddrIsTaken)
320 EntryBlock.addLiveIn(Reg);
321
322 // Insert the spill to the stack frame.
323 bool IsKill = !IsA0AndRetAddrIsTaken;
324 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
325 TII.storeRegToStackSlot(EntryBlock, MI, Reg, IsKill, CSI[i].getFrameIdx(),
326 RC, Register());
327 }
328
329 return true;
330}
331
339
340// Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions
344 if (!hasReservedCallFrame(MF)) {
345 int64_t Amount = I->getOperand(0).getImm();
346
347 if (I->getOpcode() == Xtensa::ADJCALLSTACKDOWN)
348 Amount = -Amount;
349
350 TII.adjustStackPtr(Xtensa::SP, Amount, MBB, I);
351 }
352
353 return MBB.erase(I);
354}
355
357 BitVector &SavedRegs,
358 RegScavenger *RS) const {
359 MCRegister FP = TRI->getFrameRegister(MF);
360
361 if (STI.isWindowedABI()) {
362 return;
363 }
364
366
367 // Mark $fp as used if function has dedicated frame pointer.
368 if (hasFP(MF))
369 SavedRegs.set(FP);
370}
371
372// Return an upper bound on the stack size that PEI computes.
373//
374// Estimate from MachineFrameInfo::estimateStackSize() doesn't work as one.
375// That lays out the objects in one order, but alignment and padding can change
376// its estimate. Add the worst-case padding (Align - 1) for each object.
378 const MachineFrameInfo &MFI = MF.getFrameInfo();
380 uint64_t Size = Estimate;
381 for (int I = 0, E = MFI.getObjectIndexEnd(); I != E; ++I)
382 if (!MFI.isDeadObjectIndex(I) &&
384 Size += MFI.getObjectAlign(I).value() - 1;
385 // Round up like PEI does in calculateFrameObjectOffsets().
386 return alignTo(Size, std::max({MFI.getMaxAlign(), TFI->getStackAlign(),
387 TFI->getTransientStackAlign()}));
388}
389
390// Return true if this instruction can borrow its own destination register to
391// compute the frame address. This lets us optimize away the slot for far loads.
394 const TargetRegisterInfo *TRI) {
395 if (MI.getNumExplicitDefs() != 1 || !MI.getOperand(0).isReg())
396 return false;
397 const MachineOperand &Def = MI.getOperand(0);
398 return !Def.isEarlyClobber() && Xtensa::ARRegClass.contains(Def.getReg()) &&
399 !MRI.isReserved(Def.getReg()) && !MI.readsRegister(Def.getReg(), TRI);
400}
401
402// Return true if this frame reference is guaranteed to have an encodable
403// offset. Since the layout isn't known yet, StackSize and FrameSize are upper
404// bounds.
405static bool canEncodeFrameOffset(const MachineInstr &MI, unsigned OpNo,
406 int64_t StackSize, int64_t FrameSize) {
407 const MachineFrameInfo &MFI = MI.getMF()->getFrameInfo();
408 int FI = MI.getOperand(OpNo).getIndex();
409
410 // Possible object offsets are [Min, .. Min + N * Step .., Max].
411 int64_t Min, Max, Step;
412 if (MFI.isFixedObjectIndex(FI) && MFI.getObjectOffset(FI) >= 0) {
413 // Objects above the frame (incoming args) are at a fixed offset from the
414 // top of the frame, whose size is a multiple of 16.
415 Min = MFI.getObjectOffset(FI);
416 Max = Min + FrameSize;
417 Step = 16;
418 } else {
419 // Other objects can be anywhere in [0, StackSize), at a multiple of their
420 // alignment.
421 Step = MFI.getObjectAlign(FI).value();
422 Min = 0;
423 Max = alignDown(std::max<int64_t>(StackSize - MFI.getObjectSize(FI), 0),
424 Step);
425 }
426
427 // Like eliminateFrameIndex(), the offset immediate is the operand right
428 // after the frame index.
429 int64_t Imm = MI.getOperand(OpNo + 1).getImm();
430 auto CanEncode = [&](int64_t Start) {
431 return Xtensa::isValidAddrOffsetForOpcode(MI.getOpcode(), Start + Imm);
432 };
433 // For every possible start, Start + Imm must be in the instruction's range
434 // and a multiple of its offset scale. Two conditions are enough:
435 // 1. Min and Max are in range.
436 // 2. Two adjacent starts (i.e. Min and Min + Step) are valid, because then
437 // every step preserves the alignment requirement.
438 return CanEncode(Min) && CanEncode(Max) && CanEncode(Min + Step);
439}
440
441// Return true if eliminateFrameIndex() may have to calculate a frame offset
442// that doesn't fit in the instruction, which needs a scratch register.
443//
444// This should be correct because eliminateFrameIndex() addresses frame indices
445// from the FP if there is one. Whenever SP moves around calls, an FP is used,
446// so frame offsets never depend on SP adjustments.
448 uint64_t Estimate) {
449 const MachineRegisterInfo &MRI = MF.getRegInfo();
451 uint64_t StackSize = getMaxStackSize(MF, Estimate);
452 uint64_t FrameSize = getFrameSize(MF, StackSize);
453
454 for (const MachineBasicBlock &MBB : MF) {
455 for (const MachineInstr &MI : MBB) {
456 if (MI.isDebugInstr())
457 continue;
458 for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) {
459 if (MI.getOperand(I).isFI() &&
460 !canEncodeFrameOffset(MI, I, StackSize, FrameSize) &&
462 return true;
463 }
464 }
465 }
466 return false;
467}
468
470 MachineFunction &MF, RegScavenger *RS) const {
471 // Set scavenging frame index if necessary.
472 MachineFrameInfo &MFI = MF.getFrameInfo();
473 uint64_t MaxSPOffset = MFI.estimateStackSize(MF);
474 auto *XtensaFI = MF.getInfo<XtensaMachineFunctionInfo>();
475 unsigned ScavSlotsNum = 0;
476
477 // We need a scratch register when there is a frame offset that doesn't fit
478 // in its instruction, or if we have to adjust SP around a call without a
479 // reserved call frame.
480 if (frameOffsetMayNeedScratchReg(MF, MaxSPOffset) ||
481 (!hasReservedCallFrame(MF) && MFI.getMaxCallFrameSize() > 0))
482 ScavSlotsNum = 1;
483
484 // Far branches over 18-bit offset require a spill slot for scratch register.
485 bool IsLargeFunction = !isInt<18>(MF.estimateFunctionSizeInBytes());
486 if (IsLargeFunction)
487 ScavSlotsNum = std::max(ScavSlotsNum, 1u);
488
489 const TargetRegisterClass &RC = Xtensa::ARRegClass;
490 unsigned Size = TRI->getSpillSize(RC);
491 Align Alignment = TRI->getSpillAlign(RC);
492 for (unsigned I = 0; I < ScavSlotsNum; I++) {
493 int FI = MFI.CreateSpillStackObject(Size, Alignment);
494 RS->addScavengingFrameIndex(FI);
495
496 if (IsLargeFunction &&
497 XtensaFI->getBranchRelaxationScratchFrameIndex() == -1)
498 XtensaFI->setBranchRelaxationScratchFrameIndex(FI);
499 }
500}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
uint64_t Imm
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
#define MIN_FRAME_SIZE
static bool canUseDefAsScratchReg(const MachineInstr &MI, const MachineRegisterInfo &MRI, const TargetRegisterInfo *TRI)
static uint64_t getFrameSize(const MachineFunction &MF, uint64_t StackSize)
static bool canEncodeFrameOffset(const MachineInstr &MI, unsigned OpNo, int64_t StackSize, int64_t FrameSize)
static bool frameOffsetMayNeedScratchReg(const MachineFunction &MF, uint64_t Estimate)
static uint64_t getMaxStackSize(const MachineFunction &MF, uint64_t Estimate)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:367
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
A debug info location.
Definition DebugLoc.h:126
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition MCDwarf.h:637
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition MCDwarf.h:630
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition MCDwarf.h:672
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:645
const MCRegisterInfo * getRegisterInfo() const
Definition MCContext.h:411
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return alignment of this function's frame.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
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 int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
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.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
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.
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
int64_t estimateFunctionSizeInBytes()
Return an estimate of the function's code size, taking into account block and function alignment.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
Information about stack frame layout on the target.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
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 ...
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool hasFPImpl(const MachineFunction &MF) const override
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
void emitPrologue(MachineFunction &, MachineBasicBlock &) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
XtensaFrameLowering(const XtensaSubtarget &STI)
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool isValidAddrOffsetForOpcode(unsigned Opcode, int64_t Offset)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition MathExtras.h:546
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82