LLVM  14.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 INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false,
142  false)
147  "Prologue/Epilogue Insertion & Frame Finalization", false,
148  false)
149 
151  return new PEI();
152 }
153 
154 STATISTIC(NumBytesStackSpace,
155  "Number of bytes used for stack in all functions");
156 
157 void PEI::getAnalysisUsage(AnalysisUsage &AU) const {
158  AU.setPreservesCFG();
163 }
164 
165 /// StackObjSet - A set of stack object indexes
167 
168 using SavedDbgValuesMap =
170 
171 /// Stash DBG_VALUEs that describe parameters and which are placed at the start
172 /// of the block. Later on, after the prologue code has been emitted, the
173 /// stashed DBG_VALUEs will be reinserted at the start of the block.
175  SavedDbgValuesMap &EntryDbgValues) {
176  SmallVector<const MachineInstr *, 4> FrameIndexValues;
177 
178  for (auto &MI : MBB) {
179  if (!MI.isDebugInstr())
180  break;
181  if (!MI.isDebugValue() || !MI.getDebugVariable()->isParameter())
182  continue;
183  if (any_of(MI.debug_operands(),
184  [](const MachineOperand &MO) { return MO.isFI(); })) {
185  // We can only emit valid locations for frame indices after the frame
186  // setup, so do not stash away them.
187  FrameIndexValues.push_back(&MI);
188  continue;
189  }
190  const DILocalVariable *Var = MI.getDebugVariable();
191  const DIExpression *Expr = MI.getDebugExpression();
192  auto Overlaps = [Var, Expr](const MachineInstr *DV) {
193  return Var == DV->getDebugVariable() &&
194  Expr->fragmentsOverlap(DV->getDebugExpression());
195  };
196  // See if the debug value overlaps with any preceding debug value that will
197  // not be stashed. If that is the case, then we can't stash this value, as
198  // we would then reorder the values at reinsertion.
199  if (llvm::none_of(FrameIndexValues, Overlaps))
200  EntryDbgValues[&MBB].push_back(&MI);
201  }
202 
203  // Remove stashed debug values from the block.
204  if (EntryDbgValues.count(&MBB))
205  for (auto *MI : EntryDbgValues[&MBB])
206  MI->removeFromParent();
207 }
208 
209 /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
210 /// frame indexes with appropriate references.
211 bool PEI::runOnMachineFunction(MachineFunction &MF) {
212  NumFuncSeen++;
213  const Function &F = MF.getFunction();
216 
217  RS = TRI->requiresRegisterScavenging(MF) ? new RegScavenger() : nullptr;
218  FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(MF);
219  ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
220 
221  // Calculate the MaxCallFrameSize and AdjustsStack variables for the
222  // function's frame information. Also eliminates call frame pseudo
223  // instructions.
224  calculateCallFrameInfo(MF);
225 
226  // Determine placement of CSR spill/restore code and prolog/epilog code:
227  // place all spills in the entry block, all restores in return blocks.
228  calculateSaveRestoreBlocks(MF);
229 
230  // Stash away DBG_VALUEs that should not be moved by insertion of prolog code.
231  SavedDbgValuesMap EntryDbgValues;
232  for (MachineBasicBlock *SaveBlock : SaveBlocks)
233  stashEntryDbgValues(*SaveBlock, EntryDbgValues);
234 
235  // Handle CSR spilling and restoring, for targets that need it.
236  if (MF.getTarget().usesPhysRegsForValues())
237  spillCalleeSavedRegs(MF);
238 
239  // Allow the target machine to make final modifications to the function
240  // before the frame layout is finalized.
242 
243  // Calculate actual frame offsets for all abstract stack objects...
244  calculateFrameObjectOffsets(MF);
245 
246  // Add prolog and epilog code to the function. This function is required
247  // to align the stack frame as necessary for any stack variables or
248  // called functions. Because of this, calculateCalleeSavedRegisters()
249  // must be called before this function in order to set the AdjustsStack
250  // and MaxCallFrameSize variables.
251  if (!F.hasFnAttribute(Attribute::Naked))
252  insertPrologEpilogCode(MF);
253 
254  // Reinsert stashed debug values at the start of the entry blocks.
255  for (auto &I : EntryDbgValues)
256  I.first->insert(I.first->begin(), I.second.begin(), I.second.end());
257 
258  // Allow the target machine to make final modifications to the function
259  // before the frame layout is finalized.
261 
262  // Replace all MO_FrameIndex operands with physical register references
263  // and actual offsets.
264  //
265  replaceFrameIndices(MF);
266 
267  // If register scavenging is needed, as we've enabled doing it as a
268  // post-pass, scavenge the virtual registers that frame index elimination
269  // inserted.
270  if (TRI->requiresRegisterScavenging(MF) && FrameIndexVirtualScavenging)
271  scavengeFrameVirtualRegs(MF, *RS);
272 
273  // Warn on stack size when we exceeds the given limit.
274  MachineFrameInfo &MFI = MF.getFrameInfo();
275  uint64_t StackSize = MFI.getStackSize();
276 
277  unsigned Threshold = UINT_MAX;
278  if (MF.getFunction().hasFnAttribute("warn-stack-size")) {
279  bool Failed = MF.getFunction()
280  .getFnAttribute("warn-stack-size")
282  .getAsInteger(10, Threshold);
283  // Verifier should have caught this.
284  assert(!Failed && "Invalid warn-stack-size fn attr value");
285  (void)Failed;
286  }
287  if (StackSize > Threshold) {
288  DiagnosticInfoStackSize DiagStackSize(F, StackSize, DS_Warning, Threshold);
289  F.getContext().diagnose(DiagStackSize);
290  }
291  ORE->emit([&]() {
292  return MachineOptimizationRemarkAnalysis(DEBUG_TYPE, "StackSize",
293  MF.getFunction().getSubprogram(),
294  &MF.front())
295  << ore::NV("NumStackBytes", StackSize) << " stack bytes in function";
296  });
297 
298  delete RS;
299  SaveBlocks.clear();
300  RestoreBlocks.clear();
301  MFI.setSavePoint(nullptr);
302  MFI.setRestorePoint(nullptr);
303  return true;
304 }
305 
306 /// Calculate the MaxCallFrameSize and AdjustsStack
307 /// variables for the function's frame information and eliminate call frame
308 /// pseudo instructions.
309 void PEI::calculateCallFrameInfo(MachineFunction &MF) {
310  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
312  MachineFrameInfo &MFI = MF.getFrameInfo();
313 
314  unsigned MaxCallFrameSize = 0;
315  bool AdjustsStack = MFI.adjustsStack();
316 
317  // Get the function call frame set-up and tear-down instruction opcode
318  unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
319  unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
320 
321  // Early exit for targets which have no call frame setup/destroy pseudo
322  // instructions.
323  if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
324  return;
325 
326  std::vector<MachineBasicBlock::iterator> FrameSDOps;
327  for (MachineBasicBlock &BB : MF)
328  for (MachineBasicBlock::iterator I = BB.begin(); I != BB.end(); ++I)
329  if (TII.isFrameInstr(*I)) {
330  unsigned Size = TII.getFrameSize(*I);
331  if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
332  AdjustsStack = true;
333  FrameSDOps.push_back(I);
334  } else if (I->isInlineAsm()) {
335  // Some inline asm's need a stack frame, as indicated by operand 1.
336  unsigned ExtraInfo = I->getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
337  if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
338  AdjustsStack = true;
339  }
340 
342  (MFI.getMaxCallFrameSize() == MaxCallFrameSize &&
343  MFI.adjustsStack() == AdjustsStack));
344  MFI.setAdjustsStack(AdjustsStack);
345  MFI.setMaxCallFrameSize(MaxCallFrameSize);
346 
347  for (MachineBasicBlock::iterator I : FrameSDOps) {
348  // If call frames are not being included as part of the stack frame, and
349  // the target doesn't indicate otherwise, remove the call frame pseudos
350  // here. The sub/add sp instruction pairs are still inserted, but we don't
351  // need to track the SP adjustment for frame index elimination.
352  if (TFI->canSimplifyCallFramePseudos(MF))
353  TFI->eliminateCallFramePseudoInstr(MF, *I->getParent(), I);
354  }
355 }
356 
357 /// Compute the sets of entry and return blocks for saving and restoring
358 /// callee-saved registers, and placing prolog and epilog code.
359 void PEI::calculateSaveRestoreBlocks(MachineFunction &MF) {
360  const MachineFrameInfo &MFI = MF.getFrameInfo();
361 
362  // Even when we do not change any CSR, we still want to insert the
363  // prologue and epilogue of the function.
364  // So set the save points for those.
365 
366  // Use the points found by shrink-wrapping, if any.
367  if (MFI.getSavePoint()) {
368  SaveBlocks.push_back(MFI.getSavePoint());
369  assert(MFI.getRestorePoint() && "Both restore and save must be set");
370  MachineBasicBlock *RestoreBlock = MFI.getRestorePoint();
371  // If RestoreBlock does not have any successor and is not a return block
372  // then the end point is unreachable and we do not need to insert any
373  // epilogue.
374  if (!RestoreBlock->succ_empty() || RestoreBlock->isReturnBlock())
375  RestoreBlocks.push_back(RestoreBlock);
376  return;
377  }
378 
379  // Save refs to entry and return blocks.
380  SaveBlocks.push_back(&MF.front());
381  for (MachineBasicBlock &MBB : MF) {
382  if (MBB.isEHFuncletEntry())
383  SaveBlocks.push_back(&MBB);
384  if (MBB.isReturnBlock())
385  RestoreBlocks.push_back(&MBB);
386  }
387 }
388 
390  const BitVector &SavedRegs,
391  unsigned &MinCSFrameIndex,
392  unsigned &MaxCSFrameIndex) {
393  if (SavedRegs.empty())
394  return;
395 
396  const TargetRegisterInfo *RegInfo = F.getSubtarget().getRegisterInfo();
397  const MCPhysReg *CSRegs = F.getRegInfo().getCalleeSavedRegs();
398  BitVector CSMask(SavedRegs.size());
399 
400  for (unsigned i = 0; CSRegs[i]; ++i)
401  CSMask.set(CSRegs[i]);
402 
403  std::vector<CalleeSavedInfo> CSI;
404  for (unsigned i = 0; CSRegs[i]; ++i) {
405  unsigned Reg = CSRegs[i];
406  if (SavedRegs.test(Reg)) {
407  bool SavedSuper = false;
408  for (const MCPhysReg &SuperReg : RegInfo->superregs(Reg)) {
409  // Some backends set all aliases for some registers as saved, such as
410  // Mips's $fp, so they appear in SavedRegs but not CSRegs.
411  if (SavedRegs.test(SuperReg) && CSMask.test(SuperReg)) {
412  SavedSuper = true;
413  break;
414  }
415  }
416 
417  if (!SavedSuper)
418  CSI.push_back(CalleeSavedInfo(Reg));
419  }
420  }
421 
422  const TargetFrameLowering *TFI = F.getSubtarget().getFrameLowering();
423  MachineFrameInfo &MFI = F.getFrameInfo();
424  if (!TFI->assignCalleeSavedSpillSlots(F, RegInfo, CSI, MinCSFrameIndex,
425  MaxCSFrameIndex)) {
426  // If target doesn't implement this, use generic code.
427 
428  if (CSI.empty())
429  return; // Early exit if no callee saved registers are modified!
430 
431  unsigned NumFixedSpillSlots;
432  const TargetFrameLowering::SpillSlot *FixedSpillSlots =
433  TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
434 
435  // Now that we know which registers need to be saved and restored, allocate
436  // stack slots for them.
437  for (auto &CS : CSI) {
438  // If the target has spilled this register to another register, we don't
439  // need to allocate a stack slot.
440  if (CS.isSpilledToReg())
441  continue;
442 
443  unsigned Reg = CS.getReg();
444  const TargetRegisterClass *RC = RegInfo->getMinimalPhysRegClass(Reg);
445 
446  int FrameIdx;
447  if (RegInfo->hasReservedSpillSlot(F, Reg, FrameIdx)) {
448  CS.setFrameIdx(FrameIdx);
449  continue;
450  }
451 
452  // Check to see if this physreg must be spilled to a particular stack slot
453  // on this target.
454  const TargetFrameLowering::SpillSlot *FixedSlot = FixedSpillSlots;
455  while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
456  FixedSlot->Reg != Reg)
457  ++FixedSlot;
458 
459  unsigned Size = RegInfo->getSpillSize(*RC);
460  if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
461  // Nope, just spill it anywhere convenient.
462  Align Alignment = RegInfo->getSpillAlign(*RC);
463  // We may not be able to satisfy the desired alignment specification of
464  // the TargetRegisterClass if the stack alignment is smaller. Use the
465  // min.
466  Alignment = std::min(Alignment, TFI->getStackAlign());
467  FrameIdx = MFI.CreateStackObject(Size, Alignment, true);
468  if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
469  if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
470  } else {
471  // Spill it to the stack where we must.
472  FrameIdx = MFI.CreateFixedSpillStackObject(Size, FixedSlot->Offset);
473  }
474 
475  CS.setFrameIdx(FrameIdx);
476  }
477  }
478 
479  MFI.setCalleeSavedInfo(CSI);
480 }
481 
482 /// Helper function to update the liveness information for the callee-saved
483 /// registers.
484 static void updateLiveness(MachineFunction &MF) {
485  MachineFrameInfo &MFI = MF.getFrameInfo();
486  // Visited will contain all the basic blocks that are in the region
487  // where the callee saved registers are alive:
488  // - Anything that is not Save or Restore -> LiveThrough.
489  // - Save -> LiveIn.
490  // - Restore -> LiveOut.
491  // The live-out is not attached to the block, so no need to keep
492  // Restore in this set.
495  MachineBasicBlock *Entry = &MF.front();
496  MachineBasicBlock *Save = MFI.getSavePoint();
497 
498  if (!Save)
499  Save = Entry;
500 
501  if (Entry != Save) {
502  WorkList.push_back(Entry);
503  Visited.insert(Entry);
504  }
505  Visited.insert(Save);
506 
507  MachineBasicBlock *Restore = MFI.getRestorePoint();
508  if (Restore)
509  // By construction Restore cannot be visited, otherwise it
510  // means there exists a path to Restore that does not go
511  // through Save.
512  WorkList.push_back(Restore);
513 
514  while (!WorkList.empty()) {
515  const MachineBasicBlock *CurBB = WorkList.pop_back_val();
516  // By construction, the region that is after the save point is
517  // dominated by the Save and post-dominated by the Restore.
518  if (CurBB == Save && Save != Restore)
519  continue;
520  // Enqueue all the successors not already visited.
521  // Those are by construction either before Save or after Restore.
522  for (MachineBasicBlock *SuccBB : CurBB->successors())
523  if (Visited.insert(SuccBB).second)
524  WorkList.push_back(SuccBB);
525  }
526 
527  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
528 
530  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
531  for (MachineBasicBlock *MBB : Visited) {
532  MCPhysReg Reg = CSI[i].getReg();
533  // Add the callee-saved register as live-in.
534  // It's killed at the spill.
535  if (!MRI.isReserved(Reg) && !MBB->isLiveIn(Reg))
536  MBB->addLiveIn(Reg);
537  }
538  // If callee-saved register is spilled to another register rather than
539  // spilling to stack, the destination register has to be marked as live for
540  // each MBB between the prologue and epilogue so that it is not clobbered
541  // before it is reloaded in the epilogue. The Visited set contains all
542  // blocks outside of the region delimited by prologue/epilogue.
543  if (CSI[i].isSpilledToReg()) {
544  for (MachineBasicBlock &MBB : MF) {
545  if (Visited.count(&MBB))
546  continue;
547  MCPhysReg DstReg = CSI[i].getDstReg();
548  if (!MBB.isLiveIn(DstReg))
549  MBB.addLiveIn(DstReg);
550  }
551  }
552  }
553 
554 }
555 
556 /// Insert restore code for the callee-saved registers used in the function.
557 static void insertCSRSaves(MachineBasicBlock &SaveBlock,
559  MachineFunction &MF = *SaveBlock.getParent();
560  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
563 
564  MachineBasicBlock::iterator I = SaveBlock.begin();
565  if (!TFI->spillCalleeSavedRegisters(SaveBlock, I, CSI, TRI)) {
566  for (const CalleeSavedInfo &CS : CSI) {
567  // Insert the spill to the stack frame.
568  unsigned Reg = CS.getReg();
569 
570  if (CS.isSpilledToReg()) {
571  BuildMI(SaveBlock, I, DebugLoc(),
572  TII.get(TargetOpcode::COPY), CS.getDstReg())
573  .addReg(Reg, getKillRegState(true));
574  } else {
576  TII.storeRegToStackSlot(SaveBlock, I, Reg, true, CS.getFrameIdx(), RC,
577  TRI);
578  }
579  }
580  }
581 }
582 
583 /// Insert restore code for the callee-saved registers used in the function.
584 static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
585  std::vector<CalleeSavedInfo> &CSI) {
586  MachineFunction &MF = *RestoreBlock.getParent();
587  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
590 
591  // Restore all registers immediately before the return and any
592  // terminators that precede it.
594 
595  if (!TFI->restoreCalleeSavedRegisters(RestoreBlock, I, CSI, TRI)) {
596  for (const CalleeSavedInfo &CI : reverse(CSI)) {
597  unsigned Reg = CI.getReg();
598  if (CI.isSpilledToReg()) {
599  BuildMI(RestoreBlock, I, DebugLoc(), TII.get(TargetOpcode::COPY), Reg)
600  .addReg(CI.getDstReg(), getKillRegState(true));
601  } else {
603  TII.loadRegFromStackSlot(RestoreBlock, I, Reg, CI.getFrameIdx(), RC, TRI);
604  assert(I != RestoreBlock.begin() &&
605  "loadRegFromStackSlot didn't insert any code!");
606  // Insert in reverse order. loadRegFromStackSlot can insert
607  // multiple instructions.
608  }
609  }
610  }
611 }
612 
613 void PEI::spillCalleeSavedRegs(MachineFunction &MF) {
614  // We can't list this requirement in getRequiredProperties because some
615  // targets (WebAssembly) use virtual registers past this point, and the pass
616  // pipeline is set up without giving the passes a chance to look at the
617  // TargetMachine.
618  // FIXME: Find a way to express this in getRequiredProperties.
621 
622  const Function &F = MF.getFunction();
624  MachineFrameInfo &MFI = MF.getFrameInfo();
625  MinCSFrameIndex = std::numeric_limits<unsigned>::max();
626  MaxCSFrameIndex = 0;
627 
628  // Determine which of the registers in the callee save list should be saved.
629  BitVector SavedRegs;
630  TFI->determineCalleeSaves(MF, SavedRegs, RS);
631 
632  // Assign stack slots for any callee-saved registers that must be spilled.
633  assignCalleeSavedSpillSlots(MF, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex);
634 
635  // Add the code to save and restore the callee saved registers.
636  if (!F.hasFnAttribute(Attribute::Naked)) {
637  MFI.setCalleeSavedInfoValid(true);
638 
639  std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
640  if (!CSI.empty()) {
641  if (!MFI.hasCalls())
642  NumLeafFuncWithSpills++;
643 
644  for (MachineBasicBlock *SaveBlock : SaveBlocks)
645  insertCSRSaves(*SaveBlock, CSI);
646 
647  // Update the live-in information of all the blocks up to the save point.
648  updateLiveness(MF);
649 
650  for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
651  insertCSRRestores(*RestoreBlock, CSI);
652  }
653  }
654 }
655 
656 /// AdjustStackOffset - Helper function used to adjust the stack frame offset.
657 static inline void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx,
658  bool StackGrowsDown, int64_t &Offset,
659  Align &MaxAlign, unsigned Skew) {
660  // If the stack grows down, add the object size to find the lowest address.
661  if (StackGrowsDown)
662  Offset += MFI.getObjectSize(FrameIdx);
663 
664  Align Alignment = MFI.getObjectAlign(FrameIdx);
665 
666  // If the alignment of this object is greater than that of the stack, then
667  // increase the stack alignment to match.
668  MaxAlign = std::max(MaxAlign, Alignment);
669 
670  // Adjust to alignment boundary.
671  Offset = alignTo(Offset, Alignment, Skew);
672 
673  if (StackGrowsDown) {
674  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset
675  << "]\n");
676  MFI.setObjectOffset(FrameIdx, -Offset); // Set the computed offset
677  } else {
678  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset
679  << "]\n");
680  MFI.setObjectOffset(FrameIdx, Offset);
681  Offset += MFI.getObjectSize(FrameIdx);
682  }
683 }
684 
685 /// Compute which bytes of fixed and callee-save stack area are unused and keep
686 /// track of them in StackBytesFree.
687 static inline void
688 computeFreeStackSlots(MachineFrameInfo &MFI, bool StackGrowsDown,
689  unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex,
690  int64_t FixedCSEnd, BitVector &StackBytesFree) {
691  // Avoid undefined int64_t -> int conversion below in extreme case.
692  if (FixedCSEnd > std::numeric_limits<int>::max())
693  return;
694 
695  StackBytesFree.resize(FixedCSEnd, true);
696 
697  SmallVector<int, 16> AllocatedFrameSlots;
698  // Add fixed objects.
699  for (int i = MFI.getObjectIndexBegin(); i != 0; ++i)
700  // StackSlot scavenging is only implemented for the default stack.
701  if (MFI.getStackID(i) == TargetStackID::Default)
702  AllocatedFrameSlots.push_back(i);
703  // Add callee-save objects if there are any.
704  if (MinCSFrameIndex <= MaxCSFrameIndex) {
705  for (int i = MinCSFrameIndex; i <= (int)MaxCSFrameIndex; ++i)
706  if (MFI.getStackID(i) == TargetStackID::Default)
707  AllocatedFrameSlots.push_back(i);
708  }
709 
710  for (int i : AllocatedFrameSlots) {
711  // These are converted from int64_t, but they should always fit in int
712  // because of the FixedCSEnd check above.
713  int ObjOffset = MFI.getObjectOffset(i);
714  int ObjSize = MFI.getObjectSize(i);
715  int ObjStart, ObjEnd;
716  if (StackGrowsDown) {
717  // ObjOffset is negative when StackGrowsDown is true.
718  ObjStart = -ObjOffset - ObjSize;
719  ObjEnd = -ObjOffset;
720  } else {
721  ObjStart = ObjOffset;
722  ObjEnd = ObjOffset + ObjSize;
723  }
724  // Ignore fixed holes that are in the previous stack frame.
725  if (ObjEnd > 0)
726  StackBytesFree.reset(ObjStart, ObjEnd);
727  }
728 }
729 
730 /// Assign frame object to an unused portion of the stack in the fixed stack
731 /// object range. Return true if the allocation was successful.
732 static inline bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx,
733  bool StackGrowsDown, Align MaxAlign,
734  BitVector &StackBytesFree) {
735  if (MFI.isVariableSizedObjectIndex(FrameIdx))
736  return false;
737 
738  if (StackBytesFree.none()) {
739  // clear it to speed up later scavengeStackSlot calls to
740  // StackBytesFree.none()
741  StackBytesFree.clear();
742  return false;
743  }
744 
745  Align ObjAlign = MFI.getObjectAlign(FrameIdx);
746  if (ObjAlign > MaxAlign)
747  return false;
748 
749  int64_t ObjSize = MFI.getObjectSize(FrameIdx);
750  int FreeStart;
751  for (FreeStart = StackBytesFree.find_first(); FreeStart != -1;
752  FreeStart = StackBytesFree.find_next(FreeStart)) {
753 
754  // Check that free space has suitable alignment.
755  unsigned ObjStart = StackGrowsDown ? FreeStart + ObjSize : FreeStart;
756  if (alignTo(ObjStart, ObjAlign) != ObjStart)
757  continue;
758 
759  if (FreeStart + ObjSize > StackBytesFree.size())
760  return false;
761 
762  bool AllBytesFree = true;
763  for (unsigned Byte = 0; Byte < ObjSize; ++Byte)
764  if (!StackBytesFree.test(FreeStart + Byte)) {
765  AllBytesFree = false;
766  break;
767  }
768  if (AllBytesFree)
769  break;
770  }
771 
772  if (FreeStart == -1)
773  return false;
774 
775  if (StackGrowsDown) {
776  int ObjStart = -(FreeStart + ObjSize);
777  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP["
778  << ObjStart << "]\n");
779  MFI.setObjectOffset(FrameIdx, ObjStart);
780  } else {
781  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP["
782  << FreeStart << "]\n");
783  MFI.setObjectOffset(FrameIdx, FreeStart);
784  }
785 
786  StackBytesFree.reset(FreeStart, FreeStart + ObjSize);
787  return true;
788 }
789 
790 /// AssignProtectedObjSet - Helper function to assign large stack objects (i.e.,
791 /// those required to be close to the Stack Protector) to stack offsets.
792 static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
793  SmallSet<int, 16> &ProtectedObjs,
794  MachineFrameInfo &MFI, bool StackGrowsDown,
795  int64_t &Offset, Align &MaxAlign,
796  unsigned Skew) {
797 
798  for (int i : UnassignedObjs) {
799  AdjustStackOffset(MFI, i, StackGrowsDown, Offset, MaxAlign, Skew);
800  ProtectedObjs.insert(i);
801  }
802 }
803 
804 /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
805 /// abstract stack objects.
806 void PEI::calculateFrameObjectOffsets(MachineFunction &MF) {
808 
809  bool StackGrowsDown =
811 
812  // Loop over all of the stack objects, assigning sequential addresses...
813  MachineFrameInfo &MFI = MF.getFrameInfo();
814 
815  // Start at the beginning of the local area.
816  // The Offset is the distance from the stack top in the direction
817  // of stack growth -- so it's always nonnegative.
818  int LocalAreaOffset = TFI.getOffsetOfLocalArea();
819  if (StackGrowsDown)
820  LocalAreaOffset = -LocalAreaOffset;
821  assert(LocalAreaOffset >= 0
822  && "Local area offset should be in direction of stack growth");
823  int64_t Offset = LocalAreaOffset;
824 
825  // Skew to be applied to alignment.
826  unsigned Skew = TFI.getStackAlignmentSkew(MF);
827 
828 #ifdef EXPENSIVE_CHECKS
829  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i)
830  if (!MFI.isDeadObjectIndex(i) &&
832  assert(MFI.getObjectAlign(i) <= MFI.getMaxAlign() &&
833  "MaxAlignment is invalid");
834 #endif
835 
836  // If there are fixed sized objects that are preallocated in the local area,
837  // non-fixed objects can't be allocated right at the start of local area.
838  // Adjust 'Offset' to point to the end of last fixed sized preallocated
839  // object.
840  for (int i = MFI.getObjectIndexBegin(); i != 0; ++i) {
841  if (MFI.getStackID(i) !=
842  TargetStackID::Default) // Only allocate objects on the default stack.
843  continue;
844 
845  int64_t FixedOff;
846  if (StackGrowsDown) {
847  // The maximum distance from the stack pointer is at lower address of
848  // the object -- which is given by offset. For down growing stack
849  // the offset is negative, so we negate the offset to get the distance.
850  FixedOff = -MFI.getObjectOffset(i);
851  } else {
852  // The maximum distance from the start pointer is at the upper
853  // address of the object.
854  FixedOff = MFI.getObjectOffset(i) + MFI.getObjectSize(i);
855  }
856  if (FixedOff > Offset) Offset = FixedOff;
857  }
858 
859  // First assign frame offsets to stack objects that are used to spill
860  // callee saved registers.
861  if (StackGrowsDown && MaxCSFrameIndex >= MinCSFrameIndex) {
862  for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
863  if (MFI.getStackID(i) !=
864  TargetStackID::Default) // Only allocate objects on the default stack.
865  continue;
866 
867  // If the stack grows down, we need to add the size to find the lowest
868  // address of the object.
869  Offset += MFI.getObjectSize(i);
870 
871  // Adjust to alignment boundary
872  Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
873 
874  LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n");
875  MFI.setObjectOffset(i, -Offset); // Set the computed offset
876  }
877  } else if (MaxCSFrameIndex >= MinCSFrameIndex) {
878  // Be careful about underflow in comparisons agains MinCSFrameIndex.
879  for (unsigned i = MaxCSFrameIndex; i != MinCSFrameIndex - 1; --i) {
880  if (MFI.getStackID(i) !=
881  TargetStackID::Default) // Only allocate objects on the default stack.
882  continue;
883 
884  if (MFI.isDeadObjectIndex(i))
885  continue;
886 
887  // Adjust to alignment boundary
888  Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
889 
890  LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n");
891  MFI.setObjectOffset(i, Offset);
892  Offset += MFI.getObjectSize(i);
893  }
894  }
895 
896  // FixedCSEnd is the stack offset to the end of the fixed and callee-save
897  // stack area.
898  int64_t FixedCSEnd = Offset;
899  Align MaxAlign = MFI.getMaxAlign();
900 
901  // Make sure the special register scavenging spill slot is closest to the
902  // incoming stack pointer if a frame pointer is required and is closer
903  // to the incoming rather than the final stack pointer.
904  const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
905  bool EarlyScavengingSlots = (TFI.hasFP(MF) && TFI.isFPCloseToIncomingSP() &&
906  RegInfo->useFPForScavengingIndex(MF) &&
907  !RegInfo->hasStackRealignment(MF));
908  if (RS && EarlyScavengingSlots) {
909  SmallVector<int, 2> SFIs;
910  RS->getScavengingFrameIndices(SFIs);
911  for (int SFI : SFIs)
912  AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign, Skew);
913  }
914 
915  // FIXME: Once this is working, then enable flag will change to a target
916  // check for whether the frame is large enough to want to use virtual
917  // frame index registers. Functions which don't want/need this optimization
918  // will continue to use the existing code path.
920  Align Alignment = MFI.getLocalFrameMaxAlign();
921 
922  // Adjust to alignment boundary.
923  Offset = alignTo(Offset, Alignment, Skew);
924 
925  LLVM_DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n");
926 
927  // Resolve offsets for objects in the local block.
928  for (unsigned i = 0, e = MFI.getLocalFrameObjectCount(); i != e; ++i) {
929  std::pair<int, int64_t> Entry = MFI.getLocalFrameObjectMap(i);
930  int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second;
931  LLVM_DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" << FIOffset
932  << "]\n");
933  MFI.setObjectOffset(Entry.first, FIOffset);
934  }
935  // Allocate the local block
936  Offset += MFI.getLocalFrameSize();
937 
938  MaxAlign = std::max(Alignment, MaxAlign);
939  }
940 
941  // Retrieve the Exception Handler registration node.
942  int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
943  if (const WinEHFuncInfo *FuncInfo = MF.getWinEHFuncInfo())
944  EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
945 
946  // Make sure that the stack protector comes before the local variables on the
947  // stack.
948  SmallSet<int, 16> ProtectedObjs;
949  if (MFI.hasStackProtectorIndex()) {
950  int StackProtectorFI = MFI.getStackProtectorIndex();
951  StackObjSet LargeArrayObjs;
952  StackObjSet SmallArrayObjs;
953  StackObjSet AddrOfObjs;
954 
955  // If we need a stack protector, we need to make sure that
956  // LocalStackSlotPass didn't already allocate a slot for it.
957  // If we are told to use the LocalStackAllocationBlock, the stack protector
958  // is expected to be already pre-allocated.
960  AdjustStackOffset(MFI, StackProtectorFI, StackGrowsDown, Offset, MaxAlign,
961  Skew);
962  else if (!MFI.isObjectPreAllocated(MFI.getStackProtectorIndex()))
964  "Stack protector not pre-allocated by LocalStackSlotPass.");
965 
966  // Assign large stack objects first.
967  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
969  continue;
970  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
971  continue;
972  if (RS && RS->isScavengingFrameIndex((int)i))
973  continue;
974  if (MFI.isDeadObjectIndex(i))
975  continue;
976  if (StackProtectorFI == (int)i || EHRegNodeFrameIndex == (int)i)
977  continue;
978  if (MFI.getStackID(i) !=
979  TargetStackID::Default) // Only allocate objects on the default stack.
980  continue;
981 
982  switch (MFI.getObjectSSPLayout(i)) {
984  continue;
986  SmallArrayObjs.insert(i);
987  continue;
989  AddrOfObjs.insert(i);
990  continue;
992  LargeArrayObjs.insert(i);
993  continue;
994  }
995  llvm_unreachable("Unexpected SSPLayoutKind.");
996  }
997 
998  // We expect **all** the protected stack objects to be pre-allocated by
999  // LocalStackSlotPass. If it turns out that PEI still has to allocate some
1000  // of them, we may end up messing up the expected order of the objects.
1001  if (MFI.getUseLocalStackAllocationBlock() &&
1002  !(LargeArrayObjs.empty() && SmallArrayObjs.empty() &&
1003  AddrOfObjs.empty()))
1004  llvm_unreachable("Found protected stack objects not pre-allocated by "
1005  "LocalStackSlotPass.");
1006 
1007  AssignProtectedObjSet(LargeArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
1008  Offset, MaxAlign, Skew);
1009  AssignProtectedObjSet(SmallArrayObjs, ProtectedObjs, MFI, StackGrowsDown,
1010  Offset, MaxAlign, Skew);
1011  AssignProtectedObjSet(AddrOfObjs, ProtectedObjs, MFI, StackGrowsDown,
1012  Offset, MaxAlign, Skew);
1013  }
1014 
1015  SmallVector<int, 8> ObjectsToAllocate;
1016 
1017  // Then prepare to assign frame offsets to stack objects that are not used to
1018  // spill callee saved registers.
1019  for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
1021  continue;
1022  if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
1023  continue;
1024  if (RS && RS->isScavengingFrameIndex((int)i))
1025  continue;
1026  if (MFI.isDeadObjectIndex(i))
1027  continue;
1028  if (MFI.getStackProtectorIndex() == (int)i || EHRegNodeFrameIndex == (int)i)
1029  continue;
1030  if (ProtectedObjs.count(i))
1031  continue;
1032  if (MFI.getStackID(i) !=
1033  TargetStackID::Default) // Only allocate objects on the default stack.
1034  continue;
1035 
1036  // Add the objects that we need to allocate to our working set.
1037  ObjectsToAllocate.push_back(i);
1038  }
1039 
1040  // Allocate the EH registration node first if one is present.
1041  if (EHRegNodeFrameIndex != std::numeric_limits<int>::max())
1042  AdjustStackOffset(MFI, EHRegNodeFrameIndex, StackGrowsDown, Offset,
1043  MaxAlign, Skew);
1044 
1045  // Give the targets a chance to order the objects the way they like it.
1046  if (MF.getTarget().getOptLevel() != CodeGenOpt::None &&
1048  TFI.orderFrameObjects(MF, ObjectsToAllocate);
1049 
1050  // Keep track of which bytes in the fixed and callee-save range are used so we
1051  // can use the holes when allocating later stack objects. Only do this if
1052  // stack protector isn't being used and the target requests it and we're
1053  // optimizing.
1054  BitVector StackBytesFree;
1055  if (!ObjectsToAllocate.empty() &&
1058  computeFreeStackSlots(MFI, StackGrowsDown, MinCSFrameIndex, MaxCSFrameIndex,
1059  FixedCSEnd, StackBytesFree);
1060 
1061  // Now walk the objects and actually assign base offsets to them.
1062  for (auto &Object : ObjectsToAllocate)
1063  if (!scavengeStackSlot(MFI, Object, StackGrowsDown, MaxAlign,
1064  StackBytesFree))
1065  AdjustStackOffset(MFI, Object, StackGrowsDown, Offset, MaxAlign, Skew);
1066 
1067  // Make sure the special register scavenging spill slot is closest to the
1068  // stack pointer.
1069  if (RS && !EarlyScavengingSlots) {
1070  SmallVector<int, 2> SFIs;
1071  RS->getScavengingFrameIndices(SFIs);
1072  for (int SFI : SFIs)
1073  AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign, Skew);
1074  }
1075 
1076  if (!TFI.targetHandlesStackFrameRounding()) {
1077  // If we have reserved argument space for call sites in the function
1078  // immediately on entry to the current function, count it as part of the
1079  // overall stack size.
1080  if (MFI.adjustsStack() && TFI.hasReservedCallFrame(MF))
1081  Offset += MFI.getMaxCallFrameSize();
1082 
1083  // Round up the size to a multiple of the alignment. If the function has
1084  // any calls or alloca's, align to the target's StackAlignment value to
1085  // ensure that the callee's frame or the alloca data is suitably aligned;
1086  // otherwise, for leaf functions, align to the TransientStackAlignment
1087  // value.
1088  Align StackAlign;
1089  if (MFI.adjustsStack() || MFI.hasVarSizedObjects() ||
1090  (RegInfo->hasStackRealignment(MF) && MFI.getObjectIndexEnd() != 0))
1091  StackAlign = TFI.getStackAlign();
1092  else
1094 
1095  // If the frame pointer is eliminated, all frame offsets will be relative to
1096  // SP not FP. Align to MaxAlign so this works.
1097  StackAlign = std::max(StackAlign, MaxAlign);
1098  int64_t OffsetBeforeAlignment = Offset;
1099  Offset = alignTo(Offset, StackAlign, Skew);
1100 
1101  // If we have increased the offset to fulfill the alignment constrants,
1102  // then the scavenging spill slots may become harder to reach from the
1103  // stack pointer, float them so they stay close.
1104  if (StackGrowsDown && OffsetBeforeAlignment != Offset && RS &&
1105  !EarlyScavengingSlots) {
1106  SmallVector<int, 2> SFIs;
1107  RS->getScavengingFrameIndices(SFIs);
1108  LLVM_DEBUG(if (!SFIs.empty()) llvm::dbgs()
1109  << "Adjusting emergency spill slots!\n";);
1110  int64_t Delta = Offset - OffsetBeforeAlignment;
1111  for (int SFI : SFIs) {
1113  << "Adjusting offset of emergency spill slot #" << SFI
1114  << " from " << MFI.getObjectOffset(SFI););
1115  MFI.setObjectOffset(SFI, MFI.getObjectOffset(SFI) - Delta);
1116  LLVM_DEBUG(llvm::dbgs() << " to " << MFI.getObjectOffset(SFI) << "\n";);
1117  }
1118  }
1119  }
1120 
1121  // Update frame info to pretend that this is part of the stack...
1122  int64_t StackSize = Offset - LocalAreaOffset;
1123  MFI.setStackSize(StackSize);
1124  NumBytesStackSpace += StackSize;
1125 }
1126 
1127 /// insertPrologEpilogCode - Scan the function for modified callee saved
1128 /// registers, insert spill code for these callee saved registers, then add
1129 /// prolog and epilog code to the function.
1130 void PEI::insertPrologEpilogCode(MachineFunction &MF) {
1131  const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering();
1132 
1133  // Add prologue to the function...
1134  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1135  TFI.emitPrologue(MF, *SaveBlock);
1136 
1137  // Add epilogue to restore the callee-save registers in each exiting block.
1138  for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
1139  TFI.emitEpilogue(MF, *RestoreBlock);
1140 
1141  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1142  TFI.inlineStackProbe(MF, *SaveBlock);
1143 
1144  // Emit additional code that is required to support segmented stacks, if
1145  // we've been asked for it. This, when linked with a runtime with support
1146  // for segmented stacks (libgcc is one), will result in allocating stack
1147  // space in small chunks instead of one large contiguous block.
1148  if (MF.shouldSplitStack()) {
1149  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1150  TFI.adjustForSegmentedStacks(MF, *SaveBlock);
1151  // Record that there are split-stack functions, so we will emit a
1152  // special section to tell the linker.
1153  MF.getMMI().setHasSplitStack(true);
1154  } else
1155  MF.getMMI().setHasNosplitStack(true);
1156 
1157  // Emit additional code that is required to explicitly handle the stack in
1158  // HiPE native code (if needed) when loaded in the Erlang/OTP runtime. The
1159  // approach is rather similar to that of Segmented Stacks, but it uses a
1160  // different conditional check and another BIF for allocating more stack
1161  // space.
1163  for (MachineBasicBlock *SaveBlock : SaveBlocks)
1164  TFI.adjustForHiPEPrologue(MF, *SaveBlock);
1165 }
1166 
1167 /// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
1168 /// register references and actual offsets.
1169 void PEI::replaceFrameIndices(MachineFunction &MF) {
1170  const auto &ST = MF.getSubtarget();
1171  const TargetFrameLowering &TFI = *ST.getFrameLowering();
1172  if (!TFI.needsFrameIndexResolution(MF))
1173  return;
1174 
1175  const TargetRegisterInfo *TRI = ST.getRegisterInfo();
1176 
1177  // Allow the target to determine this after knowing the frame size.
1178  FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) ||
1180 
1181  // Store SPAdj at exit of a basic block.
1182  SmallVector<int, 8> SPState;
1183  SPState.resize(MF.getNumBlockIDs());
1185 
1186  // Iterate over the reachable blocks in DFS order.
1187  for (auto DFI = df_ext_begin(&MF, Reachable), DFE = df_ext_end(&MF, Reachable);
1188  DFI != DFE; ++DFI) {
1189  int SPAdj = 0;
1190  // Check the exit state of the DFS stack predecessor.
1191  if (DFI.getPathLength() >= 2) {
1192  MachineBasicBlock *StackPred = DFI.getPath(DFI.getPathLength() - 2);
1193  assert(Reachable.count(StackPred) &&
1194  "DFS stack predecessor is already visited.\n");
1195  SPAdj = SPState[StackPred->getNumber()];
1196  }
1197  MachineBasicBlock *BB = *DFI;
1198  replaceFrameIndices(BB, MF, SPAdj);
1199  SPState[BB->getNumber()] = SPAdj;
1200  }
1201 
1202  // Handle the unreachable blocks.
1203  for (auto &BB : MF) {
1204  if (Reachable.count(&BB))
1205  // Already handled in DFS traversal.
1206  continue;
1207  int SPAdj = 0;
1208  replaceFrameIndices(&BB, MF, SPAdj);
1209  }
1210 }
1211 
1212 void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF,
1213  int &SPAdj) {
1215  "getRegisterInfo() must be implemented!");
1216  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
1219 
1220  if (RS && FrameIndexEliminationScavenging)
1221  RS->enterBasicBlock(*BB);
1222 
1223  bool InsideCallSequence = false;
1224 
1225  for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
1226  if (TII.isFrameInstr(*I)) {
1227  InsideCallSequence = TII.isFrameSetup(*I);
1228  SPAdj += TII.getSPAdjust(*I);
1229  I = TFI->eliminateCallFramePseudoInstr(MF, *BB, I);
1230  continue;
1231  }
1232 
1233  MachineInstr &MI = *I;
1234  bool DoIncr = true;
1235  bool DidFinishLoop = true;
1236  for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
1237  if (!MI.getOperand(i).isFI())
1238  continue;
1239 
1240  // Frame indices in debug values are encoded in a target independent
1241  // way with simply the frame index and offset rather than any
1242  // target-specific addressing mode.
1243  if (MI.isDebugValue()) {
1244  MachineOperand &Op = MI.getOperand(i);
1245  assert(
1246  MI.isDebugOperand(&Op) &&
1247  "Frame indices can only appear as a debug operand in a DBG_VALUE*"
1248  " machine instruction");
1249  Register Reg;
1250  unsigned FrameIdx = Op.getIndex();
1251  unsigned Size = MF.getFrameInfo().getObjectSize(FrameIdx);
1252 
1254  TFI->getFrameIndexReference(MF, FrameIdx, Reg);
1255  Op.ChangeToRegister(Reg, false /*isDef*/);
1256  Op.setIsDebug();
1257 
1258  const DIExpression *DIExpr = MI.getDebugExpression();
1259 
1260  // If we have a direct DBG_VALUE, and its location expression isn't
1261  // currently complex, then adding an offset will morph it into a
1262  // complex location that is interpreted as being a memory address.
1263  // This changes a pointer-valued variable to dereference that pointer,
1264  // which is incorrect. Fix by adding DW_OP_stack_value.
1265 
1266  if (MI.isNonListDebugValue()) {
1267  unsigned PrependFlags = DIExpression::ApplyOffset;
1268  if (!MI.isIndirectDebugValue() && !DIExpr->isComplex())
1269  PrependFlags |= DIExpression::StackValue;
1270 
1271  // If we have DBG_VALUE that is indirect and has a Implicit location
1272  // expression need to insert a deref before prepending a Memory
1273  // location expression. Also after doing this we change the DBG_VALUE
1274  // to be direct.
1275  if (MI.isIndirectDebugValue() && DIExpr->isImplicit()) {
1276  SmallVector<uint64_t, 2> Ops = {dwarf::DW_OP_deref_size, Size};
1277  bool WithStackValue = true;
1278  DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, WithStackValue);
1279  // Make the DBG_VALUE direct.
1280  MI.getDebugOffset().ChangeToRegister(0, false);
1281  }
1282  DIExpr = TRI.prependOffsetExpression(DIExpr, PrependFlags, Offset);
1283  } else {
1284  // The debug operand at DebugOpIndex was a frame index at offset
1285  // `Offset`; now the operand has been replaced with the frame
1286  // register, we must add Offset with `register x, plus Offset`.
1287  unsigned DebugOpIndex = MI.getDebugOperandIndex(&Op);
1289  TRI.getOffsetOpcodes(Offset, Ops);
1290  DIExpr = DIExpression::appendOpsToArg(DIExpr, Ops, DebugOpIndex);
1291  }
1292  MI.getDebugExpressionOp().setMetadata(DIExpr);
1293  continue;
1294  } else if (MI.isDebugPHI()) {
1295  // Allow stack ref to continue onwards.
1296  continue;
1297  }
1298 
1299  // TODO: This code should be commoned with the code for
1300  // PATCHPOINT. There's no good reason for the difference in
1301  // implementation other than historical accident. The only
1302  // remaining difference is the unconditional use of the stack
1303  // pointer as the base register.
1304  if (MI.getOpcode() == TargetOpcode::STATEPOINT) {
1305  assert((!MI.isDebugValue() || i == 0) &&
1306  "Frame indicies can only appear as the first operand of a "
1307  "DBG_VALUE machine instruction");
1308  Register Reg;
1309  MachineOperand &Offset = MI.getOperand(i + 1);
1311  MF, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false);
1312  assert(!refOffset.getScalable() &&
1313  "Frame offsets with a scalable component are not supported");
1314  Offset.setImm(Offset.getImm() + refOffset.getFixed() + SPAdj);
1315  MI.getOperand(i).ChangeToRegister(Reg, false /*isDef*/);
1316  continue;
1317  }
1318 
1319  // Some instructions (e.g. inline asm instructions) can have
1320  // multiple frame indices and/or cause eliminateFrameIndex
1321  // to insert more than one instruction. We need the register
1322  // scavenger to go through all of these instructions so that
1323  // it can update its register information. We keep the
1324  // iterator at the point before insertion so that we can
1325  // revisit them in full.
1326  bool AtBeginning = (I == BB->begin());
1327  if (!AtBeginning) --I;
1328 
1329  // If this instruction has a FrameIndex operand, we need to
1330  // use that target machine register info object to eliminate
1331  // it.
1332  TRI.eliminateFrameIndex(MI, SPAdj, i,
1333  FrameIndexEliminationScavenging ? RS : nullptr);
1334 
1335  // Reset the iterator if we were at the beginning of the BB.
1336  if (AtBeginning) {
1337  I = BB->begin();
1338  DoIncr = false;
1339  }
1340 
1341  DidFinishLoop = false;
1342  break;
1343  }
1344 
1345  // If we are looking at a call sequence, we need to keep track of
1346  // the SP adjustment made by each instruction in the sequence.
1347  // This includes both the frame setup/destroy pseudos (handled above),
1348  // as well as other instructions that have side effects w.r.t the SP.
1349  // Note that this must come after eliminateFrameIndex, because
1350  // if I itself referred to a frame index, we shouldn't count its own
1351  // adjustment.
1352  if (DidFinishLoop && InsideCallSequence)
1353  SPAdj += TII.getSPAdjust(MI);
1354 
1355  if (DoIncr && I != BB->end()) ++I;
1356 
1357  // Update register states.
1358  if (RS && FrameIndexEliminationScavenging && DidFinishLoop)
1359  RS->forward(MI);
1360  }
1361 }
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:385
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
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:627
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:102
MachineInstr.h
MathExtras.h
llvm
---------------------— PointerInfo ------------------------------------—
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:1561
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:575
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:43
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:688
Pass.h
llvm::BitVector::set
BitVector & set()
Definition: BitVector.h:343
llvm::LLVMTargetMachine::usesPhysRegsForValues
virtual bool usesPhysRegsForValues() const
True if the target uses physical regs (as nearly all targets do).
Definition: TargetMachine.h:460
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:552
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:1532
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:174
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:642
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:805
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:124
llvm::MachineFunction::getNumBlockIDs
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Definition: MachineFunction.h:749
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:150
llvm::MachineFrameInfo::setStackSize
void setStackSize(uint64_t Size)
Set the size of the stack.
Definition: MachineFrameInfo.h:554
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:897
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::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:355
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:630
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:136
llvm::MachineFrameInfo::setAdjustsStack
void setAdjustsStack(bool V)
Definition: MachineFrameInfo.h:576
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:356
STLExtras.h
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:635
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2557
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition: MachineFrameInfo.h:391
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:891
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:620
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:118
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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:370
llvm::MachineBasicBlock::push_back
void push_back(MachineInstr *MI)
Definition: MachineBasicBlock.h:843
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:348
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:816
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:1301
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:632
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:140
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::Failed
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition: Error.h:198
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:3053
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:46
llvm::DIExpression::ApplyOffset
@ ApplyOffset
Definition: DebugInfoMetadata.h:2764
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition: TargetFrameLowering.h:100
llvm::MachineFrameInfo::setCalleeSavedInfoValid
void setCalleeSavedInfoValid(bool v)
Definition: MachineFrameInfo.h:768
llvm::TargetFrameLowering::hasReservedCallFrame
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition: TargetFrameLowering.h:274
llvm::MachineRegisterInfo::isReserved
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
Definition: MachineRegisterInfo.h:915
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:220
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:484
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:713
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::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:732
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:237
llvm::MachineFrameInfo::getRestorePoint
MachineBasicBlock * getRestorePoint() const
Definition: MachineFrameInfo.h:772
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition: MachineFrameInfo.h:697
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:551
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:492
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
llvm::Attribute::getValueAsString
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:301
llvm::StringRef::getAsInteger
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:510
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:711
llvm::TargetFrameLowering::isFPCloseToIncomingSP
virtual bool isFPCloseToIncomingSP() const
isFPCloseToIncomingSP - Return true if the frame pointer is close to the incoming stack pointer,...
Definition: TargetFrameLowering.h:145
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:573
llvm::DIExpression::isImplicit
bool isImplicit() const
Return whether this is an implicit location description.
Definition: DebugInfoMetadata.cpp:1166
llvm::TargetRegisterInfo::getSpillAlign
Align getSpillAlign(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::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:622
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::MachineFrameInfo::setCalleeSavedInfo
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
Definition: MachineFrameInfo.h:761
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:657
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:178
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:2767
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:225
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:20
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:465
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:251
MCRegisterInfo.h
llvm::MachineFrameInfo::setObjectOffset
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
Definition: MachineFrameInfo.h:526
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:773
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:230
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:638
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:89
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::TargetFrameLowering::assignCalleeSavedSpillSlots
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
Definition: TargetFrameLowering.h:153
llvm::MachineFrameInfo::setSavePoint
void setSavePoint(MachineBasicBlock *NewSave)
Definition: MachineFrameInfo.h:771
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::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:753
llvm::MachineBasicBlock::getFirstTerminator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Definition: MachineBasicBlock.cpp:242
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:1056
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:1554
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:198
llvm::InlineAsm::Extra_IsAlignStack
@ Extra_IsAlignStack
Definition: InlineAsm.h:224
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::CallingConv::HiPE
@ HiPE
Definition: CallingConv.h:55
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:792
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:147
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:567
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:579
CallingConv.h
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
Attributes.h
llvm::MachineFrameInfo::getSavePoint
MachineBasicBlock * getSavePoint() const
Definition: MachineFrameInfo.h:770
llvm::InlineAsm::MIOp_ExtraInfo
@ MIOp_ExtraInfo
Definition: InlineAsm.h:219
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:1347
llvm::MachineFrameInfo::getObjectSSPLayout
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
Definition: MachineFrameInfo.h:534
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:588
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:618
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:719
MachineFrameInfo.h
llvm::Function::getFnAttribute
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:365
llvm::MachineFunction::getWinEHFuncInfo
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
Definition: MachineFunction.h:666
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:53
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:1186
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:389
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:285
llvm::TargetFrameLowering::SpillSlot::Reg
unsigned Reg
Definition: TargetFrameLowering.h:52
llvm::TargetFrameLowering::targetHandlesStackFrameRounding
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
Definition: TargetFrameLowering.h:186
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:938
llvm::MCRegisterInfo::superregs
iterator_range< mc_superreg_iterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
Definition: MCRegisterInfo.h:322
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:584
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:885
insertCSRSaves
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI)
Insert restore code for the callee-saved registers used in the function.
Definition: PrologEpilogInserter.cpp:557
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:340
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:208
Threshold
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
MachineOperand.h
llvm::TargetFrameLowering::StackGrowsDown
@ StackGrowsDown
Definition: TargetFrameLowering.h:47
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:307
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:575
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:51
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:920
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:649
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:903
llvm::DIExpression::fragmentsOverlap
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
Definition: DebugInfoMetadata.h:2854