LLVM  10.0.0
RISCVFrameLowering.cpp
Go to the documentation of this file.
1 //===-- RISCVFrameLowering.cpp - RISCV 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 RISCV implementation of TargetFrameLowering class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "RISCVFrameLowering.h"
15 #include "RISCVSubtarget.h"
21 #include "llvm/IR/DiagnosticInfo.h"
22 #include "llvm/MC/MCDwarf.h"
23 
24 using namespace llvm;
25 
27  const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
28 
29  const MachineFrameInfo &MFI = MF.getFrameInfo();
30  return MF.getTarget().Options.DisableFramePointerElim(MF) ||
31  RegInfo->needsStackRealignment(MF) || MFI.hasVarSizedObjects() ||
32  MFI.isFrameAddressTaken();
33 }
34 
36  const MachineFrameInfo &MFI = MF.getFrameInfo();
38 
39  return MFI.hasVarSizedObjects() && TRI->needsStackRealignment(MF);
40 }
41 
42 // Determines the size of the frame and maximum call frame size.
43 void RISCVFrameLowering::determineFrameLayout(MachineFunction &MF) const {
44  MachineFrameInfo &MFI = MF.getFrameInfo();
46 
47  // Get the number of bytes to allocate from the FrameInfo.
48  uint64_t FrameSize = MFI.getStackSize();
49 
50  // Get the alignment.
51  unsigned StackAlign = getStackAlignment();
52  if (RI->needsStackRealignment(MF)) {
53  unsigned MaxStackAlign = std::max(StackAlign, MFI.getMaxAlignment());
54  FrameSize += (MaxStackAlign - StackAlign);
55  StackAlign = MaxStackAlign;
56  }
57 
58  // Set Max Call Frame Size
59  uint64_t MaxCallSize = alignTo(MFI.getMaxCallFrameSize(), StackAlign);
60  MFI.setMaxCallFrameSize(MaxCallSize);
61 
62  // Make sure the frame is aligned.
63  FrameSize = alignTo(FrameSize, StackAlign);
64 
65  // Update frame info.
66  MFI.setStackSize(FrameSize);
67 }
68 
69 void RISCVFrameLowering::adjustReg(MachineBasicBlock &MBB,
71  const DebugLoc &DL, Register DestReg,
72  Register SrcReg, int64_t Val,
73  MachineInstr::MIFlag Flag) const {
76 
77  if (DestReg == SrcReg && Val == 0)
78  return;
79 
80  if (isInt<12>(Val)) {
81  BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADDI), DestReg)
82  .addReg(SrcReg)
83  .addImm(Val)
84  .setMIFlag(Flag);
85  } else {
86  unsigned Opc = RISCV::ADD;
87  bool isSub = Val < 0;
88  if (isSub) {
89  Val = -Val;
90  Opc = RISCV::SUB;
91  }
92 
93  Register ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
94  TII->movImm(MBB, MBBI, DL, ScratchReg, Val, Flag);
95  BuildMI(MBB, MBBI, DL, TII->get(Opc), DestReg)
96  .addReg(SrcReg)
97  .addReg(ScratchReg, RegState::Kill)
98  .setMIFlag(Flag);
99  }
100 }
101 
102 // Returns the register used to hold the frame pointer.
103 static Register getFPReg(const RISCVSubtarget &STI) { return RISCV::X8; }
104 
105 // Returns the register used to hold the stack pointer.
106 static Register getSPReg(const RISCVSubtarget &STI) { return RISCV::X2; }
107 
109  MachineBasicBlock &MBB) const {
110  MachineFrameInfo &MFI = MF.getFrameInfo();
111  auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
112  const RISCVRegisterInfo *RI = STI.getRegisterInfo();
113  const RISCVInstrInfo *TII = STI.getInstrInfo();
114  MachineBasicBlock::iterator MBBI = MBB.begin();
115 
116  Register FPReg = getFPReg(STI);
117  Register SPReg = getSPReg(STI);
118  Register BPReg = RISCVABI::getBPReg();
119 
120  // Debug location must be unknown since the first debug location is used
121  // to determine the end of the prologue.
122  DebugLoc DL;
123 
124  // Determine the correct frame layout
125  determineFrameLayout(MF);
126 
127  // FIXME (note copied from Lanai): This appears to be overallocating. Needs
128  // investigation. Get the number of bytes to allocate from the FrameInfo.
129  uint64_t StackSize = MFI.getStackSize();
130 
131  // Early exit if there is no need to allocate on the stack
132  if (StackSize == 0 && !MFI.adjustsStack())
133  return;
134 
135  // If the stack pointer has been marked as reserved, then produce an error if
136  // the frame requires stack allocation
137  if (STI.isRegisterReservedByUser(SPReg))
139  MF.getFunction(), "Stack pointer required, but has been reserved."});
140 
141  uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
142  // Split the SP adjustment to reduce the offsets of callee saved spill.
143  if (FirstSPAdjustAmount)
144  StackSize = FirstSPAdjustAmount;
145 
146  // Allocate space on the stack if necessary.
147  adjustReg(MBB, MBBI, DL, SPReg, SPReg, -StackSize, MachineInstr::FrameSetup);
148 
149  // Emit ".cfi_def_cfa_offset StackSize"
150  unsigned CFIIndex = MF.addFrameInst(
151  MCCFIInstruction::createDefCfaOffset(nullptr, -StackSize));
152  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
153  .addCFIIndex(CFIIndex);
154 
155  // The frame pointer is callee-saved, and code has been generated for us to
156  // save it to the stack. We need to skip over the storing of callee-saved
157  // registers as the frame pointer must be modified after it has been saved
158  // to the stack, not before.
159  // FIXME: assumes exactly one instruction is used to save each callee-saved
160  // register.
161  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
162  std::advance(MBBI, CSI.size());
163 
164  // Iterate over list of callee-saved registers and emit .cfi_offset
165  // directives.
166  for (const auto &Entry : CSI) {
167  int64_t Offset = MFI.getObjectOffset(Entry.getFrameIdx());
168  Register Reg = Entry.getReg();
169  unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
170  nullptr, RI->getDwarfRegNum(Reg, true), Offset));
171  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
172  .addCFIIndex(CFIIndex);
173  }
174 
175  // Generate new FP.
176  if (hasFP(MF)) {
177  if (STI.isRegisterReservedByUser(FPReg))
179  MF.getFunction(), "Frame pointer required, but has been reserved."});
180 
181  adjustReg(MBB, MBBI, DL, FPReg, SPReg,
182  StackSize - RVFI->getVarArgsSaveSize(), MachineInstr::FrameSetup);
183 
184  // Emit ".cfi_def_cfa $fp, 0"
185  unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfa(
186  nullptr, RI->getDwarfRegNum(FPReg, true), 0));
187  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
188  .addCFIIndex(CFIIndex);
189  }
190 
191  // Emit the second SP adjustment after saving callee saved registers.
192  if (FirstSPAdjustAmount) {
193  uint64_t SecondSPAdjustAmount = MFI.getStackSize() - FirstSPAdjustAmount;
194  assert(SecondSPAdjustAmount > 0 &&
195  "SecondSPAdjustAmount should be greater than zero");
196  adjustReg(MBB, MBBI, DL, SPReg, SPReg, -SecondSPAdjustAmount,
198 
199  // If we are using a frame-pointer, and thus emitted ".cfi_def_cfa fp, 0",
200  // don't emit an sp-based .cfi_def_cfa_offset
201  if (!hasFP(MF)) {
202  // Emit ".cfi_def_cfa_offset StackSize"
203  unsigned CFIIndex = MF.addFrameInst(
205  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
206  .addCFIIndex(CFIIndex);
207  }
208  }
209 
210  if (hasFP(MF)) {
211  // Realign Stack
212  const RISCVRegisterInfo *RI = STI.getRegisterInfo();
213  if (RI->needsStackRealignment(MF)) {
214  unsigned MaxAlignment = MFI.getMaxAlignment();
215 
216  const RISCVInstrInfo *TII = STI.getInstrInfo();
217  if (isInt<12>(-(int)MaxAlignment)) {
218  BuildMI(MBB, MBBI, DL, TII->get(RISCV::ANDI), SPReg)
219  .addReg(SPReg)
220  .addImm(-(int)MaxAlignment);
221  } else {
222  unsigned ShiftAmount = countTrailingZeros(MaxAlignment);
223  Register VR =
224  MF.getRegInfo().createVirtualRegister(&RISCV::GPRRegClass);
225  BuildMI(MBB, MBBI, DL, TII->get(RISCV::SRLI), VR)
226  .addReg(SPReg)
227  .addImm(ShiftAmount);
228  BuildMI(MBB, MBBI, DL, TII->get(RISCV::SLLI), SPReg)
229  .addReg(VR)
230  .addImm(ShiftAmount);
231  }
232  // FP will be used to restore the frame in the epilogue, so we need
233  // another base register BP to record SP after re-alignment. SP will
234  // track the current stack after allocating variable sized objects.
235  if (hasBP(MF)) {
236  // move BP, SP
237  BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADDI), BPReg)
238  .addReg(SPReg)
239  .addImm(0);
240  }
241  }
242  }
243 }
244 
246  MachineBasicBlock &MBB) const {
247  const RISCVRegisterInfo *RI = STI.getRegisterInfo();
248  MachineFrameInfo &MFI = MF.getFrameInfo();
249  auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
250  Register FPReg = getFPReg(STI);
251  Register SPReg = getSPReg(STI);
252 
253  // Get the insert location for the epilogue. If there were no terminators in
254  // the block, get the last instruction.
255  MachineBasicBlock::iterator MBBI = MBB.end();
256  DebugLoc DL;
257  if (!MBB.empty()) {
258  MBBI = MBB.getFirstTerminator();
259  if (MBBI == MBB.end())
260  MBBI = MBB.getLastNonDebugInstr();
261  DL = MBBI->getDebugLoc();
262 
263  // If this is not a terminator, the actual insert location should be after the
264  // last instruction.
265  if (!MBBI->isTerminator())
266  MBBI = std::next(MBBI);
267  }
268 
269  // Skip to before the restores of callee-saved registers
270  // FIXME: assumes exactly one instruction is used to restore each
271  // callee-saved register.
272  auto LastFrameDestroy = std::prev(MBBI, MFI.getCalleeSavedInfo().size());
273 
274  uint64_t StackSize = MFI.getStackSize();
275  uint64_t FPOffset = StackSize - RVFI->getVarArgsSaveSize();
276 
277  // Restore the stack pointer using the value of the frame pointer. Only
278  // necessary if the stack pointer was modified, meaning the stack size is
279  // unknown.
280  if (RI->needsStackRealignment(MF) || MFI.hasVarSizedObjects()) {
281  assert(hasFP(MF) && "frame pointer should not have been eliminated");
282  adjustReg(MBB, LastFrameDestroy, DL, SPReg, FPReg, -FPOffset,
284  }
285 
286  uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
287  if (FirstSPAdjustAmount) {
288  uint64_t SecondSPAdjustAmount = MFI.getStackSize() - FirstSPAdjustAmount;
289  assert(SecondSPAdjustAmount > 0 &&
290  "SecondSPAdjustAmount should be greater than zero");
291 
292  adjustReg(MBB, LastFrameDestroy, DL, SPReg, SPReg, SecondSPAdjustAmount,
294  }
295 
296  if (FirstSPAdjustAmount)
297  StackSize = FirstSPAdjustAmount;
298 
299  // Deallocate stack
300  adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackSize, MachineInstr::FrameDestroy);
301 }
302 
304  int FI,
305  unsigned &FrameReg) const {
306  const MachineFrameInfo &MFI = MF.getFrameInfo();
308  const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
309 
310  // Callee-saved registers should be referenced relative to the stack
311  // pointer (positive offset), otherwise use the frame pointer (negative
312  // offset).
313  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
314  int MinCSFI = 0;
315  int MaxCSFI = -1;
316 
317  int Offset = MFI.getObjectOffset(FI) - getOffsetOfLocalArea() +
318  MFI.getOffsetAdjustment();
319 
320  uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
321 
322  if (CSI.size()) {
323  MinCSFI = CSI[0].getFrameIdx();
324  MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
325  }
326 
327  if (FI >= MinCSFI && FI <= MaxCSFI) {
328  FrameReg = RISCV::X2;
329 
330  if (FirstSPAdjustAmount)
331  Offset += FirstSPAdjustAmount;
332  else
333  Offset += MF.getFrameInfo().getStackSize();
334  } else if (RI->needsStackRealignment(MF) && !MFI.isFixedObjectIndex(FI)) {
335  // If the stack was realigned, the frame pointer is set in order to allow
336  // SP to be restored, so we need another base register to record the stack
337  // after realignment.
338  if (hasBP(MF))
339  FrameReg = RISCVABI::getBPReg();
340  else
341  FrameReg = RISCV::X2;
342  Offset += MF.getFrameInfo().getStackSize();
343  } else {
344  FrameReg = RI->getFrameRegister(MF);
345  if (hasFP(MF))
346  Offset += RVFI->getVarArgsSaveSize();
347  else
348  Offset += MF.getFrameInfo().getStackSize();
349  }
350  return Offset;
351 }
352 
354  BitVector &SavedRegs,
355  RegScavenger *RS) const {
357  // Unconditionally spill RA and FP only if the function uses a frame
358  // pointer.
359  if (hasFP(MF)) {
360  SavedRegs.set(RISCV::X1);
361  SavedRegs.set(RISCV::X8);
362  }
363  // Mark BP as used if function has dedicated base pointer.
364  if (hasBP(MF))
365  SavedRegs.set(RISCVABI::getBPReg());
366 
367  // If interrupt is enabled and there are calls in the handler,
368  // unconditionally save all Caller-saved registers and
369  // all FP registers, regardless whether they are used.
370  MachineFrameInfo &MFI = MF.getFrameInfo();
371 
372  if (MF.getFunction().hasFnAttribute("interrupt") && MFI.hasCalls()) {
373 
374  static const MCPhysReg CSRegs[] = { RISCV::X1, /* ra */
375  RISCV::X5, RISCV::X6, RISCV::X7, /* t0-t2 */
376  RISCV::X10, RISCV::X11, /* a0-a1, a2-a7 */
377  RISCV::X12, RISCV::X13, RISCV::X14, RISCV::X15, RISCV::X16, RISCV::X17,
378  RISCV::X28, RISCV::X29, RISCV::X30, RISCV::X31, 0 /* t3-t6 */
379  };
380 
381  for (unsigned i = 0; CSRegs[i]; ++i)
382  SavedRegs.set(CSRegs[i]);
383 
384  if (MF.getSubtarget<RISCVSubtarget>().hasStdExtD() ||
385  MF.getSubtarget<RISCVSubtarget>().hasStdExtF()) {
386 
387  // If interrupt is enabled, this list contains all FP registers.
388  const MCPhysReg * Regs = MF.getRegInfo().getCalleeSavedRegs();
389 
390  for (unsigned i = 0; Regs[i]; ++i)
391  if (RISCV::FPR32RegClass.contains(Regs[i]) ||
392  RISCV::FPR64RegClass.contains(Regs[i]))
393  SavedRegs.set(Regs[i]);
394  }
395  }
396 }
397 
399  MachineFunction &MF, RegScavenger *RS) const {
400  const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
401  MachineFrameInfo &MFI = MF.getFrameInfo();
402  const TargetRegisterClass *RC = &RISCV::GPRRegClass;
403  // estimateStackSize has been observed to under-estimate the final stack
404  // size, so give ourselves wiggle-room by checking for stack size
405  // representable an 11-bit signed field rather than 12-bits.
406  // FIXME: It may be possible to craft a function with a small stack that
407  // still needs an emergency spill slot for branch relaxation. This case
408  // would currently be missed.
409  if (!isInt<11>(MFI.estimateStackSize(MF))) {
410  int RegScavFI = MFI.CreateStackObject(
411  RegInfo->getSpillSize(*RC), RegInfo->getSpillAlignment(*RC), false);
412  RS->addScavengingFrameIndex(RegScavFI);
413  }
414 }
415 
416 // Not preserve stack space within prologue for outgoing variables when the
417 // function contains variable size objects and let eliminateCallFramePseudoInstr
418 // preserve stack space for it.
420  return !MF.getFrameInfo().hasVarSizedObjects();
421 }
422 
423 // Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions.
427  Register SPReg = RISCV::X2;
428  DebugLoc DL = MI->getDebugLoc();
429 
430  if (!hasReservedCallFrame(MF)) {
431  // If space has not been reserved for a call frame, ADJCALLSTACKDOWN and
432  // ADJCALLSTACKUP must be converted to instructions manipulating the stack
433  // pointer. This is necessary when there is a variable length stack
434  // allocation (e.g. alloca), which means it's not possible to allocate
435  // space for outgoing arguments from within the function prologue.
436  int64_t Amount = MI->getOperand(0).getImm();
437 
438  if (Amount != 0) {
439  // Ensure the stack remains aligned after adjustment.
440  Amount = alignSPAdjust(Amount);
441 
442  if (MI->getOpcode() == RISCV::ADJCALLSTACKDOWN)
443  Amount = -Amount;
444 
445  adjustReg(MBB, MI, DL, SPReg, SPReg, Amount, MachineInstr::NoFlags);
446  }
447  }
448 
449  return MBB.erase(MI);
450 }
451 
452 // We would like to split the SP adjustment to reduce prologue/epilogue
453 // as following instructions. In this way, the offset of the callee saved
454 // register could fit in a single store.
455 // add sp,sp,-2032
456 // sw ra,2028(sp)
457 // sw s0,2024(sp)
458 // sw s1,2020(sp)
459 // sw s3,2012(sp)
460 // sw s4,2008(sp)
461 // add sp,sp,-64
462 uint64_t
464  const MachineFrameInfo &MFI = MF.getFrameInfo();
465  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
466  uint64_t StackSize = MFI.getStackSize();
467  uint64_t StackAlign = getStackAlignment();
468 
469  // FIXME: Disable SplitSPAdjust if save-restore libcall enabled when the patch
470  // landing. The callee saved registers will be pushed by the
471  // save-restore libcalls, so we don't have to split the SP adjustment
472  // in this case.
473  //
474  // Return the FirstSPAdjustAmount if the StackSize can not fit in signed
475  // 12-bit and there exists a callee saved register need to be pushed.
476  if (!isInt<12>(StackSize) && (CSI.size() > 0)) {
477  // FirstSPAdjustAmount is choosed as (2048 - StackAlign)
478  // because 2048 will cause sp = sp + 2048 in epilogue split into
479  // multi-instructions. The offset smaller than 2048 can fit in signle
480  // load/store instruction and we have to stick with the stack alignment.
481  // 2048 is 16-byte alignment. The stack alignment for RV32 and RV64 is 16,
482  // for RV32E is 4. So (2048 - StackAlign) will satisfy the stack alignment.
483  return 2048 - StackAlign;
484  }
485  return 0;
486 }
void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
static Register getSPReg(const RISCVSubtarget &STI)
BitVector & set()
Definition: BitVector.h:397
Diagnostic information for unsupported feature in backend.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition: MCDwarf.h:507
unsigned Reg
const RISCVRegisterInfo * getRegisterInfo() const override
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:494
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
return AArch64::GPR64RegClass contains(Reg)
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0&#39;s from the least significant bit to the most stopping at the first 1...
Definition: MathExtras.h:156
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const HexagonInstrInfo * TII
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
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 ...
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
int alignSPAdjust(int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment. ...
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:202
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:139
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This file declares the machine register scavenger class.
bool hasBP(const MachineFunction &MF) const
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
Definition: MCDwarf.h:480
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.
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.
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:223
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
bool isRegisterReservedByUser(Register i) const
bool hasStdExtD() const
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
static Register getFPReg(const RISCVSubtarget &STI)
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
Register getBPReg()
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:163
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
TargetOptions Options
void setMaxCallFrameSize(unsigned S)
int getOffsetAdjustment() const
Return the correction for frame offsets.
const RISCVSubtarget & STI
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
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...
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
const RISCVInstrInfo * getInstrInfo() const override
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
IRTranslator LLVM IR MI
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
bool hasCalls() const
Return true if the current function has any function calls.