LLVM  5.0.0
Thumb1FrameLowering.cpp
Go to the documentation of this file.
1 //===-- Thumb1FrameLowering.cpp - Thumb1 Frame Information ----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the Thumb1 implementation of TargetFrameLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Thumb1FrameLowering.h"
15 #include "ARMBaseInstrInfo.h"
16 #include "ARMBaseRegisterInfo.h"
17 #include "ARMMachineFunctionInfo.h"
18 #include "ARMSubtarget.h"
20 #include "Thumb1InstrInfo.h"
21 #include "ThumbRegisterInfo.h"
22 #include "llvm/ADT/BitVector.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SmallSet.h"
25 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/IR/DebugLoc.h"
36 #include "llvm/MC/MCDwarf.h"
37 #include "llvm/Support/Compiler.h"
41 #include <cassert>
42 #include <iterator>
43 #include <vector>
44 
45 using namespace llvm;
46 
48  : ARMFrameLowering(sti) {}
49 
51  const MachineFrameInfo &MFI = MF.getFrameInfo();
52  unsigned CFSize = MFI.getMaxCallFrameSize();
53  // It's not always a good idea to include the call frame as part of the
54  // stack frame. ARM (especially Thumb) has small immediate offset to
55  // address the stack frame. So a large call frame can cause poor codegen
56  // and may even makes it impossible to scavenge a register.
57  if (CFSize >= ((1 << 8) - 1) * 4 / 2) // Half of imm8 * 4
58  return false;
59 
60  return !MFI.hasVarSizedObjects();
61 }
62 
65  const TargetInstrInfo &TII, const DebugLoc &dl,
66  const ThumbRegisterInfo &MRI, int NumBytes,
67  unsigned MIFlags = MachineInstr::NoFlags) {
68  emitThumbRegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes, TII,
69  MRI, MIFlags);
70 }
71 
72 
76  const Thumb1InstrInfo &TII =
77  *static_cast<const Thumb1InstrInfo *>(STI.getInstrInfo());
78  const ThumbRegisterInfo *RegInfo =
79  static_cast<const ThumbRegisterInfo *>(STI.getRegisterInfo());
80  if (!hasReservedCallFrame(MF)) {
81  // If we have alloca, convert as follows:
82  // ADJCALLSTACKDOWN -> sub, sp, sp, amount
83  // ADJCALLSTACKUP -> add, sp, sp, amount
84  MachineInstr &Old = *I;
85  DebugLoc dl = Old.getDebugLoc();
86  unsigned Amount = TII.getFrameSize(Old);
87  if (Amount != 0) {
88  // We need to keep the stack aligned properly. To do this, we round the
89  // amount of space needed for the outgoing arguments up to the next
90  // alignment boundary.
91  Amount = alignTo(Amount, getStackAlignment());
92 
93  // Replace the pseudo instruction with a new instruction...
94  unsigned Opc = Old.getOpcode();
95  if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) {
96  emitSPUpdate(MBB, I, TII, dl, *RegInfo, -Amount);
97  } else {
98  assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP);
99  emitSPUpdate(MBB, I, TII, dl, *RegInfo, Amount);
100  }
101  }
102  }
103  return MBB.erase(I);
104 }
105 
107  MachineBasicBlock &MBB) const {
108  MachineBasicBlock::iterator MBBI = MBB.begin();
109  MachineFrameInfo &MFI = MF.getFrameInfo();
111  MachineModuleInfo &MMI = MF.getMMI();
112  const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
113  const ThumbRegisterInfo *RegInfo =
114  static_cast<const ThumbRegisterInfo *>(STI.getRegisterInfo());
115  const Thumb1InstrInfo &TII =
116  *static_cast<const Thumb1InstrInfo *>(STI.getInstrInfo());
117 
118  unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
119  unsigned NumBytes = MFI.getStackSize();
120  assert(NumBytes >= ArgRegsSaveSize &&
121  "ArgRegsSaveSize is included in NumBytes");
122  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
123 
124  // Debug location must be unknown since the first debug location is used
125  // to determine the end of the prologue.
126  DebugLoc dl;
127 
128  unsigned FramePtr = RegInfo->getFrameRegister(MF);
129  unsigned BasePtr = RegInfo->getBaseRegister();
130  int CFAOffset = 0;
131 
132  // Thumb add/sub sp, imm8 instructions implicitly multiply the offset by 4.
133  NumBytes = (NumBytes + 3) & ~3;
134  MFI.setStackSize(NumBytes);
135 
136  // Determine the sizes of each callee-save spill areas and record which frame
137  // belongs to which callee-save spill areas.
138  unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
139  int FramePtrSpillFI = 0;
140 
141  if (ArgRegsSaveSize) {
142  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -ArgRegsSaveSize,
144  CFAOffset -= ArgRegsSaveSize;
145  unsigned CFIIndex = MF.addFrameInst(
146  MCCFIInstruction::createDefCfaOffset(nullptr, CFAOffset));
147  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
148  .addCFIIndex(CFIIndex)
150  }
151 
152  if (!AFI->hasStackFrame()) {
153  if (NumBytes - ArgRegsSaveSize != 0) {
154  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -(NumBytes - ArgRegsSaveSize),
156  CFAOffset -= NumBytes - ArgRegsSaveSize;
157  unsigned CFIIndex = MF.addFrameInst(
158  MCCFIInstruction::createDefCfaOffset(nullptr, CFAOffset));
159  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
160  .addCFIIndex(CFIIndex)
162  }
163  return;
164  }
165 
166  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
167  unsigned Reg = CSI[i].getReg();
168  int FI = CSI[i].getFrameIdx();
169  switch (Reg) {
170  case ARM::R8:
171  case ARM::R9:
172  case ARM::R10:
173  case ARM::R11:
174  if (STI.splitFramePushPop(MF)) {
175  GPRCS2Size += 4;
176  break;
177  }
179  case ARM::R4:
180  case ARM::R5:
181  case ARM::R6:
182  case ARM::R7:
183  case ARM::LR:
184  if (Reg == FramePtr)
185  FramePtrSpillFI = FI;
186  GPRCS1Size += 4;
187  break;
188  default:
189  DPRCSSize += 8;
190  }
191  }
192 
193  if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPUSH) {
194  ++MBBI;
195  }
196 
197  // Determine starting offsets of spill areas.
198  unsigned DPRCSOffset = NumBytes - ArgRegsSaveSize - (GPRCS1Size + GPRCS2Size + DPRCSSize);
199  unsigned GPRCS2Offset = DPRCSOffset + DPRCSSize;
200  unsigned GPRCS1Offset = GPRCS2Offset + GPRCS2Size;
201  bool HasFP = hasFP(MF);
202  if (HasFP)
203  AFI->setFramePtrSpillOffset(MFI.getObjectOffset(FramePtrSpillFI) +
204  NumBytes);
205  AFI->setGPRCalleeSavedArea1Offset(GPRCS1Offset);
206  AFI->setGPRCalleeSavedArea2Offset(GPRCS2Offset);
207  AFI->setDPRCalleeSavedAreaOffset(DPRCSOffset);
208  NumBytes = DPRCSOffset;
209 
210  int FramePtrOffsetInBlock = 0;
211  unsigned adjustedGPRCS1Size = GPRCS1Size;
212  if (GPRCS1Size > 0 && GPRCS2Size == 0 &&
213  tryFoldSPUpdateIntoPushPop(STI, MF, &*std::prev(MBBI), NumBytes)) {
214  FramePtrOffsetInBlock = NumBytes;
215  adjustedGPRCS1Size += NumBytes;
216  NumBytes = 0;
217  }
218 
219  if (adjustedGPRCS1Size) {
220  CFAOffset -= adjustedGPRCS1Size;
221  unsigned CFIIndex = MF.addFrameInst(
222  MCCFIInstruction::createDefCfaOffset(nullptr, CFAOffset));
223  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
224  .addCFIIndex(CFIIndex)
226  }
227  for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(),
228  E = CSI.end(); I != E; ++I) {
229  unsigned Reg = I->getReg();
230  int FI = I->getFrameIdx();
231  switch (Reg) {
232  case ARM::R8:
233  case ARM::R9:
234  case ARM::R10:
235  case ARM::R11:
236  case ARM::R12:
237  if (STI.splitFramePushPop(MF))
238  break;
240  case ARM::R0:
241  case ARM::R1:
242  case ARM::R2:
243  case ARM::R3:
244  case ARM::R4:
245  case ARM::R5:
246  case ARM::R6:
247  case ARM::R7:
248  case ARM::LR:
249  unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
250  nullptr, MRI->getDwarfRegNum(Reg, true), MFI.getObjectOffset(FI)));
251  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
252  .addCFIIndex(CFIIndex)
254  break;
255  }
256  }
257 
258  // Adjust FP so it point to the stack slot that contains the previous FP.
259  if (HasFP) {
260  FramePtrOffsetInBlock +=
261  MFI.getObjectOffset(FramePtrSpillFI) + GPRCS1Size + ArgRegsSaveSize;
262  BuildMI(MBB, MBBI, dl, TII.get(ARM::tADDrSPi), FramePtr)
263  .addReg(ARM::SP)
264  .addImm(FramePtrOffsetInBlock / 4)
266  .add(predOps(ARMCC::AL));
267  if(FramePtrOffsetInBlock) {
268  CFAOffset += FramePtrOffsetInBlock;
269  unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfa(
270  nullptr, MRI->getDwarfRegNum(FramePtr, true), CFAOffset));
271  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
272  .addCFIIndex(CFIIndex)
274  } else {
275  unsigned CFIIndex =
277  nullptr, MRI->getDwarfRegNum(FramePtr, true)));
278  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
279  .addCFIIndex(CFIIndex)
281  }
282  if (NumBytes > 508)
283  // If offset is > 508 then sp cannot be adjusted in a single instruction,
284  // try restoring from fp instead.
285  AFI->setShouldRestoreSPFromFP(true);
286  }
287 
288  // Skip past the spilling of r8-r11, which could consist of multiple tPUSH
289  // and tMOVr instructions. We don't need to add any call frame information
290  // in-between these instructions, because they do not modify the high
291  // registers.
292  while (true) {
293  MachineBasicBlock::iterator OldMBBI = MBBI;
294  // Skip a run of tMOVr instructions
295  while (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tMOVr)
296  MBBI++;
297  if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPUSH) {
298  MBBI++;
299  } else {
300  // We have reached an instruction which is not a push, so the previous
301  // run of tMOVr instructions (which may have been empty) was not part of
302  // the prologue. Reset MBBI back to the last PUSH of the prologue.
303  MBBI = OldMBBI;
304  break;
305  }
306  }
307 
308  // Emit call frame information for the callee-saved high registers.
309  for (auto &I : CSI) {
310  unsigned Reg = I.getReg();
311  int FI = I.getFrameIdx();
312  switch (Reg) {
313  case ARM::R8:
314  case ARM::R9:
315  case ARM::R10:
316  case ARM::R11:
317  case ARM::R12: {
318  unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
319  nullptr, MRI->getDwarfRegNum(Reg, true), MFI.getObjectOffset(FI)));
320  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
321  .addCFIIndex(CFIIndex)
323  break;
324  }
325  default:
326  break;
327  }
328  }
329 
330  if (NumBytes) {
331  // Insert it after all the callee-save spills.
332  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -NumBytes,
334  if (!HasFP) {
335  CFAOffset -= NumBytes;
336  unsigned CFIIndex = MF.addFrameInst(
337  MCCFIInstruction::createDefCfaOffset(nullptr, CFAOffset));
338  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
339  .addCFIIndex(CFIIndex)
341  }
342  }
343 
344  if (STI.isTargetELF() && HasFP)
346  AFI->getFramePtrSpillOffset());
347 
348  AFI->setGPRCalleeSavedArea1Size(GPRCS1Size);
349  AFI->setGPRCalleeSavedArea2Size(GPRCS2Size);
350  AFI->setDPRCalleeSavedAreaSize(DPRCSSize);
351 
352  // Thumb1 does not currently support dynamic stack realignment. Report a
353  // fatal error rather then silently generate bad code.
354  if (RegInfo->needsStackRealignment(MF))
355  report_fatal_error("Dynamic stack realignment not supported for thumb1.");
356 
357  // If we need a base pointer, set it up here. It's whatever the value
358  // of the stack pointer is at this point. Any variable size objects
359  // will be allocated after this, so we can still use the base pointer
360  // to reference locals.
361  if (RegInfo->hasBasePointer(MF))
362  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), BasePtr)
363  .addReg(ARM::SP)
364  .add(predOps(ARMCC::AL));
365 
366  // If the frame has variable sized objects then the epilogue must restore
367  // the sp from fp. We can assume there's an FP here since hasFP already
368  // checks for hasVarSizedObjects.
369  if (MFI.hasVarSizedObjects())
370  AFI->setShouldRestoreSPFromFP(true);
371 
372  // In some cases, virtual registers have been introduced, e.g. by uses of
373  // emitThumbRegPlusImmInReg.
375 }
376 
377 static bool isCSRestore(MachineInstr &MI, const MCPhysReg *CSRegs) {
378  if (MI.getOpcode() == ARM::tLDRspi && MI.getOperand(1).isFI() &&
379  isCalleeSavedRegister(MI.getOperand(0).getReg(), CSRegs))
380  return true;
381  else if (MI.getOpcode() == ARM::tPOP) {
382  return true;
383  } else if (MI.getOpcode() == ARM::tMOVr) {
384  unsigned Dst = MI.getOperand(0).getReg();
385  unsigned Src = MI.getOperand(1).getReg();
386  return ((ARM::tGPRRegClass.contains(Src) || Src == ARM::LR) &&
387  ARM::hGPRRegClass.contains(Dst));
388  }
389  return false;
390 }
391 
393  MachineBasicBlock &MBB) const {
395  DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
396  MachineFrameInfo &MFI = MF.getFrameInfo();
398  const ThumbRegisterInfo *RegInfo =
399  static_cast<const ThumbRegisterInfo *>(STI.getRegisterInfo());
400  const Thumb1InstrInfo &TII =
401  *static_cast<const Thumb1InstrInfo *>(STI.getInstrInfo());
402 
403  unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
404  int NumBytes = (int)MFI.getStackSize();
405  assert((unsigned)NumBytes >= ArgRegsSaveSize &&
406  "ArgRegsSaveSize is included in NumBytes");
407  const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
408  unsigned FramePtr = RegInfo->getFrameRegister(MF);
409 
410  if (!AFI->hasStackFrame()) {
411  if (NumBytes - ArgRegsSaveSize != 0)
412  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, NumBytes - ArgRegsSaveSize);
413  } else {
414  // Unwind MBBI to point to first LDR / VLDRD.
415  if (MBBI != MBB.begin()) {
416  do
417  --MBBI;
418  while (MBBI != MBB.begin() && isCSRestore(*MBBI, CSRegs));
419  if (!isCSRestore(*MBBI, CSRegs))
420  ++MBBI;
421  }
422 
423  // Move SP to start of FP callee save spill area.
424  NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
427  ArgRegsSaveSize);
428 
429  if (AFI->shouldRestoreSPFromFP()) {
430  NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
431  // Reset SP based on frame pointer only if the stack frame extends beyond
432  // frame pointer stack slot, the target is ELF and the function has FP, or
433  // the target uses var sized objects.
434  if (NumBytes) {
435  assert(!MFI.getPristineRegs(MF).test(ARM::R4) &&
436  "No scratch register to restore SP from FP!");
437  emitThumbRegPlusImmediate(MBB, MBBI, dl, ARM::R4, FramePtr, -NumBytes,
438  TII, *RegInfo);
439  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
440  .addReg(ARM::R4)
441  .add(predOps(ARMCC::AL));
442  } else
443  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
444  .addReg(FramePtr)
445  .add(predOps(ARMCC::AL));
446  } else {
447  if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tBX_RET &&
448  &MBB.front() != &*MBBI && std::prev(MBBI)->getOpcode() == ARM::tPOP) {
449  MachineBasicBlock::iterator PMBBI = std::prev(MBBI);
450  if (!tryFoldSPUpdateIntoPushPop(STI, MF, &*PMBBI, NumBytes))
451  emitSPUpdate(MBB, PMBBI, TII, dl, *RegInfo, NumBytes);
452  } else if (!tryFoldSPUpdateIntoPushPop(STI, MF, &*MBBI, NumBytes))
453  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, NumBytes);
454  }
455  }
456 
457  if (needPopSpecialFixUp(MF)) {
458  bool Done = emitPopSpecialFixUp(MBB, /* DoIt */ true);
459  (void)Done;
460  assert(Done && "Emission of the special fixup failed!?");
461  }
462 }
463 
465  if (!needPopSpecialFixUp(*MBB.getParent()))
466  return true;
467 
468  MachineBasicBlock *TmpMBB = const_cast<MachineBasicBlock *>(&MBB);
469  return emitPopSpecialFixUp(*TmpMBB, /* DoIt */ false);
470 }
471 
472 bool Thumb1FrameLowering::needPopSpecialFixUp(const MachineFunction &MF) const {
473  ARMFunctionInfo *AFI =
474  const_cast<MachineFunction *>(&MF)->getInfo<ARMFunctionInfo>();
475  if (AFI->getArgRegsSaveSize())
476  return true;
477 
478  // LR cannot be encoded with Thumb1, i.e., it requires a special fix-up.
479  for (const CalleeSavedInfo &CSI : MF.getFrameInfo().getCalleeSavedInfo())
480  if (CSI.getReg() == ARM::LR)
481  return true;
482 
483  return false;
484 }
485 
486 bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
487  bool DoIt) const {
488  MachineFunction &MF = *MBB.getParent();
490  unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
491  const TargetInstrInfo &TII = *STI.getInstrInfo();
492  const ThumbRegisterInfo *RegInfo =
493  static_cast<const ThumbRegisterInfo *>(STI.getRegisterInfo());
494 
495  // If MBBI is a return instruction, or is a tPOP followed by a return
496  // instruction in the successor BB, we may be able to directly restore
497  // LR in the PC.
498  // This is only possible with v5T ops (v4T can't change the Thumb bit via
499  // a POP PC instruction), and only if we do not need to emit any SP update.
500  // Otherwise, we need a temporary register to pop the value
501  // and copy that value into LR.
502  auto MBBI = MBB.getFirstTerminator();
503  bool CanRestoreDirectly = STI.hasV5TOps() && !ArgRegsSaveSize;
504  if (CanRestoreDirectly) {
505  if (MBBI != MBB.end() && MBBI->getOpcode() != ARM::tB)
506  CanRestoreDirectly = (MBBI->getOpcode() == ARM::tBX_RET ||
507  MBBI->getOpcode() == ARM::tPOP_RET);
508  else {
509  auto MBBI_prev = MBBI;
510  MBBI_prev--;
511  assert(MBBI_prev->getOpcode() == ARM::tPOP);
512  assert(MBB.succ_size() == 1);
513  if ((*MBB.succ_begin())->begin()->getOpcode() == ARM::tBX_RET)
514  MBBI = MBBI_prev; // Replace the final tPOP with a tPOP_RET.
515  else
516  CanRestoreDirectly = false;
517  }
518  }
519 
520  if (CanRestoreDirectly) {
521  if (!DoIt || MBBI->getOpcode() == ARM::tPOP_RET)
522  return true;
523  MachineInstrBuilder MIB =
524  BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII.get(ARM::tPOP_RET))
525  .add(predOps(ARMCC::AL));
526  // Copy implicit ops and popped registers, if any.
527  for (auto MO: MBBI->operands())
528  if (MO.isReg() && (MO.isImplicit() || MO.isDef()))
529  MIB.add(MO);
530  MIB.addReg(ARM::PC, RegState::Define);
531  // Erase the old instruction (tBX_RET or tPOP).
532  MBB.erase(MBBI);
533  return true;
534  }
535 
536  // Look for a temporary register to use.
537  // First, compute the liveness information.
538  const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
539  LivePhysRegs UsedRegs(TRI);
540  UsedRegs.addLiveOuts(MBB);
541  // The semantic of pristines changed recently and now,
542  // the callee-saved registers that are touched in the function
543  // are not part of the pristines set anymore.
544  // Add those callee-saved now.
545  const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
546  for (unsigned i = 0; CSRegs[i]; ++i)
547  UsedRegs.addReg(CSRegs[i]);
548 
549  DebugLoc dl = DebugLoc();
550  if (MBBI != MBB.end()) {
551  dl = MBBI->getDebugLoc();
552  auto InstUpToMBBI = MBB.end();
553  while (InstUpToMBBI != MBBI)
554  // The pre-decrement is on purpose here.
555  // We want to have the liveness right before MBBI.
556  UsedRegs.stepBackward(*--InstUpToMBBI);
557  }
558 
559  // Look for a register that can be directly use in the POP.
560  unsigned PopReg = 0;
561  // And some temporary register, just in case.
562  unsigned TemporaryReg = 0;
563  BitVector PopFriendly =
564  TRI.getAllocatableSet(MF, TRI.getRegClass(ARM::tGPRRegClassID));
565  assert(PopFriendly.any() && "No allocatable pop-friendly register?!");
566  // Rebuild the GPRs from the high registers because they are removed
567  // form the GPR reg class for thumb1.
568  BitVector GPRsNoLRSP =
569  TRI.getAllocatableSet(MF, TRI.getRegClass(ARM::hGPRRegClassID));
570  GPRsNoLRSP |= PopFriendly;
571  GPRsNoLRSP.reset(ARM::LR);
572  GPRsNoLRSP.reset(ARM::SP);
573  GPRsNoLRSP.reset(ARM::PC);
574  for (unsigned Register : GPRsNoLRSP.set_bits()) {
575  if (!UsedRegs.contains(Register)) {
576  // Remember the first pop-friendly register and exit.
577  if (PopFriendly.test(Register)) {
578  PopReg = Register;
579  TemporaryReg = 0;
580  break;
581  }
582  // Otherwise, remember that the register will be available to
583  // save a pop-friendly register.
584  TemporaryReg = Register;
585  }
586  }
587 
588  if (!DoIt && !PopReg && !TemporaryReg)
589  return false;
590 
591  assert((PopReg || TemporaryReg) && "Cannot get LR");
592 
593  if (TemporaryReg) {
594  assert(!PopReg && "Unnecessary MOV is about to be inserted");
595  PopReg = PopFriendly.find_first();
596  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr))
597  .addReg(TemporaryReg, RegState::Define)
598  .addReg(PopReg, RegState::Kill)
599  .add(predOps(ARMCC::AL));
600  }
601 
602  if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPOP_RET) {
603  // We couldn't use the direct restoration above, so
604  // perform the opposite conversion: tPOP_RET to tPOP.
605  MachineInstrBuilder MIB =
606  BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII.get(ARM::tPOP))
607  .add(predOps(ARMCC::AL));
608  bool Popped = false;
609  for (auto MO: MBBI->operands())
610  if (MO.isReg() && (MO.isImplicit() || MO.isDef()) &&
611  MO.getReg() != ARM::PC) {
612  MIB.add(MO);
613  if (!MO.isImplicit())
614  Popped = true;
615  }
616  // Is there anything left to pop?
617  if (!Popped)
618  MBB.erase(MIB.getInstr());
619  // Erase the old instruction.
620  MBB.erase(MBBI);
621  MBBI = BuildMI(MBB, MBB.end(), dl, TII.get(ARM::tBX_RET))
622  .add(predOps(ARMCC::AL));
623  }
624 
625  assert(PopReg && "Do not know how to get LR");
626  BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP))
628  .addReg(PopReg, RegState::Define);
629 
630  emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, ArgRegsSaveSize);
631 
632  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr))
633  .addReg(ARM::LR, RegState::Define)
634  .addReg(PopReg, RegState::Kill)
635  .add(predOps(ARMCC::AL));
636 
637  if (TemporaryReg)
638  BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr))
639  .addReg(PopReg, RegState::Define)
640  .addReg(TemporaryReg, RegState::Kill)
641  .add(predOps(ARMCC::AL));
642 
643  return true;
644 }
645 
646 // Return the first iteraror after CurrentReg which is present in EnabledRegs,
647 // or OrderEnd if no further registers are in that set. This does not advance
648 // the iterator fiorst, so returns CurrentReg if it is in EnabledRegs.
649 template <unsigned SetSize>
650 static const unsigned *
651 findNextOrderedReg(const unsigned *CurrentReg,
652  SmallSet<unsigned, SetSize> &EnabledRegs,
653  const unsigned *OrderEnd) {
654  while (CurrentReg != OrderEnd && !EnabledRegs.count(*CurrentReg))
655  ++CurrentReg;
656  return CurrentReg;
657 }
658 
662  const std::vector<CalleeSavedInfo> &CSI,
663  const TargetRegisterInfo *TRI) const {
664  if (CSI.empty())
665  return false;
666 
667  DebugLoc DL;
668  const TargetInstrInfo &TII = *STI.getInstrInfo();
669  MachineFunction &MF = *MBB.getParent();
670  const ARMBaseRegisterInfo *RegInfo = static_cast<const ARMBaseRegisterInfo *>(
672 
673  SmallSet<unsigned, 9> LoRegsToSave; // r0-r7, lr
674  SmallSet<unsigned, 4> HiRegsToSave; // r8-r11
675  SmallSet<unsigned, 9> CopyRegs; // Registers which can be used after pushing
676  // LoRegs for saving HiRegs.
677 
678  for (unsigned i = CSI.size(); i != 0; --i) {
679  unsigned Reg = CSI[i-1].getReg();
680 
681  if (ARM::tGPRRegClass.contains(Reg) || Reg == ARM::LR) {
682  LoRegsToSave.insert(Reg);
683  } else if (ARM::hGPRRegClass.contains(Reg) && Reg != ARM::LR) {
684  HiRegsToSave.insert(Reg);
685  } else {
686  llvm_unreachable("callee-saved register of unexpected class");
687  }
688 
689  if ((ARM::tGPRRegClass.contains(Reg) || Reg == ARM::LR) &&
690  !MF.getRegInfo().isLiveIn(Reg) &&
691  !(hasFP(MF) && Reg == RegInfo->getFrameRegister(MF)))
692  CopyRegs.insert(Reg);
693  }
694 
695  // Unused argument registers can be used for the high register saving.
696  for (unsigned ArgReg : {ARM::R0, ARM::R1, ARM::R2, ARM::R3})
697  if (!MF.getRegInfo().isLiveIn(ArgReg))
698  CopyRegs.insert(ArgReg);
699 
700  // Push the low registers and lr
701  const MachineRegisterInfo &MRI = MF.getRegInfo();
702  if (!LoRegsToSave.empty()) {
703  MachineInstrBuilder MIB =
704  BuildMI(MBB, MI, DL, TII.get(ARM::tPUSH)).add(predOps(ARMCC::AL));
705  for (unsigned Reg : {ARM::R4, ARM::R5, ARM::R6, ARM::R7, ARM::LR}) {
706  if (LoRegsToSave.count(Reg)) {
707  bool isKill = !MRI.isLiveIn(Reg);
708  if (isKill && !MRI.isReserved(Reg))
709  MBB.addLiveIn(Reg);
710 
711  MIB.addReg(Reg, getKillRegState(isKill));
712  }
713  }
715  }
716 
717  // Push the high registers. There are no store instructions that can access
718  // these registers directly, so we have to move them to low registers, and
719  // push them. This might take multiple pushes, as it is possible for there to
720  // be fewer low registers available than high registers which need saving.
721 
722  // These are in reverse order so that in the case where we need to use
723  // multiple PUSH instructions, the order of the registers on the stack still
724  // matches the unwind info. They need to be swicthed back to ascending order
725  // before adding to the PUSH instruction.
726  static const unsigned AllCopyRegs[] = {ARM::LR, ARM::R7, ARM::R6,
727  ARM::R5, ARM::R4, ARM::R3,
728  ARM::R2, ARM::R1, ARM::R0};
729  static const unsigned AllHighRegs[] = {ARM::R11, ARM::R10, ARM::R9, ARM::R8};
730 
731  const unsigned *AllCopyRegsEnd = std::end(AllCopyRegs);
732  const unsigned *AllHighRegsEnd = std::end(AllHighRegs);
733 
734  // Find the first register to save.
735  const unsigned *HiRegToSave = findNextOrderedReg(
736  std::begin(AllHighRegs), HiRegsToSave, AllHighRegsEnd);
737 
738  while (HiRegToSave != AllHighRegsEnd) {
739  // Find the first low register to use.
740  const unsigned *CopyReg =
741  findNextOrderedReg(std::begin(AllCopyRegs), CopyRegs, AllCopyRegsEnd);
742 
743  // Create the PUSH, but don't insert it yet (the MOVs need to come first).
744  MachineInstrBuilder PushMIB =
745  BuildMI(MF, DL, TII.get(ARM::tPUSH)).add(predOps(ARMCC::AL));
746 
747  SmallVector<unsigned, 4> RegsToPush;
748  while (HiRegToSave != AllHighRegsEnd && CopyReg != AllCopyRegsEnd) {
749  if (HiRegsToSave.count(*HiRegToSave)) {
750  bool isKill = !MRI.isLiveIn(*HiRegToSave);
751  if (isKill && !MRI.isReserved(*HiRegToSave))
752  MBB.addLiveIn(*HiRegToSave);
753 
754  // Emit a MOV from the high reg to the low reg.
755  BuildMI(MBB, MI, DL, TII.get(ARM::tMOVr))
756  .addReg(*CopyReg, RegState::Define)
757  .addReg(*HiRegToSave, getKillRegState(isKill))
758  .add(predOps(ARMCC::AL));
759 
760  // Record the register that must be added to the PUSH.
761  RegsToPush.push_back(*CopyReg);
762 
763  CopyReg = findNextOrderedReg(++CopyReg, CopyRegs, AllCopyRegsEnd);
764  HiRegToSave =
765  findNextOrderedReg(++HiRegToSave, HiRegsToSave, AllHighRegsEnd);
766  }
767  }
768 
769  // Add the low registers to the PUSH, in ascending order.
770  for (unsigned Reg : llvm::reverse(RegsToPush))
771  PushMIB.addReg(Reg, RegState::Kill);
772 
773  // Insert the PUSH instruction after the MOVs.
774  MBB.insert(MI, PushMIB);
775  }
776 
777  return true;
778 }
779 
783  const std::vector<CalleeSavedInfo> &CSI,
784  const TargetRegisterInfo *TRI) const {
785  if (CSI.empty())
786  return false;
787 
788  MachineFunction &MF = *MBB.getParent();
790  const TargetInstrInfo &TII = *STI.getInstrInfo();
791  const ARMBaseRegisterInfo *RegInfo = static_cast<const ARMBaseRegisterInfo *>(
793 
794  bool isVarArg = AFI->getArgRegsSaveSize() > 0;
795  DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc();
796 
797  SmallSet<unsigned, 9> LoRegsToRestore;
798  SmallSet<unsigned, 4> HiRegsToRestore;
799  // Low registers (r0-r7) which can be used to restore the high registers.
800  SmallSet<unsigned, 9> CopyRegs;
801 
802  for (CalleeSavedInfo I : CSI) {
803  unsigned Reg = I.getReg();
804 
805  if (ARM::tGPRRegClass.contains(Reg) || Reg == ARM::LR) {
806  LoRegsToRestore.insert(Reg);
807  } else if (ARM::hGPRRegClass.contains(Reg) && Reg != ARM::LR) {
808  HiRegsToRestore.insert(Reg);
809  } else {
810  llvm_unreachable("callee-saved register of unexpected class");
811  }
812 
813  // If this is a low register not used as the frame pointer, we may want to
814  // use it for restoring the high registers.
815  if ((ARM::tGPRRegClass.contains(Reg)) &&
816  !(hasFP(MF) && Reg == RegInfo->getFrameRegister(MF)))
817  CopyRegs.insert(Reg);
818  }
819 
820  // If this is a return block, we may be able to use some unused return value
821  // registers for restoring the high regs.
822  auto Terminator = MBB.getFirstTerminator();
823  if (Terminator != MBB.end() && Terminator->getOpcode() == ARM::tBX_RET) {
824  CopyRegs.insert(ARM::R0);
825  CopyRegs.insert(ARM::R1);
826  CopyRegs.insert(ARM::R2);
827  CopyRegs.insert(ARM::R3);
828  for (auto Op : Terminator->implicit_operands()) {
829  if (Op.isReg())
830  CopyRegs.erase(Op.getReg());
831  }
832  }
833 
834  static const unsigned AllCopyRegs[] = {ARM::R0, ARM::R1, ARM::R2, ARM::R3,
835  ARM::R4, ARM::R5, ARM::R6, ARM::R7};
836  static const unsigned AllHighRegs[] = {ARM::R8, ARM::R9, ARM::R10, ARM::R11};
837 
838  const unsigned *AllCopyRegsEnd = std::end(AllCopyRegs);
839  const unsigned *AllHighRegsEnd = std::end(AllHighRegs);
840 
841  // Find the first register to restore.
842  auto HiRegToRestore = findNextOrderedReg(std::begin(AllHighRegs),
843  HiRegsToRestore, AllHighRegsEnd);
844 
845  while (HiRegToRestore != AllHighRegsEnd) {
846  assert(!CopyRegs.empty());
847  // Find the first low register to use.
848  auto CopyReg =
849  findNextOrderedReg(std::begin(AllCopyRegs), CopyRegs, AllCopyRegsEnd);
850 
851  // Create the POP instruction.
852  MachineInstrBuilder PopMIB =
853  BuildMI(MBB, MI, DL, TII.get(ARM::tPOP)).add(predOps(ARMCC::AL));
854 
855  while (HiRegToRestore != AllHighRegsEnd && CopyReg != AllCopyRegsEnd) {
856  // Add the low register to the POP.
857  PopMIB.addReg(*CopyReg, RegState::Define);
858 
859  // Create the MOV from low to high register.
860  BuildMI(MBB, MI, DL, TII.get(ARM::tMOVr))
861  .addReg(*HiRegToRestore, RegState::Define)
862  .addReg(*CopyReg, RegState::Kill)
863  .add(predOps(ARMCC::AL));
864 
865  CopyReg = findNextOrderedReg(++CopyReg, CopyRegs, AllCopyRegsEnd);
866  HiRegToRestore =
867  findNextOrderedReg(++HiRegToRestore, HiRegsToRestore, AllHighRegsEnd);
868  }
869  }
870 
871  MachineInstrBuilder MIB =
872  BuildMI(MF, DL, TII.get(ARM::tPOP)).add(predOps(ARMCC::AL));
873 
874  bool NeedsPop = false;
875  for (unsigned i = CSI.size(); i != 0; --i) {
876  unsigned Reg = CSI[i-1].getReg();
877 
878  // High registers (excluding lr) have already been dealt with
879  if (!(ARM::tGPRRegClass.contains(Reg) || Reg == ARM::LR))
880  continue;
881 
882  if (Reg == ARM::LR) {
883  if (MBB.succ_empty()) {
884  // Special epilogue for vararg functions. See emitEpilogue
885  if (isVarArg)
886  continue;
887  // ARMv4T requires BX, see emitEpilogue
888  if (!STI.hasV5TOps())
889  continue;
890  // Tailcall optimization failed; change TCRETURN to a tBL
891  if (MI->getOpcode() == ARM::TCRETURNdi ||
892  MI->getOpcode() == ARM::TCRETURNri) {
893  unsigned Opcode = MI->getOpcode() == ARM::TCRETURNdi
894  ? ARM::tBL : ARM::tBLXr;
895  MachineInstrBuilder BL = BuildMI(MF, DL, TII.get(Opcode));
896  BL.add(predOps(ARMCC::AL));
897  BL.add(MI->getOperand(0));
898  MBB.insert(MI, &*BL);
899  }
900  Reg = ARM::PC;
901  (*MIB).setDesc(TII.get(ARM::tPOP_RET));
902  if (MI != MBB.end())
903  MIB.copyImplicitOps(*MI);
904  MI = MBB.erase(MI);
905  } else
906  // LR may only be popped into PC, as part of return sequence.
907  // If this isn't the return sequence, we'll need emitPopSpecialFixUp
908  // to restore LR the hard way.
909  continue;
910  }
911  MIB.addReg(Reg, getDefRegState(true));
912  NeedsPop = true;
913  }
914 
915  // It's illegal to emit pop instruction without operands.
916  if (NeedsPop)
917  MBB.insert(MI, &*MIB);
918  else
919  MF.DeleteMachineInstr(MIB);
920 
921  return true;
922 }
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
unsigned succ_size() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
Definition: BitVector.h:332
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
#define R4(n)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
MachineFunctionProperties & reset(Property P)
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned getBaseRegister() const
DataLayout DL
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:404
const MachineInstrBuilder & add(const MachineOperand &MO) const
bool any() const
any - Returns true if any bit is set.
Definition: BitVector.h:181
A debug info location.
Definition: DebugLoc.h:34
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, MachineFunction &MF, MachineInstr *MI, unsigned NumBytes)
Tries to add registers to the reglist of a given base-updating push/pop instruction to adjust the sta...
#define R2(n)
void setGPRCalleeSavedArea2Offset(unsigned o)
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:391
bool erase(const T &V)
Definition: SmallSet.h:108
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...
return AArch64::GPR64RegClass contains(Reg)
unsigned getDPRCalleeSavedAreaSize() const
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
const ARMBaseInstrInfo * getInstrInfo() const override
Definition: ARMSubtarget.h:437
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
LLVM_NODISCARD bool empty() const
Definition: SmallSet.h:56
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
static void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const TargetInstrInfo &TII, const DebugLoc &dl, const ThumbRegisterInfo &MRI, int NumBytes, unsigned MIFlags=MachineInstr::NoFlags)
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:22
const HexagonInstrInfo * TII
bool isTargetELF() const
Definition: ARMSubtarget.h:590
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
Thumb1FrameLowering(const ARMSubtarget &sti)
unsigned getFrameRegister(const MachineFunction &MF) const override
unsigned getArgRegsSaveSize() const
const MachineFunctionProperties & getProperties() const
Get the function properties.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
void setDPRCalleeSavedAreaOffset(unsigned o)
static const unsigned * findNextOrderedReg(const unsigned *CurrentReg, SmallSet< unsigned, SetSize > &EnabledRegs, const unsigned *OrderEnd)
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void setFramePtrSpillOffset(unsigned o)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:250
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool isLiveIn(unsigned Reg) const
int getOffsetAdjustment() const
Return the correction for frame offsets.
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getDefRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isCalleeSavedRegister(unsigned Reg, const MCPhysReg *CSRegs)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
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:377
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:384
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
void setStackSize(uint64_t Size)
Set the size of the stack.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:36
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
bool splitFramePushPop(const MachineFunction &MF) const
Returns true if the frame setup is split into two separate pushes (first r0-r7,lr then r8-r11)...
Definition: ARMSubtarget.h:669
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
unsigned getFramePtrSpillOffset() const
BitVector & reset()
Definition: BitVector.h:439
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setGPRCalleeSavedArea2Size(unsigned s)
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.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:81
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:65
#define E
Definition: LargeTest.cpp:27
#define R6(n)
void setGPRCalleeSavedArea1Size(unsigned s)
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool test(unsigned Idx) const
Definition: BitVector.h:502
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
static bool isCSRestore(MachineInstr &MI, const MCPhysReg *CSRegs)
Promote Memory to Register
Definition: Mem2Reg.cpp:101
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool hasBasePointer(const MachineFunction &MF) const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:257
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:59
void setGPRCalleeSavedArea1Offset(unsigned o)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
Definition: LivePhysRegs.h:49
bool hasV5TOps() const
Definition: ARMSubtarget.h:479
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
#define I(x, y, z)
Definition: MD5.cpp:58
const ARMBaseRegisterInfo * getRegisterInfo() const override
Definition: ARMSubtarget.h:449
void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, unsigned DestReg, unsigned BaseReg, int NumBytes, const TargetInstrInfo &TII, const ARMBaseRegisterInfo &MRI, unsigned MIFlags=0)
emitThumbRegPlusImmediate - Emits a series of instructions to materialize a destreg = basereg + immed...
void setDPRCalleeSavedAreaSize(unsigned s)
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getGPRCalleeSavedArea1Size() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
static const unsigned FramePtr
IRTranslator LLVM IR MI
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MachineModuleInfo & getMMI() const
const ARMSubtarget & STI
unsigned getGPRCalleeSavedArea2Size() const
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
This class contains meta information specific to a module.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly. ...