LLVM  13.0.0git
PrologEpilogInserter.cpp
Go to the documentation of this file.
1 //===- PrologEpilogInserter.cpp - Insert Prolog/Epilog code in function ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass is responsible for finalizing the functions frame layout, saving
10 // callee saved registers, and for emitting prolog & epilog code for the
11 // function.
12 //
13 // This pass must be run after register allocation. After this pass is
14 // executed, it is illegal to construct MO_FrameIndex operands.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/BitVector.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SetVector.h"
23 #include "llvm/ADT/SmallPtrSet.h"
24 #include "llvm/ADT/SmallSet.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/Statistic.h"
47 #include "llvm/IR/Attributes.h"
48 #include "llvm/IR/CallingConv.h"
50 #include "llvm/IR/DiagnosticInfo.h"
51 #include "llvm/IR/Function.h"
52 #include "llvm/IR/InlineAsm.h"
53 #include "llvm/IR/LLVMContext.h"
54 #include "llvm/InitializePasses.h"
55 #include "llvm/MC/MCRegisterInfo.h"
56 #include "llvm/Pass.h"
57 #include "llvm/Support/CodeGen.h"
59 #include "llvm/Support/Debug.h"
65 #include <algorithm>
66 #include <cassert>
67 #include <cstdint>
68 #include <functional>
69 #include <limits>
70 #include <utility>
71 #include <vector>
72 
73 using namespace llvm;
74 
75 #define DEBUG_TYPE "prologepilog"
76 
78 
79 STATISTIC(NumLeafFuncWithSpills, "Number of leaf functions with CSRs");
80 STATISTIC(NumFuncSeen, "Number of functions seen in PEI");
81 
82 
83 namespace {
84 
85 class PEI : public MachineFunctionPass {
86 public:
87  static char ID;
88 
89  PEI() : MachineFunctionPass(ID) {
91  }
92 
93  void getAnalysisUsage(AnalysisUsage &AU) const override;
94 
95  /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
96  /// frame indexes with appropriate references.
97  bool runOnMachineFunction(MachineFunction &MF) override;
98 
99 private:
100  RegScavenger *RS;
101 
102  // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
103  // stack frame indexes.
104  unsigned MinCSFrameIndex = std::numeric_limits<unsigned>::max();
105  unsigned MaxCSFrameIndex = 0;
106 
107  // Save and Restore blocks of the current function. Typically there is a
108  // single save block, unless Windows EH funclets are involved.
109  MBBVector SaveBlocks;
110  MBBVector RestoreBlocks;
111 
112  // Flag to control whether to use the register scavenger to resolve
113  // frame index materialization registers. Set according to
114  // TRI->requiresFrameIndexScavenging() for the current function.
115  bool FrameIndexVirtualScavenging;
116 
117  // Flag to control whether the scavenger should be passed even though
118  // FrameIndexVirtualScavenging is used.
119  bool FrameIndexEliminationScavenging;
120 
121  // Emit remarks.
122  MachineOptimizationRemarkEmitter *ORE = nullptr;
123 
124  void calculateCallFrameInfo(MachineFunction &MF);
125  void calculateSaveRestoreBlocks(MachineFunction &MF);
126  void spillCalleeSavedRegs(MachineFunction &MF);
127 
128  void calculateFrameObjectOffsets(MachineFunction &MF);
129  void replaceFrameIndices(MachineFunction &MF);
130  void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF,
131  int &SPAdj);
132  void insertPrologEpilogCode(MachineFunction &MF);
133 };
134 
135 } // end anonymous namespace
136 
137 char PEI::ID = 0;
138 
140 
141 static cl::opt<unsigned>
142 WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned)-1),
143  cl::desc("Warn for stack size bigger than the given"
144  " number"));
145 
146 INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false,
147  false)
152  "Prologue/Epilogue Insertion & Frame Finalization", false,
153  false)
154 
156  return new PEI();
157 }
158 
159 STATISTIC(NumBytesStackSpace,
160  "Number of bytes used for stack in all functions");
161 
162 void PEI::getAnalysisUsage(AnalysisUsage &AU) const {
163  AU.setPreservesCFG();
168 }
169 
170 /// StackObjSet - A set of stack object indexes
172 
173 using SavedDbgValuesMap =
175 
176 /// Stash DBG_VALUEs that describe parameters and which are placed at the start
177 /// of the block. Later on, after the prologue code has been emitted, the
178 /// stashed DBG_VALUEs will be reinserted at the start of the block.
180  SavedDbgValuesMap &EntryDbgValues) {
181  SmallVector<const MachineInstr *, 4> FrameIndexValues;
182 
183  for (auto &MI : MBB) {
184  if (!MI.isDebugInstr())
185  break;
186  if (!MI.isDebugValue() || !MI.getDebugVariable()->isParameter())
187  continue;
188  if (any_of(MI.debug_operands(),
189  [](const MachineOperand &MO) { return MO.isFI(); })) {
190  // We can only emit valid locations for frame indices after the frame
191  // setup, so do not stash away them.
192  FrameIndexValues.push_back(&MI);
193  continue;
194  }
195  const DILocalVariable *Var = MI.getDebugVariable();
196  const DIExpression *Expr = MI.getDebugExpression();
197  auto Overlaps = [Var, Expr](const MachineInstr *DV) {
198  return Var == DV->getDebugVariable() &&
199  Expr->fragmentsOverlap(DV->getDebugExpression());
200  };
201  // See if the debug value overlaps with any preceding debug value that will
202  // not be stashed. If that is the case, then we can't stash this value, as
203  // we would then reorder the values at reinsertion.
204  if (llvm::none_of(FrameIndexValues, Overlaps))
205  EntryDbgValues[&MBB].push_back(&MI);
206  }
207 
208  // Remove stashed debug values from the block.
209  if (EntryDbgValues.count(&MBB))
210  for (auto *MI : EntryDbgValues[&MBB])
211  MI->removeFromParent();
212 }
213 
214 /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
215 /// frame indexes with appropriate references.
216 bool PEI::runOnMachineFunction(MachineFunction &MF) {
217  NumFuncSeen++;
218  const Function &F = MF.getFunction();
221 
222  RS = TRI->requiresRegisterScavenging(MF) ? new RegScavenger() : nullptr;
223  FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(MF);
224  ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
225 
226  // Calculate the MaxCallFrameSize and AdjustsStack variables for the
227  // function's frame information. Also eliminates call frame pseudo
228  // instructions.
229  calculateCallFrameInfo(MF);
230 
231  // Determine placement of CSR spill/restore code and prolog/epilog code:
232  // place all spills in the entry block, all restores in return blocks.
233  calculateSaveRestoreBlocks(MF);
234 
235  // Stash away DBG_VALUEs that should not be moved by insertion of prolog code.
236  SavedDbgValuesMap EntryDbgValues;
237  for (MachineBasicBlock *SaveBlock : SaveBlocks)
238  stashEntryDbgValues(*SaveBlock, EntryDbgValues);
239 
240  // Handle CSR spilling and restoring, for targets that need it.
241  if (MF.getTarget().usesPhysRegsForValues())
242  spillCalleeSavedRegs(MF);
243 
244  // Allow the target machine to make final modifications to the function
245  // before the frame layout is finalized.
247 
248  // Calculate actual frame offsets for all abstract stack objects...
249  calculateFrameObjectOffsets(MF);
250 
251  // Add prolog and epilog code to the function. This function is required
252  // to align the stack frame as necessary for any stack variables or
253  // called functions. Because of this, calculateCalleeSavedRegisters()
254  // must be called before this function in order to set the AdjustsStack
255  // and MaxCallFrameSize variables.
256  if (!F.hasFnAttribute(Attribute::Naked))
257  insertPrologEpilogCode(MF);
258 
259  // Reinsert stashed debug values at the start of the entry blocks.
260  for (auto &I : EntryDbgValues)
261  I.first->insert(I.first->begin(), I.second.begin(), I.second.end());
262 
263  // Allow the target machine to make final modifications to the function
264  // before the frame layout is finalized.
266 
267  // Replace all MO_FrameIndex operands with physical register references
268  // and actual offsets.
269  //
270  replaceFrameIndices(MF);
271 
272  // If register scavenging is needed, as we've enabled doing it as a
273  // post-pass, scavenge the virtual registers that frame index elimination
274  // inserted.
275  if (TRI->requiresRegisterScavenging(MF) && FrameIndexVirtualScavenging)
276  scavengeFrameVirtualRegs(MF, *RS);
277 
278  // Warn on stack size when we exceeds the given limit.
279  MachineFrameInfo &MFI = MF.getFrameInfo();
280  uint64_t StackSize = MFI.getStackSize();
281  if (WarnStackSize.getNumOccurrences() > 0 && WarnStackSize < StackSize) {
282  DiagnosticInfoStackSize DiagStackSize(F, StackSize);
283  F.getContext().diagnose(DiagStackSize);
284  }
285  ORE->emit([&]() {
286  return MachineOptimizationRemarkAnalysis(DEBUG_TYPE, "StackSize",
287  MF.getFunction().getSubprogram(),
288  &MF.front())
289  << ore::NV("NumStackBytes", StackSize) << " stack bytes in function";
290  });
291 
292  delete RS;
293  SaveBlocks.clear();
294  RestoreBlocks.clear();
295  MFI.setSavePoint(nullptr);
296  MFI.setRestorePoint(nullptr);
297  return true;
298 }
299 
300 /// Calculate the MaxCallFrameSize and AdjustsStack
301 /// variables for the function's frame information and eliminate call frame
302 /// pseudo instructions.
303 void PEI::calculateCallFrameInfo(MachineFunction &MF) {
304  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
306  MachineFrameInfo &MFI = MF.getFrameInfo();
307 
308  unsigned MaxCallFrameSize = 0;
309  bool AdjustsStack = MFI.adjustsStack();
310 
311  // Get the function call frame set-up and tear-down instruction opcode
312  unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
313  unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
314 
315  // Early exit for targets which have no call frame setup/destroy pseudo
316  // instructions.
317  if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
318  return;
319 
320  std::vector<MachineBasicBlock::iterator> FrameSDOps;
321  for (MachineBasicBlock &BB : MF)
322  for (MachineBasicBlock::iterator I = BB.begin(); I != BB.end(); ++I)
323  if (TII.isFrameInstr(*I)) {
324  unsigned Size = TII.getFrameSize(*I);
325  if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
326  AdjustsStack = true;
327  FrameSDOps.push_back(I);
328  } else if (I->isInlineAsm()) {
329  // Some inline asm's need a stack frame, as indicated by operand 1.
330  unsigned ExtraInfo = I->getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
331  if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
332  AdjustsStack = true;
333  }
334 
336  (MFI.getMaxCallFrameSize() == MaxCallFrameSize &&
337  MFI.adjustsStack() == AdjustsStack));
338  MFI.setAdjustsStack(AdjustsStack);
339  MFI.setMaxCallFrameSize(MaxCallFrameSize);
340 
341  for (MachineBasicBlock::iterator I : FrameSDOps) {
342  // If call frames are not being included as part of the stack frame, and
343  // the target doesn't indicate otherwise, remove the call frame pseudos
344  // here. The sub/add sp instruction pairs are still inserted, but we don't
345  // need to track the SP adjustment for frame index elimination.
346  if (TFI->canSimplifyCallFramePseudos(MF))
347  TFI->eliminateCallFramePseudoInstr(MF, *I->getParent(), I);
348  }
349 }
350 
351 /// Compute the sets of entry and return blocks for saving and restoring
352 /// callee-saved registers, and placing prolog and epilog code.
353 void PEI::calculateSaveRestoreBlocks(MachineFunction &MF) {
354  const MachineFrameInfo &MFI = MF.getFrameInfo();
355 
356  // Even when we do not change any CSR, we still want to insert the
357  // prologue and epilogue of the function.
358  // So set the save points for those.
359 
360  // Use the points found by shrink-wrapping, if any.
361  if (MFI.getSavePoint()) {
362  SaveBlocks.push_back(MFI.getSavePoint());
363  assert(MFI.getRestorePoint() && "Both restore and save must be set");
364  MachineBasicBlock *RestoreBlock = MFI.getRestorePoint();
365  // If RestoreBlock does not have any successor and is not a return block
366  // then the end point is unreachable and we do not need to insert any
367  // epilogue.
368  if (!RestoreBlock->succ_empty() || RestoreBlock->isReturnBlock())
369  RestoreBlocks.push_back(RestoreBlock);
370  return;
371  }
372 
373  // Save refs to entry and return blocks.
374  SaveBlocks.push_back(&MF.front());
375  for (MachineBasicBlock &MBB : MF) {
376  if (MBB.isEHFuncletEntry())
377  SaveBlocks.push_back(&MBB);
378  if (MBB.isReturnBlock())
379  RestoreBlocks.push_back(&MBB);
380  }
381 }
382 
384  const BitVector &SavedRegs,
385  unsigned &MinCSFrameIndex,
386  unsigned &MaxCSFrameIndex) {
387  if (SavedRegs.empty())
388  return;
389 
390  const TargetRegisterInfo *RegInfo = F.getSubtarget().getRegisterInfo();
391  const MCPhysReg *CSRegs = F.getRegInfo().getCalleeSavedRegs();
392 
393  std::vector<CalleeSavedInfo> CSI;
394  for (unsigned i = 0; CSRegs[i]; ++i) {
395  unsigned Reg = CSRegs[i];
396  if (SavedRegs.test(Reg))
397  CSI.push_back(CalleeSavedInfo(Reg));
398  }
399 
400  const TargetFrameLowering *TFI = F.getSubtarget().getFrameLowering();
401  MachineFrameInfo &MFI = F.getFrameInfo();
402  if (!TFI->assignCalleeSavedSpillSlots(F, RegInfo, CSI)) {
403  // If target doesn't implement this, use generic code.
404 
405  if (CSI.empty())
406  return; // Early exit if no callee saved registers are modified!
407 
408  unsigned NumFixedSpillSlots;
409  const TargetFrameLowering::SpillSlot *FixedSpillSlots =
410  TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
411 
412  // Now that we know which registers need to be saved and restored, allocate
413  // stack slots for them.
414  for (auto &CS : CSI) {
415  // If the target has spilled this register to another register, we don't
416  // need to allocate a stack slot.
417  if (CS.isSpilledToReg())
418  continue;
419 
420  unsigned Reg = CS.getReg();
421  const TargetRegisterClass *RC = RegInfo->getMinimalPhysRegClass(Reg);
422 
423  int FrameIdx;
424  if (RegInfo->hasReservedSpillSlot(F, Reg, FrameIdx)) {
425  CS.setFrameIdx(FrameIdx);
426  continue;
427  }
428 
429  // Check to see if this physreg must be spilled to a particular stack slot
430  // on this target.
431  const TargetFrameLowering::SpillSlot *FixedSlot = FixedSpillSlots;
432  while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
433  FixedSlot->Reg != Reg)
434  ++FixedSlot;
435 
436  unsigned Size = RegInfo->getSpillSize(*RC);
437  if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
438  // Nope, just spill it anywhere convenient.
439  Align Alignment(RegInfo->getSpillAlignment(*RC));
440  // We may not be able to satisfy the desired alignment specification of
441  // the TargetRegisterClass if the stack alignment is smaller. Use the
442  // min.
443  Alignment = std::min(Alignment, TFI->getStackAlign());
444  FrameIdx = MFI.CreateStackObject(Size, Alignment, true);
445  if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
446  if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
447  } else {
448  // Spill it to the stack where we must.
449  FrameIdx = MFI.CreateFixedSpillStackObject(Size, FixedSlot->Offset);
450  }
451 
452  CS.setFrameIdx(FrameIdx);
453  }
454  }
455 
456  MFI.setCalleeSavedInfo(CSI);
457 }
458 
459 /// Helper function to update the liveness information for the callee-saved
460 /// registers.
461 static void updateLiveness(MachineFunction &MF) {
462  MachineFrameInfo &MFI = MF.getFrameInfo();
463  // Visited will contain all the basic blocks that are in the region
464  // where the callee saved registers are alive:
465  // - Anything that is not Save or Restore -> LiveThrough.
466  // - Save -> LiveIn.
467  // - Restore -> LiveOut.
468  // The live-out is not attached to the block, so no need to keep
469  // Restore in this set.
472  MachineBasicBlock *Entry = &MF.front();
473  MachineBasicBlock *Save = MFI.getSavePoint();
474 
475  if (!Save)
476  Save = Entry;
477 
478  if (Entry != Save) {
479  WorkList.push_back(Entry);
480  Visited.insert(Entry);
481  }
482  Visited.insert(Save);
483 
484  MachineBasicBlock *Restore = MFI.getRestorePoint();
485  if (Restore)
486  // By construction Restore cannot be visited, otherwise it
487  // means there exists a path to Restore that does not go
488  // through Save.
489  WorkList.push_back(Restore);
490 
491  while (!WorkList.empty()) {
492  const MachineBasicBlock *CurBB = WorkList.pop_back_val();
493  // By construction, the region that is after the save point is
494  // dominated by the Save and post-dominated by the Restore.
495  if (CurBB == Save && Save != Restore)
496  continue;
497  // Enqueue all the successors not already visited.
498  // Those are by construction either before Save or after Restore.
499  for (MachineBasicBlock *SuccBB : CurBB->successors())
500  if (Visited.insert(SuccBB).second)
501  WorkList.push_back(SuccBB);
502  }
503 
504  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
505 
507  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
508  for (MachineBasicBlock *MBB : Visited) {
509  MCPhysReg Reg = CSI[i].getReg();
510  // Add the callee-saved register as live-in.
511  // It's killed at the spill.
512  if (!MRI.isReserved(Reg) && !MBB->isLiveIn(Reg))
513  MBB->addLiveIn(Reg);
514  }
515  // If callee-saved register is spilled to another register rather than
516  // spilling to stack, the destination register has to be marked as live for
517  // each MBB between the prologue and epilogue so that it is not clobbered
518  // before it is reloaded in the epilogue. The Visited set contains all
519  // blocks outside of the region delimited by prologue/epilogue.
520  if (CSI[i].isSpilledToReg()) {
521  for (MachineBasicBlock &MBB : MF) {
522  if (Visited.count(&MBB))
523  continue;
524  MCPhysReg DstReg = CSI[i].getDstReg();
525  if (!MBB.isLiveIn(DstReg))
526  MBB.addLiveIn(DstReg);
527  }
528  }
529  }
530 
531 }
532 
533 /// Insert restore code for the callee-saved registers used in the function.
534 static void insertCSRSaves(MachineBasicBlock &SaveBlock,
536  MachineFunction &MF = *SaveBlock.getParent();
537  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
540 
541  MachineBasicBlock::iterator I = SaveBlock.begin();
542  if (!TFI->spillCalleeSavedRegisters(SaveBlock, I, CSI, TRI)) {
543  for (const CalleeSavedInfo &CS : CSI) {
544  // Insert the spill to the stack frame.
545  unsigned Reg = CS.getReg();
546 
547  if (CS.isSpilledToReg()) {
548  BuildMI(SaveBlock, I, DebugLoc(),
549  TII.get(TargetOpcode::COPY), CS.getDstReg())
550  .addReg(Reg, getKillRegState(true));
551  } else {
553  TII.storeRegToStackSlot(SaveBlock, I, Reg, true, CS.getFrameIdx(), RC,
554  TRI);
555  }
556  }
557  }
558 }
559 
560 /// Insert restore code for the callee-saved registers used in the function.
561 static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
562  std::vector<CalleeSavedInfo> &CSI) {
563  MachineFunction &MF = *RestoreBlock.getParent();
564  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
567 
568  // Restore all registers immediately before the return and any
569  // terminators that precede it.
571 
572  if (!TFI->restoreCalleeSavedRegisters(RestoreBlock, I, CSI, TRI)) {
573  for (const CalleeSavedInfo &CI : reverse(CSI)) {
574  unsigned Reg = CI.getReg();
575  if (CI.isSpilledToReg()) {
576  BuildMI(RestoreBlock, I, DebugLoc(), TII.get(TargetOpcode::COPY), Reg)
577  .addReg(CI.getDstReg(), getKillRegState(true));
578  } else {
580  TII.loadRegFromStackSlot(RestoreBlock, I, Reg, CI.getFrameIdx(), RC, TRI);
581  assert(I != RestoreBlock.begin() &&
582  "loadRegFromStackSlot didn't insert any code!");
583  // Insert in reverse order. loadRegFromStackSlot can insert
584  // multiple instructions.
585  }
586  }
587  }
588 }
589 
590 void PEI::spillCalleeSavedRegs(MachineFunction &MF) {
591  // We can't list this requirement in getRequiredProperties because some
592  // targets (WebAssembly) use virtual registers past this point, and the pass
593  // pipeline is set up without giving the passes a chance to look at the
594  // TargetMachine.
595  // FIXME: Find a way to express this in getRequiredProperties.
598 
599  const Function &F = MF.getFunction();
601  MachineFrameInfo &MFI = MF.getFrameInfo();
602  MinCSFrameIndex = std::numeric_limits<unsigned>::max();
603  MaxCSFrameIndex = 0;
604 
605  // Determine which of the registers in the callee save list should be saved.
606  BitVector SavedRegs;
607  TFI->determineCalleeSaves(MF, SavedRegs, RS);
608 
609  // Assign stack slots for any callee-saved registers that must be spilled.
610  assignCalleeSavedSpillSlots(MF, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex);
611 
612  // Add the code to save and restore the callee saved registers.
613  if (!F.hasFnAttribute(Attribute::Naked)) {
614  MFI.setCalleeSavedInfoValid(true);
615 
616  std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
617  if (!CSI.empty()) {
618  if (!MFI.hasCalls())
619  NumLeafFuncWithSpills++;
620 
621  for (MachineBasicBlock *SaveBlock : SaveBlocks)
622  insertCSRSaves(*SaveBlock, CSI);
623 
624  // Update the live-in information of all the blocks up to the save point.
625  updateLiveness(MF);
626 
627  for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
628  insertCSRRestores(*RestoreBlock, CSI);
629  }
630  }
631 }
632 
633 /// AdjustStackOffset - Helper function used to adjust the stack frame offset.
634 static inline void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx,
635  bool StackGrowsDown, int64_t &Offset,
636  Align &MaxAlign, unsigned Skew) {
637  // If the stack grows down, add the object size to find the lowest address.
638  if (StackGrowsDown)
639  Offset += MFI.getObjectSize(FrameIdx);
640 
641  Align Alignment = MFI.getObjectAlign(FrameIdx);
642 
643  // If the alignment of this object is greater than that of the stack, then
644  // increase the stack alignment to match.
645  MaxAlign = std::max(MaxAlign, Alignment);
646 
647  // Adjust to alignment boundary.
648  Offset = alignTo(Offset, Alignment, Skew);
649 
650  if (StackGrowsDown) {
651  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset
652  << "]\n");
653  MFI.setObjectOffset(FrameIdx, -Offset); // Set the computed offset
654  } else {
655  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset
656  << "]\n");
657  MFI.setObjectOffset(FrameIdx, Offset);
658  Offset += MFI.getObjectSize(FrameIdx);
659  }
660 }
661 
662 /// Compute which bytes of fixed and callee-save stack area are unused and keep
663 /// track of them in StackBytesFree.
664 static inline void
665 computeFreeStackSlots(MachineFrameInfo &MFI, bool StackGrowsDown,
666  unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex,
667  int64_t FixedCSEnd, BitVector &StackBytesFree) {
668  // Avoid undefined int64_t -> int conversion below in extreme case.
669  if (FixedCSEnd > std::numeric_limits<int>::max())
670  return;
671 
672  StackBytesFree.resize(FixedCSEnd, true);
673 
674  SmallVector<int, 16> AllocatedFrameSlots;
675  // Add fixed objects.
676  for (int i = MFI.getObjectIndexBegin(); i != 0; ++i)
677  // StackSlot scavenging is only implemented for the default stack.
678  if (MFI.getStackID(i) == TargetStackID::Default)
679  AllocatedFrameSlots.push_back(i);
680  // Add callee-save objects.
681  for (int i = MinCSFrameIndex; i <= (int)MaxCSFrameIndex; ++i)
682  if (MFI.getStackID(i) == TargetStackID::Default)
683  AllocatedFrameSlots.push_back(i);
684 
685  for (int i : AllocatedFrameSlots) {
686  // These are converted from int64_t, but they should always fit in int
687  // because of the FixedCSEnd check above.
688  int ObjOffset = MFI.getObjectOffset(i);
689  int ObjSize = MFI.getObjectSize(i);
690  int ObjStart, ObjEnd;
691  if (StackGrowsDown) {
692  // ObjOffset is negative when StackGrowsDown is true.
693  ObjStart = -ObjOffset - ObjSize;
694  ObjEnd = -ObjOffset;
695  } else {
696  ObjStart = ObjOffset;
697  ObjEnd = ObjOffset + ObjSize;
698  }
699  // Ignore fixed holes that are in the previous stack frame.
700  if (ObjEnd > 0)
701  StackBytesFree.reset(ObjStart, ObjEnd);
702  }
703 }
704 
705 /// Assign frame object to an unused portion of the stack in the fixed stack
706 /// object range. Return true if the allocation was successful.
707 static inline bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx,
708  bool StackGrowsDown, Align MaxAlign,
709  BitVector &StackBytesFree) {
710  if (MFI.isVariableSizedObjectIndex(FrameIdx))
711  return false;
712 
713  if (StackBytesFree.none()) {
714  // clear it to speed up later scavengeStackSlot calls to
715  // StackBytesFree.none()
716  StackBytesFree.clear();
717  return false;
718  }
719 
720  Align ObjAlign = MFI.getObjectAlign(FrameIdx);
721  if (ObjAlign > MaxAlign)
722  return false;
723 
724  int64_t ObjSize = MFI.getObjectSize(FrameIdx);
725  int FreeStart;
726  for (FreeStart = StackBytesFree.find_first(); FreeStart != -1;
727  FreeStart = StackBytesFree.find_next(FreeStart)) {
728 
729  // Check that free space has suitable alignment.
730  unsigned ObjStart = StackGrowsDown ? FreeStart + ObjSize : FreeStart;
731  if (alignTo(ObjStart, ObjAlign) != ObjStart)
732  continue;
733 
734  if (FreeStart + ObjSize > StackBytesFree.size())
735  return false;
736 
737  bool AllBytesFree = true;
738  for (unsigned Byte = 0; Byte < ObjSize; ++Byte)
739  if (!StackBytesFree.test(FreeStart + Byte)) {
740  AllBytesFree = false;
741  break;
742  }
743  if (AllBytesFree)
744  break;
745  }
746 
747  if (FreeStart == -1)
748  return false;
749 
750  if (StackGrowsDown) {
751  int ObjStart = -(FreeStart + ObjSize);
752  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP["
753  << ObjStart << "]\n");
754  MFI.setObjectOffset(FrameIdx, ObjStart);
755  } else {
756  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP["
757  << FreeStart << "]\n");
758  MFI.setObjectOffset(FrameIdx, FreeStart);
759  }
760 
761  StackBytesFree.reset(FreeStart, FreeStart + ObjSize);
762  return true;
763 }
764 
765 /// AssignProtectedObjSet - Helper function to assign large stack objects (i.e.,
766 /// those required to be close to the Stack Protector) to stack offsets.
767 static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
768  SmallSet<int, 16> &ProtectedObjs,
769  MachineFrameInfo &MFI, bool StackGrowsDown,
770  int64_t &Offset, Align &MaxAlign,
771  unsigned Skew) {
772 
773  for (int i : UnassignedObjs) {
774  AdjustStackOffset(MFI, i, StackGrowsDown, Offset, MaxAlign, Skew);
775  ProtectedObjs.insert(i);
776  }
777 }
778 
779 /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
780 /// abstract stack objects.
781 void PEI::calculateFrameObjectOffsets(MachineFunction &MF) {
783 
784  bool StackGrowsDown =
786 
787  // Loop over all of the stack objects, assigning sequential addresses...
788  MachineFrameInfo &MFI = MF.getFrameInfo();
789 
790  // Start at the beginning of the local area.
791  // The Offset is the distance from the stack top in the direction
792  // of stack growth -- so it's always nonnegative.
793  int LocalAreaOffset = TFI.getOffsetOfLocalArea();
794  if (StackGrowsDown)
795  LocalAreaOffset = -LocalAreaOffset;
796  assert(LocalAreaOffset >= 0
797  && "Local area offset should be in direction of stack growth");
798  int64_t Offset = LocalAreaOffset;
799 
800  // Skew to be applied to alignment.
801  unsigned Skew = TFI.getStackAlignmentSkew(MF);
802 
803 #ifdef EXPENSIVE_CHECKS
804  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i)
805  if (!MFI.isDeadObjectIndex(i) &&
807  assert(MFI.getObjectAlign(i) <= MFI.getMaxAlign() &&
808  "MaxAlignment is invalid");
809 #endif
810 
811  // If there are fixed sized objects that are preallocated in the local area,
812  // non-fixed objects can't be allocated right at the start of local area.
813  // Adjust 'Offset' to point to the end of last fixed sized preallocated
814  // object.
815  for (int i = MFI.getObjectIndexBegin(); i != 0; ++i) {
816  if (MFI.getStackID(i) !=
817  TargetStackID::Default) // Only allocate objects on the default stack.
818  continue;
819 
820  int64_t FixedOff;
821  if (StackGrowsDown) {
822  // The maximum distance from the stack pointer is at lower address of
823  // the object -- which is given by offset. For down growing stack
824  // the offset is negative, so we negate the offset to get the distance.
825  FixedOff = -MFI.getObjectOffset(i);
826  } else {
827  // The maximum distance from the start pointer is at the upper
828  // address of the object.
829  FixedOff = MFI.getObjectOffset(i) + MFI.getObjectSize(i);
830  }
831  if (FixedOff > Offset) Offset = FixedOff;
832  }
833 
834  // First assign frame offsets to stack objects that are used to spill
835  // callee saved registers.
836  if (StackGrowsDown) {
837  for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
838  if (MFI.getStackID(i) !=
839  TargetStackID::Default) // Only allocate objects on the default stack.
840  continue;
841 
842  // If the stack grows down, we need to add the size to find the lowest
843  // address of the object.
844  Offset += MFI.getObjectSize(i);
845 
846  // Adjust to alignment boundary
847  Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
848 
849  LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n");
850  MFI.setObjectOffset(i, -Offset); // Set the computed offset
851  }
852  } else if (MaxCSFrameIndex >= MinCSFrameIndex) {
853  // Be careful about underflow in comparisons agains MinCSFrameIndex.
854  for (unsigned i = MaxCSFrameIndex; i != MinCSFrameIndex - 1; --i) {
855  if (MFI.getStackID(i) !=
856  TargetStackID::Default) // Only allocate objects on the default stack.
857  continue;
858 
859  if (MFI.isDeadObjectIndex(i))
860  continue;
861 
862  // Adjust to alignment boundary
863  Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
864 
865  LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n");
866  MFI.setObjectOffset(i, Offset);
867  Offset += MFI.getObjectSize(i);
868  }
869  }
870 
871  // FixedCSEnd is the stack offset to the end of the fixed and callee-save
872  // stack area.
873  int64_t FixedCSEnd = Offset;
874  Align MaxAlign = MFI.getMaxAlign();
875 
876  // Make sure the special register scavenging spill slot is closest to the
877  // incoming stack pointer if a frame pointer is required and is closer
878  // to the incoming rather than the final stack pointer.
879  const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
880  bool EarlyScavengingSlots = (TFI.hasFP(MF) && TFI.isFPCloseToIncomingSP() &&
881  RegInfo->useFPForScavengingIndex(MF) &&
882  !RegInfo->hasStackRealignment(MF));
883  if (RS && EarlyScavengingSlots) {
884  SmallVector<int, 2> SFIs;
885  RS->getScavengingFrameIndices(SFIs);
886  for (int SFI : SFIs)
887  AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign, Skew);
888  }
889 
890  // FIXME: Once this is working, then enable flag will change to a target
891  // check for whether the frame is large enough to want to use virtual
892  // frame index registers. Functions which don't want/need this optimization
893  // will continue to use the existing code path.
895  Align Alignment = MFI.getLocalFrameMaxAlign();
896 
897  // Adjust to alignment boundary.
898  Offset = alignTo(Offset, Alignment, Skew);
899 
900  LLVM_DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n");
901 
902  // Resolve offsets for objects in the local block.
903  for (unsigned i = 0, e = MFI.getLocalFrameObjectCount(); i != e; ++i) {
904  std::pair<int, int64_t> Entry = MFI.getLocalFrameObjectMap(i);
905  int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second;
906  LLVM_DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" << FIOffset
907  << "]\n");
908  MFI.setObjectOffset(Entry.first, FIOffset);
909  }
910  // Allocate the local block
911  Offset += MFI.getLocalFrameSize();
912 
913  MaxAlign = std::max(Alignment, MaxAlign);
914  }
915 
916  // Retrieve the Exception Handler registration node.
917  int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
918  if (const WinEHFuncInfo *FuncInfo = MF.getWinEHFuncInfo())
919  EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
920 
921  // Make sure that the stack protector comes before the local variables on the
922  // stack.
923  SmallSet<int, 16> ProtectedObjs;
924  if (MFI.hasStackProtectorIndex()) {
925  int StackProtectorFI = MFI.getStackProtectorIndex();
926  StackObjSet LargeArrayObjs;
927  StackObjSet SmallArrayObjs;
928  StackObjSet AddrOfObjs;
929 
930  // If we need a stack protector, we need to make sure that
931  // LocalStackSlotPass didn't already allocate a slot for it.
932  // If we are told to use the LocalStackAllocationBlock, the stack protector
933  // is expected to be already pre-allocated.
935  AdjustStackOffset(MFI, StackProtectorFI, StackGrowsDown, Offset, MaxAlign,
936  Skew);
937  else if (!MFI.isObjectPreAllocated(MFI.getStackProtectorIndex()))
939  "Stack protector not pre-allocated by LocalStackSlotPass.");
940 
941  // Assign large stack objects first.
942  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
944  continue;
945  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
946  continue;
947  if (RS && RS->isScavengingFrameIndex((int)i))
948  continue;
949  if (MFI.isDeadObjectIndex(i))
950  continue;
951  if (StackProtectorFI == (int)i || EHRegNodeFrameIndex == (int)i)
952  continue;
953  if (MFI.getStackID(i) !=
954  TargetStackID::Default) // Only allocate objects on the default stack.
955  continue;
956 
957  switch (MFI.getObjectSSPLayout(i)) {
959  continue;
961  SmallArrayObjs.insert(i);
962  continue;
964  AddrOfObjs.insert(i);
965  continue;
967  LargeArrayObjs.insert(i);
968  continue;
969  }
970  llvm_unreachable("Unexpected SSPLayoutKind.");
971  }
972 
973  // We expect **all** the protected stack objects to be pre-allocated by
974  // LocalStackSlotPass. If it turns out that PEI still has to allocate some
975  // of them, we may end up messing up the expected order of the objects.
977  !(LargeArrayObjs.empty() && SmallArrayObjs.empty() &&
978  AddrOfObjs.empty()))
979  llvm_unreachable("Found protected stack objects not pre-allocated by "
980  "LocalStackSlotPass.");
981 
982  AssignProtectedObjSet(LargeArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
983  Offset, MaxAlign, Skew);
984  AssignProtectedObjSet(SmallArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
985  Offset, MaxAlign, Skew);
986  AssignProtectedObjSet(AddrOfObjs, ProtectedObjs, MFI, StackGrowsDown,
987  Offset, MaxAlign, Skew);
988  }
989 
990  SmallVector<int, 8> ObjectsToAllocate;
991 
992  // Then prepare to assign frame offsets to stack objects that are not used to
993  // spill callee saved registers.
994  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
996  continue;
997  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
998  continue;
999  if (RS && RS->isScavengingFrameIndex((int)i))
1000  continue;
1001  if (MFI.isDeadObjectIndex(i))
1002  continue;
1003  if (MFI.getStackProtectorIndex() == (int)i || EHRegNodeFrameIndex == (int)i)
1004  continue;
1005  if (ProtectedObjs.count(i))
1006  continue;
1007  if (MFI.getStackID(i) !=
1008  TargetStackID::Default) // Only allocate objects on the default stack.
1009  continue;
1010 
1011  // Add the objects that we need to allocate to our working set.
1012  ObjectsToAllocate.push_back(i);
1013  }
1014 
1015  // Allocate the EH registration node first if one is present.
1016  if (EHRegNodeFrameIndex != std::numeric_limits<int>::max())
1017  AdjustStackOffset(MFI, EHRegNodeFrameIndex, StackGrowsDown, Offset,
1018  MaxAlign, Skew);
1019 
1020  // Give the targets a chance to order the objects the way they like it.
1021  if (MF.getTarget().getOptLevel() != CodeGenOpt::None &&
1023  TFI.orderFrameObjects(MF, ObjectsToAllocate);
1024 
1025  // Keep track of which bytes in the fixed and callee-save range are used so we
1026  // can use the holes when allocating later stack objects. Only do this if
1027  // stack protector isn't being used and the target requests it and we're
1028  // optimizing.
1029  BitVector StackBytesFree;
1030  if (!ObjectsToAllocate.empty() &&
1033  computeFreeStackSlots(MFI, StackGrowsDown, MinCSFrameIndex, MaxCSFrameIndex,
1034  FixedCSEnd, StackBytesFree);
1035 
1036  // Now walk the objects and actually assign base offsets to them.
1037  for (auto &Object : ObjectsToAllocate)
1038  if (!scavengeStackSlot(MFI, Object, StackGrowsDown, MaxAlign,
1039  StackBytesFree))
1040  AdjustStackOffset(MFI, Object, StackGrowsDown, Offset, MaxAlign, Skew);
1041 
1042  // Make sure the special register scavenging spill slot is closest to the
1043  // stack pointer.
1044  if (RS && !EarlyScavengingSlots) {
1045  SmallVector<int, 2> SFIs;
1046  RS->getScavengingFrameIndices(SFIs);
1047  for (int SFI : SFIs)
1048  AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign, Skew);
1049  }
1050 
1051  if (!TFI.targetHandlesStackFrameRounding()) {
1052  // If we have reserved argument space for call sites in the function
1053  // immediately on entry to the current function, count it as part of the
1054  // overall stack size.
1055  if (MFI.adjustsStack() && TFI.hasReservedCallFrame(MF))
1056  Offset += MFI.getMaxCallFrameSize();
1057 
1058  // Round up the size to a multiple of the alignment. If the function has
1059  // any calls or alloca's, align to the target's StackAlignment value to
1060  // ensure that the callee's frame or the alloca data is suitably aligned;
1061  // otherwise, for leaf functions, align to the TransientStackAlignment
1062  // value.
1063  Align StackAlign;
1064  if (MFI.adjustsStack() || MFI.hasVarSizedObjects() ||
1065  (RegInfo->hasStackRealignment(MF) && MFI.getObjectIndexEnd() != 0))
1066  StackAlign = TFI.getStackAlign();
1067  else
1069 
1070  // If the frame pointer is eliminated, all frame offsets will be relative to
1071  // SP not FP. Align to MaxAlign so this works.
1072  StackAlign = std::max(StackAlign, MaxAlign);
1073  int64_t OffsetBeforeAlignment = Offset;
1074  Offset = alignTo(Offset, StackAlign, Skew);
1075 
1076  // If we have increased the offset to fulfill the alignment constrants,
1077  // then the scavenging spill slots may become harder to reach from the
1078  // stack pointer, float them so they stay close.
1079  if (StackGrowsDown && OffsetBeforeAlignment != Offset && RS &&
1080  !EarlyScavengingSlots) {
1081  SmallVector<int, 2> SFIs;
1082  RS->getScavengingFrameIndices(SFIs);
1083  LLVM_DEBUG(if (!SFIs.empty()) llvm::dbgs()
1084  << "Adjusting emergency spill slots!\n";);
1085  int64_t Delta = Offset - OffsetBeforeAlignment;
1086  for (int SFI : SFIs) {
1088  << "Adjusting offset of emergency spill slot #" << SFI
1089  << " from " << MFI.getObjectOffset(SFI););
1090  MFI.setObjectOffset(SFI, MFI.getObjectOffset(SFI) - Delta);
1091  LLVM_DEBUG(llvm::dbgs() << " to " << MFI.getObjectOffset(SFI) << "\n";);
1092  }
1093  }
1094  }
1095 
1096  // Update frame info to pretend that this is part of the stack...
1097  int64_t StackSize = Offset - LocalAreaOffset;
1098  MFI.setStackSize(StackSize);
1099  NumBytesStackSpace += StackSize;
1100 }
1101 
1102 /// insertPrologEpilogCode - Scan the function for modified callee saved
1103 /// registers, insert spill code for these callee saved registers, then add
1104 /// prolog and epilog code to the function.
1105 void PEI::insertPrologEpilogCode(MachineFunction &MF) {
1106  const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering();
1107 
1108  // Add prologue to the function...
1109  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1110  TFI.emitPrologue(MF, *SaveBlock);
1111 
1112  // Add epilogue to restore the callee-save registers in each exiting block.
1113  for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
1114  TFI.emitEpilogue(MF, *RestoreBlock);
1115 
1116  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1117  TFI.inlineStackProbe(MF, *SaveBlock);
1118 
1119  // Emit additional code that is required to support segmented stacks, if
1120  // we've been asked for it. This, when linked with a runtime with support
1121  // for segmented stacks (libgcc is one), will result in allocating stack
1122  // space in small chunks instead of one large contiguous block.
1123  if (MF.shouldSplitStack()) {
1124  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1125  TFI.adjustForSegmentedStacks(MF, *SaveBlock);
1126  // Record that there are split-stack functions, so we will emit a
1127  // special section to tell the linker.
1128  MF.getMMI().setHasSplitStack(true);
1129  } else
1130  MF.getMMI().setHasNosplitStack(true);
1131 
1132  // Emit additional code that is required to explicitly handle the stack in
1133  // HiPE native code (if needed) when loaded in the Erlang/OTP runtime. The
1134  // approach is rather similar to that of Segmented Stacks, but it uses a
1135  // different conditional check and another BIF for allocating more stack
1136  // space.
1138  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1139  TFI.adjustForHiPEPrologue(MF, *SaveBlock);
1140 }
1141 
1142 /// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
1143 /// register references and actual offsets.
1144 void PEI::replaceFrameIndices(MachineFunction &MF) {
1145  const auto &ST = MF.getSubtarget();
1146  const TargetFrameLowering &TFI = *ST.getFrameLowering();
1147  if (!TFI.needsFrameIndexResolution(MF))
1148  return;
1149 
1150  const TargetRegisterInfo *TRI = ST.getRegisterInfo();
1151 
1152  // Allow the target to determine this after knowing the frame size.
1153  FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) ||
1155 
1156  // Store SPAdj at exit of a basic block.
1157  SmallVector<int, 8> SPState;
1158  SPState.resize(MF.getNumBlockIDs());
1160 
1161  // Iterate over the reachable blocks in DFS order.
1162  for (auto DFI = df_ext_begin(&MF, Reachable), DFE = df_ext_end(&MF, Reachable);
1163  DFI != DFE; ++DFI) {
1164  int SPAdj = 0;
1165  // Check the exit state of the DFS stack predecessor.
1166  if (DFI.getPathLength() >= 2) {
1167  MachineBasicBlock *StackPred = DFI.getPath(DFI.getPathLength() - 2);
1168  assert(Reachable.count(StackPred) &&
1169  "DFS stack predecessor is already visited.\n");
1170  SPAdj = SPState[StackPred->getNumber()];
1171  }
1172  MachineBasicBlock *BB = *DFI;
1173  replaceFrameIndices(BB, MF, SPAdj);
1174  SPState[BB->getNumber()] = SPAdj;
1175  }
1176 
1177  // Handle the unreachable blocks.
1178  for (auto &BB : MF) {
1179  if (Reachable.count(&BB))
1180  // Already handled in DFS traversal.
1181  continue;
1182  int SPAdj = 0;
1183  replaceFrameIndices(&BB, MF, SPAdj);
1184  }
1185 }
1186 
1187 void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF,
1188  int &SPAdj) {
1190  "getRegisterInfo() must be implemented!");
1191  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
1194 
1195  if (RS && FrameIndexEliminationScavenging)
1196  RS->enterBasicBlock(*BB);
1197 
1198  bool InsideCallSequence = false;
1199 
1200  for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
1201  if (TII.isFrameInstr(*I)) {
1202  InsideCallSequence = TII.isFrameSetup(*I);
1203  SPAdj += TII.getSPAdjust(*I);
1204  I = TFI->eliminateCallFramePseudoInstr(MF, *BB, I);
1205  continue;
1206  }
1207 
1208  MachineInstr &MI = *I;
1209  bool DoIncr = true;
1210  bool DidFinishLoop = true;
1211  for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
1212  if (!MI.getOperand(i).isFI())
1213  continue;
1214 
1215  // Frame indices in debug values are encoded in a target independent
1216  // way with simply the frame index and offset rather than any
1217  // target-specific addressing mode.
1218  if (MI.isDebugValue()) {
1219  MachineOperand &Op = MI.getOperand(i);
1220  assert(
1221  MI.isDebugOperand(&Op) &&
1222  "Frame indices can only appear as a debug operand in a DBG_VALUE*"
1223  " machine instruction");
1224  Register Reg;
1225  unsigned FrameIdx = Op.getIndex();
1226  unsigned Size = MF.getFrameInfo().getObjectSize(FrameIdx);
1227 
1229  TFI->getFrameIndexReference(MF, FrameIdx, Reg);
1230  Op.ChangeToRegister(Reg, false /*isDef*/);
1231  Op.setIsDebug();
1232 
1233  const DIExpression *DIExpr = MI.getDebugExpression();
1234 
1235  // If we have a direct DBG_VALUE, and its location expression isn't
1236  // currently complex, then adding an offset will morph it into a
1237  // complex location that is interpreted as being a memory address.
1238  // This changes a pointer-valued variable to dereference that pointer,
1239  // which is incorrect. Fix by adding DW_OP_stack_value.
1240 
1241  if (MI.isNonListDebugValue()) {
1242  unsigned PrependFlags = DIExpression::ApplyOffset;
1243  if (!MI.isIndirectDebugValue() && !DIExpr->isComplex())
1244  PrependFlags |= DIExpression::StackValue;
1245 
1246  // If we have DBG_VALUE that is indirect and has a Implicit location
1247  // expression need to insert a deref before prepending a Memory
1248  // location expression. Also after doing this we change the DBG_VALUE
1249  // to be direct.
1250  if (MI.isIndirectDebugValue() && DIExpr->isImplicit()) {
1251  SmallVector<uint64_t, 2> Ops = {dwarf::DW_OP_deref_size, Size};
1252  bool WithStackValue = true;
1253  DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, WithStackValue);
1254  // Make the DBG_VALUE direct.
1255  MI.getDebugOffset().ChangeToRegister(0, false);
1256  }
1257  DIExpr = TRI.prependOffsetExpression(DIExpr, PrependFlags, Offset);
1258  } else {
1259  // The debug operand at DebugOpIndex was a frame index at offset
1260  // `Offset`; now the operand has been replaced with the frame
1261  // register, we must add Offset with `register x, plus Offset`.
1262  unsigned DebugOpIndex = MI.getDebugOperandIndex(&Op);
1264  TRI.getOffsetOpcodes(Offset, Ops);
1265  DIExpr = DIExpression::appendOpsToArg(DIExpr, Ops, DebugOpIndex);
1266  }
1267  MI.getDebugExpressionOp().setMetadata(DIExpr);
1268  continue;
1269  }
1270 
1271  // TODO: This code should be commoned with the code for
1272  // PATCHPOINT. There's no good reason for the difference in
1273  // implementation other than historical accident. The only
1274  // remaining difference is the unconditional use of the stack
1275  // pointer as the base register.
1276  if (MI.getOpcode() == TargetOpcode::STATEPOINT) {
1277  assert((!MI.isDebugValue() || i == 0) &&
1278  "Frame indicies can only appear as the first operand of a "
1279  "DBG_VALUE machine instruction");
1280  Register Reg;
1281  MachineOperand &Offset = MI.getOperand(i + 1);
1283  MF, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false);
1284  assert(!refOffset.getScalable() &&
1285  "Frame offsets with a scalable component are not supported");
1286  Offset.setImm(Offset.getImm() + refOffset.getFixed() + SPAdj);
1287  MI.getOperand(i).ChangeToRegister(Reg, false /*isDef*/);
1288  continue;
1289  }
1290 
1291  // Some instructions (e.g. inline asm instructions) can have
1292  // multiple frame indices and/or cause eliminateFrameIndex
1293  // to insert more than one instruction. We need the register
1294  // scavenger to go through all of these instructions so that
1295  // it can update its register information. We keep the
1296  // iterator at the point before insertion so that we can
1297  // revisit them in full.
1298  bool AtBeginning = (I == BB->begin());
1299  if (!AtBeginning) --I;
1300 
1301  // If this instruction has a FrameIndex operand, we need to
1302  // use that target machine register info object to eliminate
1303  // it.
1304  TRI.eliminateFrameIndex(MI, SPAdj, i,
1305  FrameIndexEliminationScavenging ? RS : nullptr);
1306 
1307  // Reset the iterator if we were at the beginning of the BB.
1308  if (AtBeginning) {
1309  I = BB->begin();
1310  DoIncr = false;
1311  }
1312 
1313  DidFinishLoop = false;
1314  break;
1315  }
1316 
1317  // If we are looking at a call sequence, we need to keep track of
1318  // the SP adjustment made by each instruction in the sequence.
1319  // This includes both the frame setup/destroy pseudos (handled above),
1320  // as well as other instructions that have side effects w.r.t the SP.
1321  // Note that this must come after eliminateFrameIndex, because
1322  // if I itself referred to a frame index, we shouldn't count its own
1323  // adjustment.
1324  if (DidFinishLoop && InsideCallSequence)
1325  SPAdj += TII.getSPAdjust(MI);
1326 
1327  if (DoIncr && I != BB->end()) ++I;
1328 
1329  // Update register states.
1330  if (RS && FrameIndexEliminationScavenging && DidFinishLoop)
1331  RS->forward(MI);
1332  }
1333 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
i
i
Definition: README.txt:29
llvm::TargetFrameLowering::orderFrameObjects
virtual void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &objectsToAllocate) const
Order the symbols in the local stack frame.
Definition: TargetFrameLowering.h:389
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:158
llvm::TargetMachine::getOptLevel
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition: TargetMachine.cpp:198
llvm::MachineFrameInfo::isMaxCallFrameSizeComputed
bool isMaxCallFrameSizeComputed() const
Definition: MachineFrameInfo.h:650
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition: MachineFrameInfo.h:351
llvm::RISCVAttrs::StackAlign
StackAlign
Definition: RISCVAttributes.h:37
llvm::MachineFunctionProperties::hasProperty
bool hasProperty(Property P) const
Definition: MachineFunction.h:165
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
MachineInstr.h
MathExtras.h
llvm
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::none_of
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1496
llvm::MachineBasicBlock::isLiveIn
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
Definition: MachineBasicBlock.cpp:574
llvm::TargetFrameLowering::needsFrameIndexResolution
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
Definition: TargetFrameLoweringImpl.cpp:60
TargetFrameLowering.h
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:42
DebugInfoMetadata.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::Function
Definition: Function.h:61
computeFreeStackSlots
static void computeFreeStackSlots(MachineFrameInfo &MFI, bool StackGrowsDown, unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex, int64_t FixedCSEnd, BitVector &StackBytesFree)
Compute which bytes of fixed and callee-save stack area are unused and keep track of them in StackByt...
Definition: PrologEpilogInserter.cpp:665
Pass.h
llvm::LLVMTargetMachine::usesPhysRegsForValues
virtual bool usesPhysRegsForValues() const
True if the target uses physical regs (as nearly all targets do).
Definition: TargetMachine.h:461
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
llvm::BitVector::clear
void clear()
clear - Removes all bits from the bitvector.
Definition: BitVector.h:327
llvm::BitVector::none
bool none() const
none - Returns true if none of the bits are set.
Definition: BitVector.h:180
llvm::MachineBasicBlock::isEHFuncletEntry
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
Definition: MachineBasicBlock.h:461
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Statistic.h
InlineAsm.h
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1526
llvm::MachineFrameInfo::getUseLocalStackAllocationBlock
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
Definition: MachineFrameInfo.h:432
ErrorHandling.h
stashEntryDbgValues
static void stashEntryDbgValues(MachineBasicBlock &MBB, SavedDbgValuesMap &EntryDbgValues)
Stash DBG_VALUEs that describe parameters and which are placed at the start of the block.
Definition: PrologEpilogInserter.cpp:179
llvm::MachineOptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: MachineOptimizationRemarkEmitter.h:144
llvm::SmallDenseMap
Definition: DenseMap.h:880
llvm::TargetRegisterInfo::getOffsetOpcodes
virtual void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const
Gets the DWARF expression opcodes for Offset.
Definition: TargetRegisterInfo.cpp:641
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
OptimizationRemarkEmitter.h
MachineBasicBlock.h
llvm::MachineBasicBlock::isReturnBlock
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
Definition: MachineBasicBlock.h:718
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:124
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::MachineFunction::getNumBlockIDs
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Definition: MachineFunction.h:685
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:231
llvm::createPrologEpilogInserterPass
MachineFunctionPass * createPrologEpilogInserterPass()
Definition: PrologEpilogInserter.cpp:155
llvm::MachineFrameInfo::setStackSize
void setStackSize(uint64_t Size)
Set the size of the stack.
Definition: MachineFrameInfo.h:566
llvm::BitVector::resize
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition: BitVector.h:333
llvm::MachineFrameInfo::isObjectPreAllocated
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
Definition: MachineFrameInfo.h:444
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:329
llvm::TargetRegisterInfo::requiresFrameIndexScavenging
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
Definition: TargetRegisterInfo.h:899
TargetInstrInfo.h
llvm::MachineFrameInfo::SSPLK_LargeArray
@ SSPLK_LargeArray
Array or nested array >= SSP-buffer-size.
Definition: MachineFrameInfo.h:114
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
llvm::MachineFrameInfo::setMaxCallFrameSize
void setMaxCallFrameSize(unsigned S)
Definition: MachineFrameInfo.h:653
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:128
llvm::MachineFrameInfo::setAdjustsStack
void setAdjustsStack(bool V)
Definition: MachineFrameInfo.h:599
llvm::TargetFrameLowering::processFunctionBeforeFrameIndicesReplaced
virtual void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
Definition: TargetFrameLowering.h:360
STLExtras.h
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:635
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2559
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition: MachineFrameInfo.h:391
llvm::InlineAsm::Extra_IsAlignStack
@ Extra_IsAlignStack
Definition: InlineAsm.h:222
llvm::TargetRegisterInfo::useFPForScavengingIndex
virtual bool useFPForScavengingIndex(const MachineFunction &MF) const
Returns true if the target wants to use frame pointer based accesses to spill to the scavenger emerge...
Definition: TargetRegisterInfo.h:893
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::MachineFrameInfo::getMaxCallFrameSize
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
Definition: MachineFrameInfo.h:643
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
DepthFirstIterator.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:90
MachineRegisterInfo.h
llvm::TargetFrameLowering::getTransientStackAlign
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
Definition: TargetFrameLowering.h:125
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::df_ext_begin
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
Definition: DepthFirstIterator.h:241
CommandLine.h
llvm::TargetFrameLowering::eliminateCallFramePseudoInstr
virtual MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
Definition: TargetFrameLowering.h:374
llvm::MachineBasicBlock::push_back
void push_back(MachineInstr *MI)
Definition: MachineBasicBlock.h:756
llvm::TargetFrameLowering::processFunctionBeforeFrameFinalized
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition: TargetFrameLowering.h:352
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:752
llvm::DIExpression::appendOpsToArg
static DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
Definition: DebugInfoMetadata.cpp:1283
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:568
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
MachineLoopInfo.h
llvm::TargetFrameLowering::getOffsetOfLocalArea
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Definition: TargetFrameLowering.h:147
TargetMachine.h
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::PrologEpilogCodeInserterID
char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
Definition: PrologEpilogInserter.cpp:139
llvm::DILocalVariable
Local variable.
Definition: DebugInfoMetadata.h:3041
llvm::DIExpression::ApplyOffset
@ ApplyOffset
Definition: DebugInfoMetadata.h:2752
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition: TargetFrameLowering.h:99
llvm::MachineFrameInfo::setCalleeSavedInfoValid
void setCalleeSavedInfoValid(bool v)
Definition: MachineFrameInfo.h:811
llvm::TargetFrameLowering::hasReservedCallFrame
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition: TargetFrameLowering.h:278
llvm::MachineRegisterInfo::isReserved
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
Definition: MachineRegisterInfo.h:900
llvm::TargetFrameLowering::inlineStackProbe
virtual void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Replace a StackProbe stub (if any) with the actual probe code inline.
Definition: TargetFrameLowering.h:224
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::BitVector::size
size_type size() const
size - Returns the number of bits in this bitvector.
Definition: BitVector.h:151
updateLiveness
static void updateLiveness(MachineFunction &MF)
Helper function to update the liveness information for the callee-saved registers.
Definition: PrologEpilogInserter.cpp:461
llvm::InlineAsm::MIOp_ExtraInfo
@ MIOp_ExtraInfo
Definition: InlineAsm.h:217
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:649
false
Definition: StackSlotColoring.cpp:142
TargetOpcodes.h
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false, false) INITIALIZE_PASS_END(PEI
llvm::TargetFrameLowering::hasFP
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register.
llvm::TargetFrameLowering::assignCalleeSavedSpillSlots
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
Definition: TargetFrameLowering.h:161
llvm::MachineOptimizationRemarkAnalysis
Diagnostic information for optimization analysis remarks.
Definition: MachineOptimizationRemarkEmitter.h:108
scavengeStackSlot
static bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, Align MaxAlign, BitVector &StackBytesFree)
Assign frame object to an unused portion of the stack in the fixed stack object range.
Definition: PrologEpilogInserter.cpp:707
llvm::TargetFrameLowering::spillCalleeSavedRegisters
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
Definition: TargetFrameLowering.h:241
llvm::MachineFrameInfo::getRestorePoint
MachineBasicBlock * getRestorePoint() const
Definition: MachineFrameInfo.h:815
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition: MachineFrameInfo.h:720
llvm::MachineFunction::shouldSplitStack
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
Definition: MachineFunction.cpp:280
llvm::MachineFrameInfo::SSPLK_None
@ SSPLK_None
Did not trigger a stack protector.
Definition: MachineFrameInfo.h:112
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:606
BitVector.h
llvm::MachineFrameInfo::getLocalFrameMaxAlign
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
Definition: MachineFrameInfo.h:428
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition: MachineFrameInfo.h:563
SmallPtrSet.h
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition: MachineFrameInfo.h:504
llvm::BitVector
Definition: BitVector.h:74
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MachineFrameInfo::getObjectIndexBegin
int getObjectIndexBegin() const
Return the minimum frame object index.
Definition: MachineFrameInfo.h:388
llvm::SetVector::empty
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:72
WarnStackSize
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"))
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFrameInfo::isDeadObjectIndex
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
Definition: MachineFrameInfo.h:734
llvm::TargetFrameLowering::isFPCloseToIncomingSP
virtual bool isFPCloseToIncomingSP() const
isFPCloseToIncomingSP - Return true if the frame pointer is close to the incoming stack pointer,...
Definition: TargetFrameLowering.h:152
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::BitVector::empty
bool empty() const
empty - Tests whether there are no bits in this bitvector.
Definition: BitVector.h:148
MachineOptimizationRemarkEmitter.h
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
llvm::MachineFunctionProperties::Property::NoVRegs
@ NoVRegs
llvm::MachineFunction::getMMI
MachineModuleInfo & getMMI() const
Definition: MachineFunction.h:509
llvm::DIExpression::isImplicit
bool isImplicit() const
Return whether this is an implicit location description.
Definition: DebugInfoMetadata.cpp:1159
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:558
llvm::MachineFrameInfo::getLocalFrameObjectMap
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
Definition: MachineFrameInfo.h:406
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::MachineFrameInfo::setCalleeSavedInfo
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
Definition: MachineFrameInfo.h:804
AdjustStackOffset
static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign, unsigned Skew)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
Definition: PrologEpilogInserter.cpp:634
llvm::TargetRegisterInfo::getSpillSize
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
Definition: TargetRegisterInfo.h:280
llvm::MachineFrameInfo::CreateFixedSpillStackObject
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
Definition: MachineFrameInfo.cpp:102
llvm::SmallSet::count
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:164
llvm::WinEHFuncInfo
Definition: WinEHFuncInfo.h:90
llvm::MachineFrameInfo::getLocalFrameSize
int64_t getLocalFrameSize() const
Get the size of the local object blob.
Definition: MachineFrameInfo.h:419
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition: MachineFrameInfo.h:451
llvm::TargetFrameLowering::getCalleeSavedSpillSlots
virtual const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
Definition: TargetFrameLowering.h:177
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:238
llvm::DIExpression::StackValue
@ StackValue
Definition: DebugInfoMetadata.h:2755
llvm::MachineFrameInfo::hasStackProtectorIndex
bool hasStackProtectorIndex() const
Definition: MachineFrameInfo.h:356
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::HexagonInstrInfo::storeRegToStackSlot
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Store the specified register of the given register class to the specified stack frame index.
Definition: HexagonInstrInfo.cpp:913
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::TargetFrameLowering::adjustForSegmentedStacks
virtual void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to have the function use segmented stacks.
Definition: TargetFrameLowering.h:229
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MCPhysReg
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition: MCRegister.h:19
llvm::scavengeFrameVirtualRegs
void scavengeFrameVirtualRegs(MachineFunction &MF, RegScavenger &RS)
Replaces all frame index virtual registers with physical registers.
Definition: RegisterScavenging.cpp:738
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition: MachineFrameInfo.h:471
llvm::TargetRegisterInfo::eliminateFrameIndex
virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
llvm::TargetFrameLowering::restoreCalleeSavedRegisters
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
Definition: TargetFrameLowering.h:255
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
MCRegisterInfo.h
llvm::MachineFrameInfo::setObjectOffset
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
Definition: MachineFrameInfo.h:538
llvm::StackOffset::getScalable
static StackOffset getScalable(ScalarTy Scalable)
Definition: TypeSize.h:144
ArrayRef.h
MachineFunctionPass.h
llvm::MachineFrameInfo::setRestorePoint
void setRestorePoint(MachineBasicBlock *NewRestore)
Definition: MachineFrameInfo.h:816
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:115
llvm::TargetFrameLowering::adjustForHiPEPrologue
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...
Definition: TargetFrameLowering.h:234
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:574
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::TargetFrameLowering::getStackGrowthDirection
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
Definition: TargetFrameLowering.h:88
MachineModuleInfo.h
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
llvm::MachineFrameInfo::setSavePoint
void setSavePoint(MachineBasicBlock *NewSave)
Definition: MachineFrameInfo.h:814
llvm::SmallPtrSetImpl< NodeRef >::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::MachineModuleInfo::setHasNosplitStack
void setHasNosplitStack(bool b)
Definition: MachineModuleInfo.h:230
llvm::df_iterator_default_set
Definition: DepthFirstIterator.h:69
llvm::CallingConv::HiPE
@ HiPE
Definition: CallingConv.h:55
llvm::CodeGenOpt::None
@ None
Definition: CodeGen.h:53
llvm::MachineBasicBlock::succ_empty
bool succ_empty() const
Definition: MachineBasicBlock.h:347
TargetOptions.h
llvm::MachineFrameInfo::getCalleeSavedInfo
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Definition: MachineFrameInfo.h:796
llvm::MachineBasicBlock::getFirstTerminator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Definition: MachineBasicBlock.cpp:241
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MachineBasicBlock::getNumber
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Definition: MachineBasicBlock.h:969
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1489
llvm::MachineFrameInfo::CreateStackObject
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Definition: MachineFrameInfo.cpp:51
llvm::MachineBasicBlock::successors
iterator_range< succ_iterator > successors()
Definition: MachineBasicBlock.h:355
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::HexagonInstrInfo::loadRegFromStackSlot
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Load the specified register of the given register class from the specified stack frame index.
Definition: HexagonInstrInfo.cpp:958
llvm::TargetFrameLowering::enableStackSlotScavenging
virtual bool enableStackSlotScavenging(const MachineFunction &MF) const
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allo...
Definition: TargetFrameLowering.h:197
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MachineOptimizationRemarkEmitterPass
The analysis pass.
Definition: MachineOptimizationRemarkEmitter.h:212
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
AssignProtectedObjSet
static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign, unsigned Skew)
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be clo...
Definition: PrologEpilogInserter.cpp:767
llvm::StackOffset
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
Definition: TypeSize.h:134
TargetSubtargetInfo.h
Finalization
Prologue Epilogue Insertion &Frame Finalization
Definition: PrologEpilogInserter.cpp:152
llvm::DiagnosticInfoStackSize
Definition: DiagnosticInfo.h:217
llvm::SmallSet::insert
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
llvm::StackOffset::getFixed
static StackOffset getFixed(ScalarTy Fixed)
Definition: TypeSize.h:143
llvm::df_ext_end
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
Definition: DepthFirstIterator.h:246
llvm::MachineFrameInfo::getLocalFrameObjectCount
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
Definition: MachineFrameInfo.h:413
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::MachineFrameInfo::getMaxAlign
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Definition: MachineFrameInfo.h:585
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MachineBasicBlock::addLiveIn
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Definition: MachineBasicBlock.h:367
llvm::MachineFrameInfo::hasCalls
bool hasCalls() const
Return true if the current function has any function calls.
Definition: MachineFrameInfo.h:602
CallingConv.h
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
Attributes.h
llvm::MachineFrameInfo::getSavePoint
MachineBasicBlock * getSavePoint() const
Definition: MachineFrameInfo.h:813
llvm::BitVector::test
bool test(unsigned Idx) const
Definition: BitVector.h:447
llvm::DIExpression::prependOpcodes
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
Definition: DebugInfoMetadata.cpp:1329
llvm::MachineFrameInfo::getObjectSSPLayout
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
Definition: MachineFrameInfo.h:546
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:524
llvm::TargetSubtargetInfo::getFrameLowering
virtual const TargetFrameLowering * getFrameLowering() const
Definition: TargetSubtargetInfo.h:93
llvm::CalleeSavedInfo
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Definition: MachineFrameInfo.h:34
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:554
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::MachineFrameInfo::isVariableSizedObjectIndex
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
Definition: MachineFrameInfo.h:742
MachineFrameInfo.h
llvm::MachineFunction::getWinEHFuncInfo
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
Definition: MachineFunction.h:602
llvm::TargetFrameLowering::getFrameIndexReference
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
Definition: TargetFrameLoweringImpl.cpp:45
llvm::MachineModuleInfo::setHasSplitStack
void setHasSplitStack(bool b)
Definition: MachineModuleInfo.h:222
DiagnosticInfo.h
llvm::TargetFrameLowering::SpillSlot::Offset
int Offset
Definition: TargetFrameLowering.h:52
llvm::DIExpression::isComplex
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
Definition: DebugInfoMetadata.cpp:1179
Function.h
llvm::initializePEIPass
void initializePEIPass(PassRegistry &)
llvm::TargetStackID::Default
@ Default
Definition: TargetFrameLowering.h:28
assignCalleeSavedSpillSlots
static void assignCalleeSavedSpillSlots(MachineFunction &F, const BitVector &SavedRegs, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex)
Definition: PrologEpilogInserter.cpp:383
llvm::TargetFrameLowering::canSimplifyCallFramePseudos
virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
Definition: TargetFrameLowering.h:289
llvm::TargetFrameLowering::SpillSlot::Reg
unsigned Reg
Definition: TargetFrameLowering.h:51
llvm::TargetFrameLowering::targetHandlesStackFrameRounding
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
Definition: TargetFrameLowering.h:185
llvm::BitVector::find_next
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
Definition: BitVector.h:300
llvm::BitVector::reset
BitVector & reset()
Definition: BitVector.h:384
WinEHFuncInfo.h
CodeGen.h
llvm::TargetRegisterInfo::hasStackRealignment
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
Definition: TargetRegisterInfo.h:940
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition: MachineInstrBuilder.h:508
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
insertCSRRestores
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, std::vector< CalleeSavedInfo > &CSI)
Insert restore code for the callee-saved registers used in the function.
Definition: PrologEpilogInserter.cpp:561
llvm::TargetRegisterInfo::requiresRegisterScavenging
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger.
Definition: TargetRegisterInfo.h:887
insertCSRSaves
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI)
Insert restore code for the callee-saved registers used in the function.
Definition: PrologEpilogInserter.cpp:534
SmallVector.h
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:268
MachineInstrBuilder.h
llvm::MachineFrameInfo::SSPLK_AddrOf
@ SSPLK_AddrOf
The address of this allocation is exposed and triggered protection.
Definition: MachineFrameInfo.h:118
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::BitVector::find_first
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:292
DEBUG_TYPE
#define DEBUG_TYPE
Definition: PrologEpilogInserter.cpp:75
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
llvm::MachineFrameInfo::SSPLK_SmallArray
@ SSPLK_SmallArray
Array or nested array < SSP-buffer-size.
Definition: MachineFrameInfo.h:116
llvm::TargetOptions::StackSymbolOrdering
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
Definition: TargetOptions.h:216
MachineOperand.h
llvm::TargetFrameLowering::StackGrowsDown
@ StackGrowsDown
Definition: TargetFrameLowering.h:46
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::MachineFrameInfo::getStackProtectorIndex
int getStackProtectorIndex() const
Return the index for the stack protector object.
Definition: MachineFrameInfo.h:354
llvm::TargetFrameLowering::emitPrologue
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
llvm::TargetFrameLowering::determineCalleeSaves
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: TargetFrameLoweringImpl.cpp:78
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
LLVMContext.h
llvm::TargetFrameLowering::getFrameIndexReferencePreferSP
virtual StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will ...
Definition: TargetFrameLowering.h:311
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::MachineFrameInfo::adjustsStack
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
Definition: MachineFrameInfo.h:598
llvm::TargetRegisterInfo::getSpillAlignment
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
Definition: TargetRegisterInfo.h:286
llvm::cl::desc
Definition: CommandLine.h:414
llvm::TargetRegisterInfo::getMinimalPhysRegClass
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
Definition: TargetRegisterInfo.cpp:211
RegisterScavenging.h
raw_ostream.h
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:45
MachineFunction.h
llvm::TargetFrameLowering::emitEpilogue
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::TargetFrameLowering::SpillSlot
Definition: TargetFrameLowering.h:50
llvm::TargetRegisterInfo::hasReservedSpillSlot
virtual bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
Definition: TargetRegisterInfo.h:922
InitializePasses.h
TargetRegisterInfo.h
Debug.h
llvm::TargetRegisterInfo::prependOffsetExpression
DIExpression * prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags, const StackOffset &Offset) const
Prepends a DWARF expression for Offset to DIExpression Expr.
Definition: TargetRegisterInfo.cpp:648
SetVector.h
MachineDominators.h
llvm::TargetFrameLowering::getStackAlignmentSkew
virtual unsigned getStackAlignmentSkew(const MachineFunction &MF) const
Return the skew that has to be applied to stack alignment under certain conditions (e....
Definition: TargetFrameLoweringImpl.cpp:129
SmallSet.h
llvm::SmallPtrSetImpl::insert
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:364
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::TargetRegisterInfo::requiresFrameIndexReplacementScavenging
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
Definition: TargetRegisterInfo.h:905
llvm::DIExpression::fragmentsOverlap
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
Definition: DebugInfoMetadata.h:2842