LLVM  3.7.0
PrologEpilogInserter.cpp
Go to the documentation of this file.
1 //===-- PrologEpilogInserter.cpp - Insert Prolog/Epilog code in function --===//
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 pass is responsible for finalizing the functions frame layout, saving
11 // callee saved registers, and for emitting prolog & epilog code for the
12 // function.
13 //
14 // This pass must be run after register allocation. After this pass is
15 // executed, it is illegal to construct MO_FrameIndex operands.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #include "llvm/ADT/IndexedMap.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/SetVector.h"
22 #include "llvm/ADT/SmallSet.h"
23 #include "llvm/ADT/Statistic.h"
30 #include "llvm/CodeGen/Passes.h"
34 #include "llvm/IR/DiagnosticInfo.h"
35 #include "llvm/IR/InlineAsm.h"
36 #include "llvm/IR/LLVMContext.h"
38 #include "llvm/Support/Compiler.h"
39 #include "llvm/Support/Debug.h"
46 #include <climits>
47 
48 using namespace llvm;
49 
50 #define DEBUG_TYPE "pei"
51 
52 namespace {
53 class PEI : public MachineFunctionPass {
54 public:
55  static char ID;
56  PEI() : MachineFunctionPass(ID) {
58  }
59 
60  void getAnalysisUsage(AnalysisUsage &AU) const override;
61 
62  /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
63  /// frame indexes with appropriate references.
64  ///
65  bool runOnMachineFunction(MachineFunction &Fn) override;
66 
67 private:
68  RegScavenger *RS;
69 
70  // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
71  // stack frame indexes.
72  unsigned MinCSFrameIndex, MaxCSFrameIndex;
73 
74  // Save and Restore blocks of the current function.
75  MachineBasicBlock *SaveBlock;
77 
78  // Flag to control whether to use the register scavenger to resolve
79  // frame index materialization registers. Set according to
80  // TRI->requiresFrameIndexScavenging() for the current function.
81  bool FrameIndexVirtualScavenging;
82 
83  void calculateSets(MachineFunction &Fn);
84  void calculateCallsInformation(MachineFunction &Fn);
85  void assignCalleeSavedSpillSlots(MachineFunction &Fn,
86  const BitVector &SavedRegs);
87  void insertCSRSpillsAndRestores(MachineFunction &Fn);
88  void calculateFrameObjectOffsets(MachineFunction &Fn);
89  void replaceFrameIndices(MachineFunction &Fn);
90  void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn,
91  int &SPAdj);
92  void scavengeFrameVirtualRegs(MachineFunction &Fn);
93  void insertPrologEpilogCode(MachineFunction &Fn);
94 
95  // Convenience for recognizing return blocks.
96  bool isReturnBlock(const MachineBasicBlock *MBB) const;
97 };
98 } // namespace
99 
100 char PEI::ID = 0;
102 
103 static cl::opt<unsigned>
104 WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned)-1),
105  cl::desc("Warn for stack size bigger than the given"
106  " number"));
107 
108 INITIALIZE_PASS_BEGIN(PEI, "prologepilog",
109  "Prologue/Epilogue Insertion", false, false)
115  "Prologue/Epilogue Insertion & Frame Finalization",
116  false, false)
117 
118 STATISTIC(NumScavengedRegs, "Number of frame index regs scavenged");
119 STATISTIC(NumBytesStackSpace,
120  "Number of bytes used for stack in all functions");
121 
122 void PEI::getAnalysisUsage(AnalysisUsage &AU) const {
123  AU.setPreservesCFG();
124  AU.addPreserved<MachineLoopInfo>();
125  AU.addPreserved<MachineDominatorTree>();
126  AU.addRequired<StackProtector>();
127  AU.addRequired<TargetPassConfig>();
129 }
130 
131 bool PEI::isReturnBlock(const MachineBasicBlock* MBB) const {
132  return (MBB && !MBB->empty() && MBB->back().isReturn());
133 }
134 
135 /// Compute the set of return blocks
136 void PEI::calculateSets(MachineFunction &Fn) {
137  const MachineFrameInfo *MFI = Fn.getFrameInfo();
138 
139  // Even when we do not change any CSR, we still want to insert the
140  // prologue and epilogue of the function.
141  // So set the save points for those.
142 
143  // Use the points found by shrink-wrapping, if any.
144  if (MFI->getSavePoint()) {
145  SaveBlock = MFI->getSavePoint();
146  assert(MFI->getRestorePoint() && "Both restore and save must be set");
147  MachineBasicBlock *RestoreBlock = MFI->getRestorePoint();
148  // If RestoreBlock does not have any successor and is not a return block
149  // then the end point is unreachable and we do not need to insert any
150  // epilogue.
151  if (!RestoreBlock->succ_empty() || isReturnBlock(RestoreBlock))
152  RestoreBlocks.push_back(RestoreBlock);
153  return;
154  }
155 
156  // Save refs to entry and return blocks.
157  SaveBlock = Fn.begin();
158  for (MachineFunction::iterator MBB = Fn.begin(), E = Fn.end();
159  MBB != E; ++MBB)
160  if (isReturnBlock(MBB))
161  RestoreBlocks.push_back(MBB);
162 
163  return;
164 }
165 
166 /// StackObjSet - A set of stack object indexes
168 
169 /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
170 /// frame indexes with appropriate references.
171 ///
172 bool PEI::runOnMachineFunction(MachineFunction &Fn) {
173  const Function* F = Fn.getFunction();
174  const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
176 
177  assert(!Fn.getRegInfo().getNumVirtRegs() && "Regalloc must assign all vregs");
178 
179  RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : nullptr;
180  FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(Fn);
181 
182  // Calculate the MaxCallFrameSize and AdjustsStack variables for the
183  // function's frame information. Also eliminates call frame pseudo
184  // instructions.
185  calculateCallsInformation(Fn);
186 
187  // Determine which of the registers in the callee save list should be saved.
188  BitVector SavedRegs;
189  TFI->determineCalleeSaves(Fn, SavedRegs, RS);
190 
191  // Insert spill code for any callee saved registers that are modified.
192  assignCalleeSavedSpillSlots(Fn, SavedRegs);
193 
194  // Determine placement of CSR spill/restore code:
195  // place all spills in the entry block, all restores in return blocks.
196  calculateSets(Fn);
197 
198  // Add the code to save and restore the callee saved registers
200  insertCSRSpillsAndRestores(Fn);
201 
202  // Allow the target machine to make final modifications to the function
203  // before the frame layout is finalized.
205 
206  // Calculate actual frame offsets for all abstract stack objects...
207  calculateFrameObjectOffsets(Fn);
208 
209  // Add prolog and epilog code to the function. This function is required
210  // to align the stack frame as necessary for any stack variables or
211  // called functions. Because of this, calculateCalleeSavedRegisters()
212  // must be called before this function in order to set the AdjustsStack
213  // and MaxCallFrameSize variables.
215  insertPrologEpilogCode(Fn);
216 
217  // Replace all MO_FrameIndex operands with physical register references
218  // and actual offsets.
219  //
220  replaceFrameIndices(Fn);
221 
222  // If register scavenging is needed, as we've enabled doing it as a
223  // post-pass, scavenge the virtual registers that frame index elimination
224  // inserted.
225  if (TRI->requiresRegisterScavenging(Fn) && FrameIndexVirtualScavenging)
226  scavengeFrameVirtualRegs(Fn);
227 
228  // Clear any vregs created by virtual scavenging.
229  Fn.getRegInfo().clearVirtRegs();
230 
231  // Warn on stack size when we exceeds the given limit.
232  MachineFrameInfo *MFI = Fn.getFrameInfo();
233  uint64_t StackSize = MFI->getStackSize();
234  if (WarnStackSize.getNumOccurrences() > 0 && WarnStackSize < StackSize) {
235  DiagnosticInfoStackSize DiagStackSize(*F, StackSize);
236  F->getContext().diagnose(DiagStackSize);
237  }
238 
239  delete RS;
240  RestoreBlocks.clear();
241  return true;
242 }
243 
244 /// calculateCallsInformation - Calculate the MaxCallFrameSize and AdjustsStack
245 /// variables for the function's frame information and eliminate call frame
246 /// pseudo instructions.
247 void PEI::calculateCallsInformation(MachineFunction &Fn) {
248  const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
250  MachineFrameInfo *MFI = Fn.getFrameInfo();
251 
252  unsigned MaxCallFrameSize = 0;
253  bool AdjustsStack = MFI->adjustsStack();
254 
255  // Get the function call frame set-up and tear-down instruction opcode
256  unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
257  unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
258 
259  // Early exit for targets which have no call frame setup/destroy pseudo
260  // instructions.
261  if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
262  return;
263 
264  std::vector<MachineBasicBlock::iterator> FrameSDOps;
265  for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB)
266  for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
267  if (I->getOpcode() == FrameSetupOpcode ||
268  I->getOpcode() == FrameDestroyOpcode) {
269  assert(I->getNumOperands() >= 1 && "Call Frame Setup/Destroy Pseudo"
270  " instructions should have a single immediate argument!");
271  unsigned Size = I->getOperand(0).getImm();
272  if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
273  AdjustsStack = true;
274  FrameSDOps.push_back(I);
275  } else if (I->isInlineAsm()) {
276  // Some inline asm's need a stack frame, as indicated by operand 1.
277  unsigned ExtraInfo = I->getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
278  if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
279  AdjustsStack = true;
280  }
281 
282  MFI->setAdjustsStack(AdjustsStack);
283  MFI->setMaxCallFrameSize(MaxCallFrameSize);
284 
285  for (std::vector<MachineBasicBlock::iterator>::iterator
286  i = FrameSDOps.begin(), e = FrameSDOps.end(); i != e; ++i) {
288 
289  // If call frames are not being included as part of the stack frame, and
290  // the target doesn't indicate otherwise, remove the call frame pseudos
291  // here. The sub/add sp instruction pairs are still inserted, but we don't
292  // need to track the SP adjustment for frame index elimination.
293  if (TFI->canSimplifyCallFramePseudos(Fn))
294  TFI->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I);
295  }
296 }
297 
298 void PEI::assignCalleeSavedSpillSlots(MachineFunction &F,
299  const BitVector &SavedRegs) {
300  // These are used to keep track the callee-save area. Initialize them.
301  MinCSFrameIndex = INT_MAX;
302  MaxCSFrameIndex = 0;
303 
304  if (SavedRegs.empty())
305  return;
306 
307  const TargetRegisterInfo *RegInfo = F.getSubtarget().getRegisterInfo();
308  const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&F);
309 
310  std::vector<CalleeSavedInfo> CSI;
311  for (unsigned i = 0; CSRegs[i]; ++i) {
312  unsigned Reg = CSRegs[i];
313  if (SavedRegs.test(Reg))
314  CSI.push_back(CalleeSavedInfo(Reg));
315  }
316 
318  MachineFrameInfo *MFI = F.getFrameInfo();
319  if (!TFI->assignCalleeSavedSpillSlots(F, RegInfo, CSI)) {
320  // If target doesn't implement this, use generic code.
321 
322  if (CSI.empty())
323  return; // Early exit if no callee saved registers are modified!
324 
325  unsigned NumFixedSpillSlots;
326  const TargetFrameLowering::SpillSlot *FixedSpillSlots =
327  TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
328 
329  // Now that we know which registers need to be saved and restored, allocate
330  // stack slots for them.
331  for (std::vector<CalleeSavedInfo>::iterator I = CSI.begin(), E = CSI.end();
332  I != E; ++I) {
333  unsigned Reg = I->getReg();
334  const TargetRegisterClass *RC = RegInfo->getMinimalPhysRegClass(Reg);
335 
336  int FrameIdx;
337  if (RegInfo->hasReservedSpillSlot(F, Reg, FrameIdx)) {
338  I->setFrameIdx(FrameIdx);
339  continue;
340  }
341 
342  // Check to see if this physreg must be spilled to a particular stack slot
343  // on this target.
344  const TargetFrameLowering::SpillSlot *FixedSlot = FixedSpillSlots;
345  while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
346  FixedSlot->Reg != Reg)
347  ++FixedSlot;
348 
349  if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
350  // Nope, just spill it anywhere convenient.
351  unsigned Align = RC->getAlignment();
352  unsigned StackAlign = TFI->getStackAlignment();
353 
354  // We may not be able to satisfy the desired alignment specification of
355  // the TargetRegisterClass if the stack alignment is smaller. Use the
356  // min.
357  Align = std::min(Align, StackAlign);
358  FrameIdx = MFI->CreateStackObject(RC->getSize(), Align, true);
359  if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
360  if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
361  } else {
362  // Spill it to the stack where we must.
363  FrameIdx =
364  MFI->CreateFixedSpillStackObject(RC->getSize(), FixedSlot->Offset);
365  }
366 
367  I->setFrameIdx(FrameIdx);
368  }
369  }
370 
371  MFI->setCalleeSavedInfo(CSI);
372 }
373 
374 /// Helper function to update the liveness information for the callee-saved
375 /// registers.
376 static void updateLiveness(MachineFunction &MF) {
377  MachineFrameInfo *MFI = MF.getFrameInfo();
378  // Visited will contain all the basic blocks that are in the region
379  // where the callee saved registers are alive:
380  // - Anything that is not Save or Restore -> LiveThrough.
381  // - Save -> LiveIn.
382  // - Restore -> LiveOut.
383  // The live-out is not attached to the block, so no need to keep
384  // Restore in this set.
387  MachineBasicBlock *Entry = &MF.front();
388  MachineBasicBlock *Save = MFI->getSavePoint();
389 
390  if (!Save)
391  Save = Entry;
392 
393  if (Entry != Save) {
394  WorkList.push_back(Entry);
395  Visited.insert(Entry);
396  }
397  Visited.insert(Save);
398 
399  MachineBasicBlock *Restore = MFI->getRestorePoint();
400  if (Restore)
401  // By construction Restore cannot be visited, otherwise it
402  // means there exists a path to Restore that does not go
403  // through Save.
404  WorkList.push_back(Restore);
405 
406  while (!WorkList.empty()) {
407  const MachineBasicBlock *CurBB = WorkList.pop_back_val();
408  // By construction, the region that is after the save point is
409  // dominated by the Save and post-dominated by the Restore.
410  if (CurBB == Save)
411  continue;
412  // Enqueue all the successors not already visited.
413  // Those are by construction either before Save or after Restore.
414  for (MachineBasicBlock *SuccBB : CurBB->successors())
415  if (Visited.insert(SuccBB).second)
416  WorkList.push_back(SuccBB);
417  }
418 
419  const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
420 
421  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
422  for (MachineBasicBlock *MBB : Visited)
423  // Add the callee-saved register as live-in.
424  // It's killed at the spill.
425  MBB->addLiveIn(CSI[i].getReg());
426  }
427 }
428 
429 /// insertCSRSpillsAndRestores - Insert spill and restore code for
430 /// callee saved registers used in the function.
431 ///
432 void PEI::insertCSRSpillsAndRestores(MachineFunction &Fn) {
433  // Get callee saved register information.
434  MachineFrameInfo *MFI = Fn.getFrameInfo();
435  const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
436 
437  MFI->setCalleeSavedInfoValid(true);
438 
439  // Early exit if no callee saved registers are modified!
440  if (CSI.empty())
441  return;
442 
443  const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
445  const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
447 
448  // Spill using target interface.
449  I = SaveBlock->begin();
450  if (!TFI->spillCalleeSavedRegisters(*SaveBlock, I, CSI, TRI)) {
451  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
452  // Insert the spill to the stack frame.
453  unsigned Reg = CSI[i].getReg();
454  const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
455  TII.storeRegToStackSlot(*SaveBlock, I, Reg, true, CSI[i].getFrameIdx(),
456  RC, TRI);
457  }
458  }
459  // Update the live-in information of all the blocks up to the save point.
460  updateLiveness(Fn);
461 
462  // Restore using target interface.
463  for (MachineBasicBlock *MBB : RestoreBlocks) {
464  I = MBB->end();
465 
466  // Skip over all terminator instructions, which are part of the return
467  // sequence.
469  while (I2 != MBB->begin() && (--I2)->isTerminator())
470  I = I2;
471 
472  bool AtStart = I == MBB->begin();
473  MachineBasicBlock::iterator BeforeI = I;
474  if (!AtStart)
475  --BeforeI;
476 
477  // Restore all registers immediately before the return and any
478  // terminators that precede it.
479  if (!TFI->restoreCalleeSavedRegisters(*MBB, I, CSI, TRI)) {
480  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
481  unsigned Reg = CSI[i].getReg();
482  const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
483  TII.loadRegFromStackSlot(*MBB, I, Reg, CSI[i].getFrameIdx(), RC, TRI);
484  assert(I != MBB->begin() &&
485  "loadRegFromStackSlot didn't insert any code!");
486  // Insert in reverse order. loadRegFromStackSlot can insert
487  // multiple instructions.
488  if (AtStart)
489  I = MBB->begin();
490  else {
491  I = BeforeI;
492  ++I;
493  }
494  }
495  }
496  }
497 }
498 
499 /// AdjustStackOffset - Helper function used to adjust the stack frame offset.
500 static inline void
502  bool StackGrowsDown, int64_t &Offset,
503  unsigned &MaxAlign) {
504  // If the stack grows down, add the object size to find the lowest address.
505  if (StackGrowsDown)
506  Offset += MFI->getObjectSize(FrameIdx);
507 
508  unsigned Align = MFI->getObjectAlignment(FrameIdx);
509 
510  // If the alignment of this object is greater than that of the stack, then
511  // increase the stack alignment to match.
512  MaxAlign = std::max(MaxAlign, Align);
513 
514  // Adjust to alignment boundary.
515  Offset = (Offset + Align - 1) / Align * Align;
516 
517  if (StackGrowsDown) {
518  DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset << "]\n");
519  MFI->setObjectOffset(FrameIdx, -Offset); // Set the computed offset
520  } else {
521  DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset << "]\n");
522  MFI->setObjectOffset(FrameIdx, Offset);
523  Offset += MFI->getObjectSize(FrameIdx);
524  }
525 }
526 
527 /// AssignProtectedObjSet - Helper function to assign large stack objects (i.e.,
528 /// those required to be close to the Stack Protector) to stack offsets.
529 static void
530 AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
531  SmallSet<int, 16> &ProtectedObjs,
532  MachineFrameInfo *MFI, bool StackGrowsDown,
533  int64_t &Offset, unsigned &MaxAlign) {
534 
535  for (StackObjSet::const_iterator I = UnassignedObjs.begin(),
536  E = UnassignedObjs.end(); I != E; ++I) {
537  int i = *I;
538  AdjustStackOffset(MFI, i, StackGrowsDown, Offset, MaxAlign);
539  ProtectedObjs.insert(i);
540  }
541 }
542 
543 /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
544 /// abstract stack objects.
545 ///
546 void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
548  StackProtector *SP = &getAnalysis<StackProtector>();
549 
550  bool StackGrowsDown =
552 
553  // Loop over all of the stack objects, assigning sequential addresses...
554  MachineFrameInfo *MFI = Fn.getFrameInfo();
555 
556  // Start at the beginning of the local area.
557  // The Offset is the distance from the stack top in the direction
558  // of stack growth -- so it's always nonnegative.
559  int LocalAreaOffset = TFI.getOffsetOfLocalArea();
560  if (StackGrowsDown)
561  LocalAreaOffset = -LocalAreaOffset;
562  assert(LocalAreaOffset >= 0
563  && "Local area offset should be in direction of stack growth");
564  int64_t Offset = LocalAreaOffset;
565 
566  // If there are fixed sized objects that are preallocated in the local area,
567  // non-fixed objects can't be allocated right at the start of local area.
568  // We currently don't support filling in holes in between fixed sized
569  // objects, so we adjust 'Offset' to point to the end of last fixed sized
570  // preallocated object.
571  for (int i = MFI->getObjectIndexBegin(); i != 0; ++i) {
572  int64_t FixedOff;
573  if (StackGrowsDown) {
574  // The maximum distance from the stack pointer is at lower address of
575  // the object -- which is given by offset. For down growing stack
576  // the offset is negative, so we negate the offset to get the distance.
577  FixedOff = -MFI->getObjectOffset(i);
578  } else {
579  // The maximum distance from the start pointer is at the upper
580  // address of the object.
581  FixedOff = MFI->getObjectOffset(i) + MFI->getObjectSize(i);
582  }
583  if (FixedOff > Offset) Offset = FixedOff;
584  }
585 
586  // First assign frame offsets to stack objects that are used to spill
587  // callee saved registers.
588  if (StackGrowsDown) {
589  for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
590  // If the stack grows down, we need to add the size to find the lowest
591  // address of the object.
592  Offset += MFI->getObjectSize(i);
593 
594  unsigned Align = MFI->getObjectAlignment(i);
595  // Adjust to alignment boundary
596  Offset = RoundUpToAlignment(Offset, Align);
597 
598  MFI->setObjectOffset(i, -Offset); // Set the computed offset
599  }
600  } else {
601  int MaxCSFI = MaxCSFrameIndex, MinCSFI = MinCSFrameIndex;
602  for (int i = MaxCSFI; i >= MinCSFI ; --i) {
603  unsigned Align = MFI->getObjectAlignment(i);
604  // Adjust to alignment boundary
605  Offset = RoundUpToAlignment(Offset, Align);
606 
607  MFI->setObjectOffset(i, Offset);
608  Offset += MFI->getObjectSize(i);
609  }
610  }
611 
612  unsigned MaxAlign = MFI->getMaxAlignment();
613 
614  // Make sure the special register scavenging spill slot is closest to the
615  // incoming stack pointer if a frame pointer is required and is closer
616  // to the incoming rather than the final stack pointer.
617  const TargetRegisterInfo *RegInfo = Fn.getSubtarget().getRegisterInfo();
618  bool EarlyScavengingSlots = (TFI.hasFP(Fn) &&
619  TFI.isFPCloseToIncomingSP() &&
620  RegInfo->useFPForScavengingIndex(Fn) &&
621  !RegInfo->needsStackRealignment(Fn));
622  if (RS && EarlyScavengingSlots) {
623  SmallVector<int, 2> SFIs;
624  RS->getScavengingFrameIndices(SFIs);
625  for (SmallVectorImpl<int>::iterator I = SFIs.begin(),
626  IE = SFIs.end(); I != IE; ++I)
627  AdjustStackOffset(MFI, *I, StackGrowsDown, Offset, MaxAlign);
628  }
629 
630  // FIXME: Once this is working, then enable flag will change to a target
631  // check for whether the frame is large enough to want to use virtual
632  // frame index registers. Functions which don't want/need this optimization
633  // will continue to use the existing code path.
634  if (MFI->getUseLocalStackAllocationBlock()) {
635  unsigned Align = MFI->getLocalFrameMaxAlign();
636 
637  // Adjust to alignment boundary.
638  Offset = RoundUpToAlignment(Offset, Align);
639 
640  DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n");
641 
642  // Resolve offsets for objects in the local block.
643  for (unsigned i = 0, e = MFI->getLocalFrameObjectCount(); i != e; ++i) {
644  std::pair<int, int64_t> Entry = MFI->getLocalFrameObjectMap(i);
645  int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second;
646  DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" <<
647  FIOffset << "]\n");
648  MFI->setObjectOffset(Entry.first, FIOffset);
649  }
650  // Allocate the local block
651  Offset += MFI->getLocalFrameSize();
652 
653  MaxAlign = std::max(Align, MaxAlign);
654  }
655 
656  // Make sure that the stack protector comes before the local variables on the
657  // stack.
658  SmallSet<int, 16> ProtectedObjs;
659  if (MFI->getStackProtectorIndex() >= 0) {
660  StackObjSet LargeArrayObjs;
661  StackObjSet SmallArrayObjs;
662  StackObjSet AddrOfObjs;
663 
664  AdjustStackOffset(MFI, MFI->getStackProtectorIndex(), StackGrowsDown,
665  Offset, MaxAlign);
666 
667  // Assign large stack objects first.
668  for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
669  if (MFI->isObjectPreAllocated(i) &&
671  continue;
672  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
673  continue;
674  if (RS && RS->isScavengingFrameIndex((int)i))
675  continue;
676  if (MFI->isDeadObjectIndex(i))
677  continue;
678  if (MFI->getStackProtectorIndex() == (int)i)
679  continue;
680 
681  switch (SP->getSSPLayout(MFI->getObjectAllocation(i))) {
683  continue;
685  SmallArrayObjs.insert(i);
686  continue;
688  AddrOfObjs.insert(i);
689  continue;
691  LargeArrayObjs.insert(i);
692  continue;
693  }
694  llvm_unreachable("Unexpected SSPLayoutKind.");
695  }
696 
697  AssignProtectedObjSet(LargeArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
698  Offset, MaxAlign);
699  AssignProtectedObjSet(SmallArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
700  Offset, MaxAlign);
701  AssignProtectedObjSet(AddrOfObjs, ProtectedObjs, MFI, StackGrowsDown,
702  Offset, MaxAlign);
703  }
704 
705  // Then assign frame offsets to stack objects that are not used to spill
706  // callee saved registers.
707  for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
708  if (MFI->isObjectPreAllocated(i) &&
710  continue;
711  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
712  continue;
713  if (RS && RS->isScavengingFrameIndex((int)i))
714  continue;
715  if (MFI->isDeadObjectIndex(i))
716  continue;
717  if (MFI->getStackProtectorIndex() == (int)i)
718  continue;
719  if (ProtectedObjs.count(i))
720  continue;
721 
722  AdjustStackOffset(MFI, i, StackGrowsDown, Offset, MaxAlign);
723  }
724 
725  // Make sure the special register scavenging spill slot is closest to the
726  // stack pointer.
727  if (RS && !EarlyScavengingSlots) {
728  SmallVector<int, 2> SFIs;
729  RS->getScavengingFrameIndices(SFIs);
730  for (SmallVectorImpl<int>::iterator I = SFIs.begin(),
731  IE = SFIs.end(); I != IE; ++I)
732  AdjustStackOffset(MFI, *I, StackGrowsDown, Offset, MaxAlign);
733  }
734 
735  if (!TFI.targetHandlesStackFrameRounding()) {
736  // If we have reserved argument space for call sites in the function
737  // immediately on entry to the current function, count it as part of the
738  // overall stack size.
739  if (MFI->adjustsStack() && TFI.hasReservedCallFrame(Fn))
740  Offset += MFI->getMaxCallFrameSize();
741 
742  // Round up the size to a multiple of the alignment. If the function has
743  // any calls or alloca's, align to the target's StackAlignment value to
744  // ensure that the callee's frame or the alloca data is suitably aligned;
745  // otherwise, for leaf functions, align to the TransientStackAlignment
746  // value.
747  unsigned StackAlign;
748  if (MFI->adjustsStack() || MFI->hasVarSizedObjects() ||
749  (RegInfo->needsStackRealignment(Fn) && MFI->getObjectIndexEnd() != 0))
750  StackAlign = TFI.getStackAlignment();
751  else
752  StackAlign = TFI.getTransientStackAlignment();
753 
754  // If the frame pointer is eliminated, all frame offsets will be relative to
755  // SP not FP. Align to MaxAlign so this works.
756  StackAlign = std::max(StackAlign, MaxAlign);
757  Offset = RoundUpToAlignment(Offset, StackAlign);
758  }
759 
760  // Update frame info to pretend that this is part of the stack...
761  int64_t StackSize = Offset - LocalAreaOffset;
762  MFI->setStackSize(StackSize);
763  NumBytesStackSpace += StackSize;
764 }
765 
766 /// insertPrologEpilogCode - Scan the function for modified callee saved
767 /// registers, insert spill code for these callee saved registers, then add
768 /// prolog and epilog code to the function.
769 ///
770 void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
772 
773  // Add prologue to the function...
774  TFI.emitPrologue(Fn, *SaveBlock);
775 
776  // Add epilogue to restore the callee-save registers in each exiting block.
777  for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
778  TFI.emitEpilogue(Fn, *RestoreBlock);
779 
780  // Emit additional code that is required to support segmented stacks, if
781  // we've been asked for it. This, when linked with a runtime with support
782  // for segmented stacks (libgcc is one), will result in allocating stack
783  // space in small chunks instead of one large contiguous block.
784  if (Fn.shouldSplitStack())
785  TFI.adjustForSegmentedStacks(Fn, *SaveBlock);
786 
787  // Emit additional code that is required to explicitly handle the stack in
788  // HiPE native code (if needed) when loaded in the Erlang/OTP runtime. The
789  // approach is rather similar to that of Segmented Stacks, but it uses a
790  // different conditional check and another BIF for allocating more stack
791  // space.
793  TFI.adjustForHiPEPrologue(Fn, *SaveBlock);
794 }
795 
796 /// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
797 /// register references and actual offsets.
798 ///
799 void PEI::replaceFrameIndices(MachineFunction &Fn) {
801  if (!TFI.needsFrameIndexResolution(Fn)) return;
802 
803  MachineModuleInfo &MMI = Fn.getMMI();
804  const Function *F = Fn.getFunction();
805  const Function *ParentF = MMI.getWinEHParent(F);
806  unsigned FrameReg;
807  if (F == ParentF) {
808  WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
809  // FIXME: This should be unconditional but we have bugs in the preparation
810  // pass.
811  if (FuncInfo.UnwindHelpFrameIdx != INT_MAX)
813  Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
814  } else if (MMI.hasWinEHFuncInfo(F)) {
815  WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
816  auto I = FuncInfo.CatchHandlerParentFrameObjIdx.find(F);
817  if (I != FuncInfo.CatchHandlerParentFrameObjIdx.end())
819  TFI.getFrameIndexReferenceFromSP(Fn, I->second, FrameReg);
820  }
821 
822  // Store SPAdj at exit of a basic block.
823  SmallVector<int, 8> SPState;
824  SPState.resize(Fn.getNumBlockIDs());
826 
827  // Iterate over the reachable blocks in DFS order.
828  for (auto DFI = df_ext_begin(&Fn, Reachable), DFE = df_ext_end(&Fn, Reachable);
829  DFI != DFE; ++DFI) {
830  int SPAdj = 0;
831  // Check the exit state of the DFS stack predecessor.
832  if (DFI.getPathLength() >= 2) {
833  MachineBasicBlock *StackPred = DFI.getPath(DFI.getPathLength() - 2);
834  assert(Reachable.count(StackPred) &&
835  "DFS stack predecessor is already visited.\n");
836  SPAdj = SPState[StackPred->getNumber()];
837  }
838  MachineBasicBlock *BB = *DFI;
839  replaceFrameIndices(BB, Fn, SPAdj);
840  SPState[BB->getNumber()] = SPAdj;
841  }
842 
843  // Handle the unreachable blocks.
844  for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
845  if (Reachable.count(BB))
846  // Already handled in DFS traversal.
847  continue;
848  int SPAdj = 0;
849  replaceFrameIndices(BB, Fn, SPAdj);
850  }
851 }
852 
853 void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn,
854  int &SPAdj) {
855  assert(Fn.getSubtarget().getRegisterInfo() &&
856  "getRegisterInfo() must be implemented!");
857  const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
858  const TargetRegisterInfo &TRI = *Fn.getSubtarget().getRegisterInfo();
860  unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
861  unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
862 
863  if (RS && !FrameIndexVirtualScavenging) RS->enterBasicBlock(BB);
864 
865  bool InsideCallSequence = false;
866 
867  for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
868 
869  if (I->getOpcode() == FrameSetupOpcode ||
870  I->getOpcode() == FrameDestroyOpcode) {
871  InsideCallSequence = (I->getOpcode() == FrameSetupOpcode);
872  SPAdj += TII.getSPAdjust(I);
873 
874  MachineBasicBlock::iterator PrevI = BB->end();
875  if (I != BB->begin()) PrevI = std::prev(I);
876  TFI->eliminateCallFramePseudoInstr(Fn, *BB, I);
877 
878  // Visit the instructions created by eliminateCallFramePseudoInstr().
879  if (PrevI == BB->end())
880  I = BB->begin(); // The replaced instr was the first in the block.
881  else
882  I = std::next(PrevI);
883  continue;
884  }
885 
886  MachineInstr *MI = I;
887  bool DoIncr = true;
888  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
889  if (!MI->getOperand(i).isFI())
890  continue;
891 
892  // Frame indicies in debug values are encoded in a target independent
893  // way with simply the frame index and offset rather than any
894  // target-specific addressing mode.
895  if (MI->isDebugValue()) {
896  assert(i == 0 && "Frame indicies can only appear as the first "
897  "operand of a DBG_VALUE machine instruction");
898  unsigned Reg;
899  MachineOperand &Offset = MI->getOperand(1);
900  Offset.setImm(Offset.getImm() +
902  Fn, MI->getOperand(0).getIndex(), Reg));
903  MI->getOperand(0).ChangeToRegister(Reg, false /*isDef*/);
904  continue;
905  }
906 
907  // TODO: This code should be commoned with the code for
908  // PATCHPOINT. There's no good reason for the difference in
909  // implementation other than historical accident. The only
910  // remaining difference is the unconditional use of the stack
911  // pointer as the base register.
912  if (MI->getOpcode() == TargetOpcode::STATEPOINT) {
913  assert((!MI->isDebugValue() || i == 0) &&
914  "Frame indicies can only appear as the first operand of a "
915  "DBG_VALUE machine instruction");
916  unsigned Reg;
917  MachineOperand &Offset = MI->getOperand(i + 1);
918  const unsigned refOffset =
920  Reg);
921 
922  Offset.setImm(Offset.getImm() + refOffset);
923  MI->getOperand(i).ChangeToRegister(Reg, false /*isDef*/);
924  continue;
925  }
926 
927  // Some instructions (e.g. inline asm instructions) can have
928  // multiple frame indices and/or cause eliminateFrameIndex
929  // to insert more than one instruction. We need the register
930  // scavenger to go through all of these instructions so that
931  // it can update its register information. We keep the
932  // iterator at the point before insertion so that we can
933  // revisit them in full.
934  bool AtBeginning = (I == BB->begin());
935  if (!AtBeginning) --I;
936 
937  // If this instruction has a FrameIndex operand, we need to
938  // use that target machine register info object to eliminate
939  // it.
940  TRI.eliminateFrameIndex(MI, SPAdj, i,
941  FrameIndexVirtualScavenging ? nullptr : RS);
942 
943  // Reset the iterator if we were at the beginning of the BB.
944  if (AtBeginning) {
945  I = BB->begin();
946  DoIncr = false;
947  }
948 
949  MI = nullptr;
950  break;
951  }
952 
953  // If we are looking at a call sequence, we need to keep track of
954  // the SP adjustment made by each instruction in the sequence.
955  // This includes both the frame setup/destroy pseudos (handled above),
956  // as well as other instructions that have side effects w.r.t the SP.
957  // Note that this must come after eliminateFrameIndex, because
958  // if I itself referred to a frame index, we shouldn't count its own
959  // adjustment.
960  if (MI && InsideCallSequence)
961  SPAdj += TII.getSPAdjust(MI);
962 
963  if (DoIncr && I != BB->end()) ++I;
964 
965  // Update register states.
966  if (RS && !FrameIndexVirtualScavenging && MI) RS->forward(MI);
967  }
968 }
969 
970 /// scavengeFrameVirtualRegs - Replace all frame index virtual registers
971 /// with physical registers. Use the register scavenger to find an
972 /// appropriate register to use.
973 ///
974 /// FIXME: Iterating over the instruction stream is unnecessary. We can simply
975 /// iterate over the vreg use list, which at this point only contains machine
976 /// operands for which eliminateFrameIndex need a new scratch reg.
977 void
978 PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
979  // Run through the instructions and find any virtual registers.
980  for (MachineFunction::iterator BB = Fn.begin(),
981  E = Fn.end(); BB != E; ++BB) {
982  RS->enterBasicBlock(BB);
983 
984  int SPAdj = 0;
985 
986  // The instruction stream may change in the loop, so check BB->end()
987  // directly.
988  for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
989  // We might end up here again with a NULL iterator if we scavenged a
990  // register for which we inserted spill code for definition by what was
991  // originally the first instruction in BB.
992  if (I == MachineBasicBlock::iterator(nullptr))
993  I = BB->begin();
994 
995  MachineInstr *MI = I;
996  MachineBasicBlock::iterator J = std::next(I);
998  I == BB->begin() ? MachineBasicBlock::iterator(nullptr)
999  : std::prev(I);
1000 
1001  // RS should process this instruction before we might scavenge at this
1002  // location. This is because we might be replacing a virtual register
1003  // defined by this instruction, and if so, registers killed by this
1004  // instruction are available, and defined registers are not.
1005  RS->forward(I);
1006 
1007  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
1008  if (MI->getOperand(i).isReg()) {
1009  MachineOperand &MO = MI->getOperand(i);
1010  unsigned Reg = MO.getReg();
1011  if (Reg == 0)
1012  continue;
1014  continue;
1015 
1016  // When we first encounter a new virtual register, it
1017  // must be a definition.
1018  assert(MI->getOperand(i).isDef() &&
1019  "frame index virtual missing def!");
1020  // Scavenge a new scratch register
1021  const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(Reg);
1022  unsigned ScratchReg = RS->scavengeRegister(RC, J, SPAdj);
1023 
1024  ++NumScavengedRegs;
1025 
1026  // Replace this reference to the virtual register with the
1027  // scratch register.
1028  assert (ScratchReg && "Missing scratch register!");
1029  MachineRegisterInfo &MRI = Fn.getRegInfo();
1030  Fn.getRegInfo().replaceRegWith(Reg, ScratchReg);
1031 
1032  // Make sure MRI now accounts this register as used.
1033  MRI.setPhysRegUsed(ScratchReg);
1034 
1035  // Because this instruction was processed by the RS before this
1036  // register was allocated, make sure that the RS now records the
1037  // register as being used.
1038  RS->setRegUsed(ScratchReg);
1039  }
1040  }
1041 
1042  // If the scavenger needed to use one of its spill slots, the
1043  // spill code will have been inserted in between I and J. This is a
1044  // problem because we need the spill code before I: Move I to just
1045  // prior to J.
1046  if (I != std::prev(J)) {
1047  BB->splice(J, BB, I);
1048 
1049  // Before we move I, we need to prepare the RS to visit I again.
1050  // Specifically, RS will assert if it sees uses of registers that
1051  // it believes are undefined. Because we have already processed
1052  // register kills in I, when it visits I again, it will believe that
1053  // those registers are undefined. To avoid this situation, unprocess
1054  // the instruction I.
1055  assert(RS->getCurrentPosition() == I &&
1056  "The register scavenger has an unexpected position");
1057  I = P;
1058  RS->unprocess(P);
1059  } else
1060  ++I;
1061  }
1062  }
1063 }
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void setPhysRegUsed(unsigned Reg)
setPhysRegUsed - Mark the specified register used in this function.
virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg, int &FrameIdx) const
hasReservedSpillSlot - Return true if target has reserved a spill slot in the stack frame of the give...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:223
void setCalleeSavedInfoValid(bool v)
STATISTIC(NumFunctions,"Total number of functions")
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
WinEHFuncInfo & getWinEHFuncInfo(const Function *F)
static void updateLiveness(MachineFunction &MF)
Helper function to update the liveness information for the callee-saved registers.
MachineBasicBlock * getRestorePoint() const
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:276
virtual void adjustForHiPEPrologue(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to add Erlang Run-Time System (ERTS) specific code in the assembly prologue to ex...
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
void addLiveIn(unsigned Reg)
Adds the specified register as a live in.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
F(f)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
requiresFrameIndexScavenging - returns true if the target requires post PEI scavenging of registers f...
virtual const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
bool hasWinEHFuncInfo(const Function *F) const
Diagnostic information for stack size reporting.
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:79
Naked function.
Definition: Attributes.h:81
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:172
iterator_range< succ_iterator > successors()
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Prologue Epilogue Insertion &Frame false
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
int64_t getLocalFrameSize() const
Get the size of the local object blob.
unsigned getSize() const
getSize - Return the size of the register in bytes, which is also the size of a stack slot allocated ...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:70
unsigned getCallFrameDestroyOpcode() const
Did not trigger a stack protector.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
Definition: SmallVector.h:406
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:75
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const TargetRegisterClass * getRegClass(unsigned Reg) const
getRegClass - Return the register class of the specified virtual register.
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...
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
The address of this allocation is exposed and triggered protection.
Target-Independent Code Generator Pass Configuration Options.
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
const MachineBasicBlock & front() const
int getObjectIndexBegin() const
Return the minimum frame object index.
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:102
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: SmallVector.h:57
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise)...
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:69
virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
eliminateFrameIndex - This method must be overriden to eliminate abstract frame indices from instruct...
virtual bool useFPForScavengingIndex(const MachineFunction &MF) const
useFPForScavengingIndex - returns true if the target wants to use frame pointer based accesses to spi...
int64_t getImm() const
static cl::opt< unsigned > WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned)-1), cl::desc("Warn for stack size bigger than the given"" number"))
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
getCalleeSavedRegs - Return a null-terminated list of all of the callee saved registers on this targe...
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
unsigned getTransientStackAlignment() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:267
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
requiresRegisterScavenging - returns true if the target requires (and can make use of) the register s...
TargetInstrInfo - Interface to description of machine instruction set.
bool isDebugValue() const
Definition: MachineInstr.h:748
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bundle_iterator< MachineInstr, instr_iterator > iterator
#define P(N)
DenseMap< const Function *, int > CatchHandlerParentFrameObjIdx
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
bool isReturn(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:399
void initializePEIPass(PassRegistry &)
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
virtual bool needsStackRealignment(const MachineFunction &MF) const
needsStackRealignment - true if storage within the function requires the stack pointer to be aligned ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned getAlignment() const
getAlignment - Return the minimum required alignment for a register of this class.
bool getUseLocalStackAllocationBlock()
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
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:32
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:273
bool empty() const
empty - Tests whether there are no bits in this bitvector.
Definition: BitVector.h:115
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:264
bool shouldSplitStack()
Should we be emitting segmented stack stuff for the function.
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Load the specified register of the given register class from the specified stack frame index...
SmallSetVector< int, 8 > StackObjSet
StackObjSet - A set of stack object indexes.
Represent the analysis usage information of a pass.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
DenseMap< const Function *, int > CatchHandlerParentFrameObjOffset
void setImm(int64_t immVal)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
SSPLayoutKind getSSPLayout(const AllocaInst *AI) const
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:69
virtual void eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
eliminateCallFramePseudoInstr - This method is called during prolog/epilog code insertion to eliminat...
INITIALIZE_PASS_BEGIN(PEI,"prologepilog","Prologue/Epilogue Insertion", false, false) INITIALIZE_PASS_END(PEI
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Store the specified register of the given register class to the specified stack frame index...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
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.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:53
virtual const TargetFrameLowering * getFrameLowering() const
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:217
int64_t getLocalFrameObjectCount()
Return the number of objects allocated into the local object block.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:299
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
bool test(unsigned Idx) const
Definition: BitVector.h:322
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Prologue Epilogue Insertion &Frame Finalization
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
Information about stack frame layout on the target.
virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
static void AdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
getMinimalPhysRegClass - Returns the Register Class of a physical register of the given type...
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:609
int getStackProtectorIndex() const
Return the index for the stack protector object.
char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineBasicBlock * getSavePoint() const
const Function * getWinEHParent(const Function *F) const
Representation of each machine instruction.
Definition: MachineInstr.h:51
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:217
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Call instruction with associated vm state for deoptimization and list of live pointers for relocation...
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:54
virtual void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to have the function use segmented stacks.
void setMaxCallFrameSize(unsigned S)
virtual int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI, unsigned &FrameReg) const
Same as above, except that the 'base register' will always be RSP, not RBP on x86.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset)
Create a spill slot at a fixed location on the stack.
safe stack
Definition: SafeStack.cpp:606
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
unsigned getReg() const
getReg - Returns the register number.
virtual const TargetInstrInfo * getInstrInfo() const
BasicBlockListType::iterator iterator
#define DEBUG(X)
Definition: Debug.h:92
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MachineModuleInfo & getMMI() const
std::pair< int, int64_t > getLocalFrameObjectMap(int i)
Get the local offset mapping for a for an object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
always Inliner for always_inline functions
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo *MFI, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign)
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be clo...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Array or nested array >= SSP-buffer-size.
Array or nested array < SSP-buffer-size.
MachineModuleInfo - This class contains meta information specific to a module.
virtual bool isFPCloseToIncomingSP() const
isFPCloseToIncomingSP - Return true if the frame pointer is close to the incoming stack pointer...
void resize(size_type N)
Definition: SmallVector.h:376