LLVM  14.0.0git
AVRFrameLowering.cpp
Go to the documentation of this file.
1 //===-- AVRFrameLowering.cpp - AVR 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 AVR implementation of TargetFrameLowering class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "AVRFrameLowering.h"
14 
15 #include "AVR.h"
16 #include "AVRInstrInfo.h"
17 #include "AVRMachineFunctionInfo.h"
18 #include "AVRTargetMachine.h"
20 
26 #include "llvm/IR/Function.h"
27 
28 #include <vector>
29 
30 namespace llvm {
31 
33  : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(1), -2) {}
34 
36  const MachineFunction &MF) const {
37  // Always simplify call frame pseudo instructions, even when
38  // hasReservedCallFrame is false.
39  return true;
40 }
41 
43  // Reserve call frame memory in function prologue under the following
44  // conditions:
45  // - Y pointer is reserved to be the frame pointer.
46  // - The function does not contain variable sized objects.
47 
48  const MachineFrameInfo &MFI = MF.getFrameInfo();
49  return hasFP(MF) && !MFI.hasVarSizedObjects();
50 }
51 
53  MachineBasicBlock &MBB) const {
55  DebugLoc DL = (MBBI != MBB.end()) ? MBBI->getDebugLoc() : DebugLoc();
56  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
57  const AVRInstrInfo &TII = *STI.getInstrInfo();
59  bool HasFP = hasFP(MF);
60 
61  // Interrupt handlers re-enable interrupts in function entry.
62  if (AFI->isInterruptHandler()) {
63  BuildMI(MBB, MBBI, DL, TII.get(AVR::BSETs))
64  .addImm(0x07)
66  }
67 
68  // Emit special prologue code to save R1, R0 and SREG in interrupt/signal
69  // handlers before saving any other registers.
70  if (AFI->isInterruptOrSignalHandler()) {
71  BuildMI(MBB, MBBI, DL, TII.get(AVR::PUSHWRr))
72  .addReg(AVR::R1R0, RegState::Kill)
74 
75  BuildMI(MBB, MBBI, DL, TII.get(AVR::INRdA), AVR::R0)
76  .addImm(0x3f)
78  BuildMI(MBB, MBBI, DL, TII.get(AVR::PUSHRr))
79  .addReg(AVR::R0, RegState::Kill)
81  BuildMI(MBB, MBBI, DL, TII.get(AVR::EORRdRr))
82  .addReg(AVR::R0, RegState::Define)
83  .addReg(AVR::R0, RegState::Kill)
84  .addReg(AVR::R0, RegState::Kill)
86  BuildMI(MBB, MBBI, DL, TII.get(AVR::EORRdRr))
87  .addReg(AVR::R1, RegState::Define)
88  .addReg(AVR::R1, RegState::Kill)
89  .addReg(AVR::R1, RegState::Kill)
91  }
92 
93  // Early exit if the frame pointer is not needed in this function.
94  if (!HasFP) {
95  return;
96  }
97 
98  const MachineFrameInfo &MFI = MF.getFrameInfo();
99  unsigned FrameSize = MFI.getStackSize() - AFI->getCalleeSavedFrameSize();
100 
101  // Skip the callee-saved push instructions.
102  while (
103  (MBBI != MBB.end()) && MBBI->getFlag(MachineInstr::FrameSetup) &&
104  (MBBI->getOpcode() == AVR::PUSHRr || MBBI->getOpcode() == AVR::PUSHWRr)) {
105  ++MBBI;
106  }
107 
108  // Update Y with the new base value.
109  BuildMI(MBB, MBBI, DL, TII.get(AVR::SPREAD), AVR::R29R28)
110  .addReg(AVR::SP)
112 
113  // Mark the FramePtr as live-in in every block except the entry.
114  for (MachineBasicBlock &MBBJ : llvm::drop_begin(MF)) {
115  MBBJ.addLiveIn(AVR::R29R28);
116  }
117 
118  if (!FrameSize) {
119  return;
120  }
121 
122  // Reserve the necessary frame memory by doing FP -= <size>.
123  unsigned Opcode = (isUInt<6>(FrameSize)) ? AVR::SBIWRdK : AVR::SUBIWRdK;
124 
125  MachineInstr *MI = BuildMI(MBB, MBBI, DL, TII.get(Opcode), AVR::R29R28)
126  .addReg(AVR::R29R28, RegState::Kill)
127  .addImm(FrameSize)
129  // The SREG implicit def is dead.
130  MI->getOperand(3).setIsDead();
131 
132  // Write back R29R28 to SP and temporarily disable interrupts.
133  BuildMI(MBB, MBBI, DL, TII.get(AVR::SPWRITE), AVR::SP)
134  .addReg(AVR::R29R28)
136 }
137 
140 
142 
143  DebugLoc DL = MBBI->getDebugLoc();
144  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
145  const AVRInstrInfo &TII = *STI.getInstrInfo();
146 
147  // Emit special epilogue code to restore R1, R0 and SREG in interrupt/signal
148  // handlers at the very end of the function, just before reti.
149  if (AFI->isInterruptOrSignalHandler()) {
150  BuildMI(MBB, MBBI, DL, TII.get(AVR::POPRd), AVR::R0);
151  BuildMI(MBB, MBBI, DL, TII.get(AVR::OUTARr))
152  .addImm(0x3f)
153  .addReg(AVR::R0, RegState::Kill);
154  BuildMI(MBB, MBBI, DL, TII.get(AVR::POPWRd), AVR::R1R0);
155  }
156 }
157 
159  MachineBasicBlock &MBB) const {
161 
162  // Early exit if the frame pointer is not needed in this function except for
163  // signal/interrupt handlers where special code generation is required.
164  if (!hasFP(MF) && !AFI->isInterruptOrSignalHandler()) {
165  return;
166  }
167 
168  MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
169  assert(MBBI->getDesc().isReturn() &&
170  "Can only insert epilog into returning blocks");
171 
172  DebugLoc DL = MBBI->getDebugLoc();
173  const MachineFrameInfo &MFI = MF.getFrameInfo();
174  unsigned FrameSize = MFI.getStackSize() - AFI->getCalleeSavedFrameSize();
175  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
176  const AVRInstrInfo &TII = *STI.getInstrInfo();
177 
178  // Early exit if there is no need to restore the frame pointer.
179  if (!FrameSize) {
181  return;
182  }
183 
184  // Skip the callee-saved pop instructions.
185  while (MBBI != MBB.begin()) {
186  MachineBasicBlock::iterator PI = std::prev(MBBI);
187  int Opc = PI->getOpcode();
188 
189  if (Opc != AVR::POPRd && Opc != AVR::POPWRd && !PI->isTerminator()) {
190  break;
191  }
192 
193  --MBBI;
194  }
195 
196  unsigned Opcode;
197 
198  // Select the optimal opcode depending on how big it is.
199  if (isUInt<6>(FrameSize)) {
200  Opcode = AVR::ADIWRdK;
201  } else {
202  Opcode = AVR::SUBIWRdK;
203  FrameSize = -FrameSize;
204  }
205 
206  // Restore the frame pointer by doing FP += <size>.
207  MachineInstr *MI = BuildMI(MBB, MBBI, DL, TII.get(Opcode), AVR::R29R28)
208  .addReg(AVR::R29R28, RegState::Kill)
209  .addImm(FrameSize);
210  // The SREG implicit def is dead.
211  MI->getOperand(3).setIsDead();
212 
213  // Write back R29R28 to SP and temporarily disable interrupts.
214  BuildMI(MBB, MBBI, DL, TII.get(AVR::SPWRITE), AVR::SP)
215  .addReg(AVR::R29R28, RegState::Kill);
216 
218 }
219 
220 // Return true if the specified function should have a dedicated frame
221 // pointer register. This is true if the function meets any of the following
222 // conditions:
223 // - a register has been spilled
224 // - has allocas
225 // - input arguments are passed using the stack
226 //
227 // Notice that strictly this is not a frame pointer because it contains SP after
228 // frame allocation instead of having the original SP in function entry.
230  const AVRMachineFunctionInfo *FuncInfo = MF.getInfo<AVRMachineFunctionInfo>();
231 
232  return (FuncInfo->getHasSpills() || FuncInfo->getHasAllocas() ||
233  FuncInfo->getHasStackArgs());
234 }
235 
239  if (CSI.empty()) {
240  return false;
241  }
242 
243  unsigned CalleeFrameSize = 0;
244  DebugLoc DL = MBB.findDebugLoc(MI);
245  MachineFunction &MF = *MBB.getParent();
246  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
247  const TargetInstrInfo &TII = *STI.getInstrInfo();
249 
250  for (unsigned i = CSI.size(); i != 0; --i) {
251  unsigned Reg = CSI[i - 1].getReg();
252  bool IsNotLiveIn = !MBB.isLiveIn(Reg);
253 
254  assert(TRI->getRegSizeInBits(*TRI->getMinimalPhysRegClass(Reg)) == 8 &&
255  "Invalid register size");
256 
257  // Add the callee-saved register as live-in only if it is not already a
258  // live-in register, this usually happens with arguments that are passed
259  // through callee-saved registers.
260  if (IsNotLiveIn) {
261  MBB.addLiveIn(Reg);
262  }
263 
264  // Do not kill the register when it is an input argument.
265  BuildMI(MBB, MI, DL, TII.get(AVR::PUSHRr))
266  .addReg(Reg, getKillRegState(IsNotLiveIn))
268  ++CalleeFrameSize;
269  }
270 
271  AVRFI->setCalleeSavedFrameSize(CalleeFrameSize);
272 
273  return true;
274 }
275 
279  if (CSI.empty()) {
280  return false;
281  }
282 
283  DebugLoc DL = MBB.findDebugLoc(MI);
284  const MachineFunction &MF = *MBB.getParent();
285  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
286  const TargetInstrInfo &TII = *STI.getInstrInfo();
287 
288  for (const CalleeSavedInfo &CCSI : CSI) {
289  unsigned Reg = CCSI.getReg();
290 
291  assert(TRI->getRegSizeInBits(*TRI->getMinimalPhysRegClass(Reg)) == 8 &&
292  "Invalid register size");
293 
294  BuildMI(MBB, MI, DL, TII.get(AVR::POPRd), Reg);
295  }
296 
297  return true;
298 }
299 
300 /// Replace pseudo store instructions that pass arguments through the stack with
301 /// real instructions.
304  const TargetInstrInfo &TII, Register FP) {
305  // Iterate through the BB until we hit a call instruction or we reach the end.
306  for (MachineInstr &MI :
308  if (MI.isCall())
309  break;
310 
311  unsigned Opcode = MI.getOpcode();
312 
313  // Only care of pseudo store instructions where SP is the base pointer.
314  if (Opcode != AVR::STDSPQRr && Opcode != AVR::STDWSPQRr)
315  continue;
316 
317  assert(MI.getOperand(0).getReg() == AVR::SP &&
318  "Invalid register, should be SP!");
319 
320  // Replace this instruction with a regular store. Use Y as the base
321  // pointer since it is guaranteed to contain a copy of SP.
322  unsigned STOpc =
323  (Opcode == AVR::STDWSPQRr) ? AVR::STDWPtrQRr : AVR::STDPtrQRr;
324 
325  MI.setDesc(TII.get(STOpc));
326  MI.getOperand(0).setReg(FP);
327  }
328 }
329 
333  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
334  const AVRInstrInfo &TII = *STI.getInstrInfo();
335 
336  // There is nothing to insert when the call frame memory is allocated during
337  // function entry. Delete the call frame pseudo and replace all pseudo stores
338  // with real store instructions.
339  if (hasReservedCallFrame(MF)) {
340  fixStackStores(MBB, MI, TII, AVR::R29R28);
341  return MBB.erase(MI);
342  }
343 
344  DebugLoc DL = MI->getDebugLoc();
345  unsigned int Opcode = MI->getOpcode();
346  int Amount = TII.getFrameSize(*MI);
347 
348  // ADJCALLSTACKUP and ADJCALLSTACKDOWN are converted to adiw/subi
349  // instructions to read and write the stack pointer in I/O space.
350  if (Amount != 0) {
351  assert(getStackAlign() == Align(1) && "Unsupported stack alignment");
352 
353  if (Opcode == TII.getCallFrameSetupOpcode()) {
354  // Update the stack pointer.
355  // In many cases this can be done far more efficiently by pushing the
356  // relevant values directly to the stack. However, doing that correctly
357  // (in the right order, possibly skipping some empty space for undef
358  // values, etc) is tricky and thus left to be optimized in the future.
359  BuildMI(MBB, MI, DL, TII.get(AVR::SPREAD), AVR::R31R30).addReg(AVR::SP);
360 
361  MachineInstr *New =
362  BuildMI(MBB, MI, DL, TII.get(AVR::SUBIWRdK), AVR::R31R30)
363  .addReg(AVR::R31R30, RegState::Kill)
364  .addImm(Amount);
365  New->getOperand(3).setIsDead();
366 
367  BuildMI(MBB, MI, DL, TII.get(AVR::SPWRITE), AVR::SP).addReg(AVR::R31R30);
368 
369  // Make sure the remaining stack stores are converted to real store
370  // instructions.
371  fixStackStores(MBB, MI, TII, AVR::R31R30);
372  } else {
373  assert(Opcode == TII.getCallFrameDestroyOpcode());
374 
375  // Note that small stack changes could be implemented more efficiently
376  // with a few pop instructions instead of the 8-9 instructions now
377  // required.
378 
379  // Select the best opcode to adjust SP based on the offset size.
380  unsigned addOpcode;
381  if (isUInt<6>(Amount)) {
382  addOpcode = AVR::ADIWRdK;
383  } else {
384  addOpcode = AVR::SUBIWRdK;
385  Amount = -Amount;
386  }
387 
388  // Build the instruction sequence.
389  BuildMI(MBB, MI, DL, TII.get(AVR::SPREAD), AVR::R31R30).addReg(AVR::SP);
390 
391  MachineInstr *New = BuildMI(MBB, MI, DL, TII.get(addOpcode), AVR::R31R30)
392  .addReg(AVR::R31R30, RegState::Kill)
393  .addImm(Amount);
394  New->getOperand(3).setIsDead();
395 
396  BuildMI(MBB, MI, DL, TII.get(AVR::SPWRITE), AVR::SP)
397  .addReg(AVR::R31R30, RegState::Kill);
398  }
399  }
400 
401  return MBB.erase(MI);
402 }
403 
405  BitVector &SavedRegs,
406  RegScavenger *RS) const {
408 
409  // If we have a frame pointer, the Y register needs to be saved as well.
410  if (hasFP(MF)) {
411  SavedRegs.set(AVR::R29);
412  SavedRegs.set(AVR::R28);
413  }
414 }
415 /// The frame analyzer pass.
416 ///
417 /// Scans the function for allocas and used arguments
418 /// that are passed through the stack.
420  static char ID;
422 
424  const MachineFrameInfo &MFI = MF.getFrameInfo();
426 
427  // If there are no fixed frame indexes during this stage it means there
428  // are allocas present in the function.
429  if (MFI.getNumObjects() != MFI.getNumFixedObjects()) {
430  // Check for the type of allocas present in the function. We only care
431  // about fixed size allocas so do not give false positives if only
432  // variable sized allocas are present.
433  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
434  // Variable sized objects have size 0.
435  if (MFI.getObjectSize(i)) {
436  FuncInfo->setHasAllocas(true);
437  break;
438  }
439  }
440  }
441 
442  // If there are fixed frame indexes present, scan the function to see if
443  // they are really being used.
444  if (MFI.getNumFixedObjects() == 0) {
445  return false;
446  }
447 
448  // Ok fixed frame indexes present, now scan the function to see if they
449  // are really being used, otherwise we can ignore them.
450  for (const MachineBasicBlock &BB : MF) {
451  for (const MachineInstr &MI : BB) {
452  int Opcode = MI.getOpcode();
453 
454  if ((Opcode != AVR::LDDRdPtrQ) && (Opcode != AVR::LDDWRdPtrQ) &&
455  (Opcode != AVR::STDPtrQRr) && (Opcode != AVR::STDWPtrQRr)) {
456  continue;
457  }
458 
459  for (const MachineOperand &MO : MI.operands()) {
460  if (!MO.isFI()) {
461  continue;
462  }
463 
464  if (MFI.isFixedObjectIndex(MO.getIndex())) {
465  FuncInfo->setHasStackArgs(true);
466  return false;
467  }
468  }
469  }
470  }
471 
472  return false;
473  }
474 
475  StringRef getPassName() const override { return "AVR Frame Analyzer"; }
476 };
477 
478 char AVRFrameAnalyzer::ID = 0;
479 
480 /// Creates instance of the frame analyzer pass.
482 
483 /// Create the Dynalloca Stack Pointer Save/Restore pass.
484 /// Insert a copy of SP before allocating the dynamic stack memory and restore
485 /// it in function exit to restore the original SP state. This avoids the need
486 /// of reserving a register pair for a frame pointer.
488  static char ID;
490 
492  // Early exit when there are no variable sized objects in the function.
493  if (!MF.getFrameInfo().hasVarSizedObjects()) {
494  return false;
495  }
496 
497  const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
498  const TargetInstrInfo &TII = *STI.getInstrInfo();
499  MachineBasicBlock &EntryMBB = MF.front();
501  DebugLoc DL = EntryMBB.findDebugLoc(MBBI);
502 
503  Register SPCopy =
504  MF.getRegInfo().createVirtualRegister(&AVR::DREGSRegClass);
505 
506  // Create a copy of SP in function entry before any dynallocas are
507  // inserted.
508  BuildMI(EntryMBB, MBBI, DL, TII.get(AVR::COPY), SPCopy).addReg(AVR::SP);
509 
510  // Restore SP in all exit basic blocks.
511  for (MachineBasicBlock &MBB : MF) {
512  // If last instruction is a return instruction, add a restore copy.
513  if (!MBB.empty() && MBB.back().isReturn()) {
514  MBBI = MBB.getLastNonDebugInstr();
515  DL = MBBI->getDebugLoc();
516  BuildMI(MBB, MBBI, DL, TII.get(AVR::COPY), AVR::SP)
517  .addReg(SPCopy, RegState::Kill);
518  }
519  }
520 
521  return true;
522  }
523 
524  StringRef getPassName() const override {
525  return "AVR dynalloca stack pointer save/restore";
526  }
527 };
528 
529 char AVRDynAllocaSR::ID = 0;
530 
531 /// createAVRDynAllocaSRPass - returns an instance of the dynalloca stack
532 /// pointer save/restore pass.
534 
535 } // end of namespace llvm
i
i
Definition: README.txt:29
CmpMode::FP
@ FP
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition: MachineFrameInfo.h:353
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1558
llvm::AVRFrameLowering::hasReservedCallFrame
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition: AVRFrameLowering.cpp:42
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::drop_begin
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:266
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::MachineRegisterInfo::createVirtualRegister
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Definition: MachineRegisterInfo.cpp:158
llvm::MachineFrameInfo::getNumFixedObjects
unsigned getNumFixedObjects() const
Return the number of fixed objects.
Definition: MachineFrameInfo.h:396
llvm::AVRMachineFunctionInfo::setHasStackArgs
void setHasStackArgs(bool B)
Definition: AVRMachineFunctionInfo.h:71
llvm::AVRFrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: AVRFrameLowering.cpp:404
llvm::RegState::Kill
@ Kill
The last use of a register.
Definition: MachineInstrBuilder.h:48
llvm::BitVector::set
BitVector & set()
Definition: BitVector.h:343
llvm::AVRFrameLowering::canSimplifyCallFramePseudos
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
Definition: AVRFrameLowering.cpp:35
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineBasicBlock::findDebugLoc
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions.
Definition: MachineBasicBlock.cpp:1375
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::AVRFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition: AVRFrameLowering.cpp:158
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition: MachineFrameInfo.h:393
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1559
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
MachineRegisterInfo.h
llvm::AVRMachineFunctionInfo::getHasStackArgs
bool getHasStackArgs() const
Definition: AVRMachineFunctionInfo.h:70
llvm::AVRMachineFunctionInfo::setCalleeSavedFrameSize
void setCalleeSavedFrameSize(unsigned Bytes)
Definition: AVRMachineFunctionInfo.h:82
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:828
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:644
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:732
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition: TargetFrameLowering.h:100
llvm::AVRSubtarget
A specific AVR target MCU.
Definition: AVRSubtarget.h:31
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineInstr::FrameSetup
@ FrameSetup
Definition: MachineInstr.h:82
llvm::AVRSubtarget::getInstrInfo
const AVRInstrInfo * getInstrInfo() const override
Definition: AVRSubtarget.h:41
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition: MachineFrameInfo.h:553
llvm::AVRFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: AVRFrameLowering.cpp:229
llvm::AVRMachineFunctionInfo::getCalleeSavedFrameSize
unsigned getCalleeSavedFrameSize() const
Definition: AVRMachineFunctionInfo.h:81
llvm::BitVector
Definition: BitVector.h:74
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::MachineFrameInfo::isFixedObjectIndex
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
Definition: MachineFrameInfo.h:656
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AVRFrameAnalyzer::ID
static char ID
Definition: AVRFrameLowering.cpp:420
llvm::AVRFrameLowering::eliminateCallFramePseudoInstr
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...
Definition: AVRFrameLowering.cpp:330
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:634
llvm::MachineInstrBuilder::setMIFlag
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
Definition: MachineInstrBuilder.h:278
llvm::AVRFrameAnalyzer
The frame analyzer pass.
Definition: AVRFrameLowering.cpp:419
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition: MachineFrameInfo.h:453
AVRFrameLowering.h
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::createAVRDynAllocaSRPass
FunctionPass * createAVRDynAllocaSRPass()
createAVRDynAllocaSRPass - returns an instance of the dynalloca stack pointer save/restore pass.
Definition: AVRFrameLowering.cpp:533
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:593
llvm::AVRMachineFunctionInfo::isInterruptHandler
bool isInterruptHandler() const
Definition: AVRMachineFunctionInfo.h:78
llvm::MachineBasicBlock::getLastNonDebugInstr
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
Definition: MachineBasicBlock.cpp:266
MachineFunctionPass.h
AVRTargetMachine.h
llvm::AVRMachineFunctionInfo::setHasAllocas
void setHasAllocas(bool B)
Definition: AVRMachineFunctionInfo.h:68
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::fixStackStores
static void fixStackStores(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const TargetInstrInfo &TII, Register FP)
Replace pseudo store instructions that pass arguments through the stack with real instructions.
Definition: AVRFrameLowering.cpp:302
llvm::restoreStatusRegister
static void restoreStatusRegister(MachineFunction &MF, MachineBasicBlock &MBB)
Definition: AVRFrameLowering.cpp:138
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:650
AVRMCTargetDesc.h
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::AVRMachineFunctionInfo::getHasSpills
bool getHasSpills() const
Definition: AVRMachineFunctionInfo.h:64
AVRMachineFunctionInfo.h
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::AVRFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition: AVRFrameLowering.cpp:52
llvm::AVRMachineFunctionInfo::getHasAllocas
bool getHasAllocas() const
Definition: AVRMachineFunctionInfo.h:67
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::CalleeSavedInfo
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Definition: MachineFrameInfo.h:34
llvm::createAVRFrameAnalyzerPass
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
Definition: AVRFrameLowering.cpp:481
MachineFrameInfo.h
llvm::RegState::Define
@ Define
Register definition.
Definition: MachineInstrBuilder.h:44
Function.h
llvm::AVRDynAllocaSR::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: AVRFrameLowering.cpp:524
llvm::AVRDynAllocaSR::AVRDynAllocaSR
AVRDynAllocaSR()
Definition: AVRFrameLowering.cpp:489
AVR.h
llvm::AVRMachineFunctionInfo::isInterruptOrSignalHandler
bool isInterruptOrSignalHandler() const
Checks if the function is some form of interrupt service routine.
Definition: AVRMachineFunctionInfo.h:74
llvm::MachineFrameInfo::getNumObjects
unsigned getNumObjects() const
Return the number of objects.
Definition: MachineFrameInfo.h:399
llvm::AVRFrameLowering::spillCalleeSavedRegisters
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...
Definition: AVRFrameLowering.cpp:236
llvm::AVRFrameLowering::AVRFrameLowering
AVRFrameLowering()
Definition: AVRFrameLowering.cpp:32
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition: MachineInstrBuilder.h:508
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:268
MachineInstrBuilder.h
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::AVRInstrInfo
Utilities related to the AVR instruction set.
Definition: AVRInstrInfo.h:64
llvm::AVRDynAllocaSR
Create the Dynalloca Stack Pointer Save/Restore pass.
Definition: AVRFrameLowering.cpp:487
llvm::AVRMachineFunctionInfo
Contains AVR-specific information for each MachineFunction.
Definition: AVRMachineFunctionInfo.h:21
AVRInstrInfo.h
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::TargetFrameLowering::determineCalleeSaves
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: TargetFrameLoweringImpl.cpp:78
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
MachineFunction.h
llvm::AVRFrameAnalyzer::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: AVRFrameLowering.cpp:423
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::AVRDynAllocaSR::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: AVRFrameLowering.cpp:491
llvm::AVRDynAllocaSR::ID
static char ID
Definition: AVRFrameLowering.cpp:488
llvm::AVRFrameAnalyzer::AVRFrameAnalyzer
AVRFrameAnalyzer()
Definition: AVRFrameLowering.cpp:421
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:270
llvm::AVRFrameLowering::restoreCalleeSavedRegisters
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...
Definition: AVRFrameLowering.cpp:276
llvm::AVRFrameAnalyzer::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: AVRFrameLowering.cpp:475