LLVM  16.0.0git
StackSlotColoring.cpp
Go to the documentation of this file.
1 //===- StackSlotColoring.cpp - Stack slot coloring pass. ------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the stack slot coloring pass.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/BitVector.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/Statistic.h"
27 #include "llvm/CodeGen/Passes.h"
32 #include "llvm/InitializePasses.h"
33 #include "llvm/Pass.h"
34 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/Debug.h"
38 #include <algorithm>
39 #include <cassert>
40 #include <cstdint>
41 #include <iterator>
42 #include <vector>
43 
44 using namespace llvm;
45 
46 #define DEBUG_TYPE "stack-slot-coloring"
47 
48 static cl::opt<bool>
49 DisableSharing("no-stack-slot-sharing",
50  cl::init(false), cl::Hidden,
51  cl::desc("Suppress slot sharing during stack coloring"));
52 
53 static cl::opt<int> DCELimit("ssc-dce-limit", cl::init(-1), cl::Hidden);
54 
55 STATISTIC(NumEliminated, "Number of stack slots eliminated due to coloring");
56 STATISTIC(NumDead, "Number of trivially dead stack accesses eliminated");
57 
58 namespace {
59 
60  class StackSlotColoring : public MachineFunctionPass {
61  LiveStacks* LS;
62  MachineFrameInfo *MFI;
63  const TargetInstrInfo *TII;
64  const MachineBlockFrequencyInfo *MBFI;
65 
66  // SSIntervals - Spill slot intervals.
67  std::vector<LiveInterval*> SSIntervals;
68 
69  // SSRefs - Keep a list of MachineMemOperands for each spill slot.
70  // MachineMemOperands can be shared between instructions, so we need
71  // to be careful that renames like [FI0, FI1] -> [FI1, FI2] do not
72  // become FI0 -> FI1 -> FI2.
74 
75  // OrigAlignments - Alignments of stack objects before coloring.
76  SmallVector<Align, 16> OrigAlignments;
77 
78  // OrigSizes - Sizes of stack objects before coloring.
79  SmallVector<unsigned, 16> OrigSizes;
80 
81  // AllColors - If index is set, it's a spill slot, i.e. color.
82  // FIXME: This assumes PEI locate spill slot with smaller indices
83  // closest to stack pointer / frame pointer. Therefore, smaller
84  // index == better color. This is per stack ID.
85  SmallVector<BitVector, 2> AllColors;
86 
87  // NextColor - Next "color" that's not yet used. This is per stack ID.
88  SmallVector<int, 2> NextColors = { -1 };
89 
90  // UsedColors - "Colors" that have been assigned. This is per stack ID
91  SmallVector<BitVector, 2> UsedColors;
92 
93  // Assignments - Color to intervals mapping.
95 
96  public:
97  static char ID; // Pass identification
98 
99  StackSlotColoring() : MachineFunctionPass(ID) {
101  }
102 
103  void getAnalysisUsage(AnalysisUsage &AU) const override {
104  AU.setPreservesCFG();
105  AU.addRequired<SlotIndexes>();
107  AU.addRequired<LiveStacks>();
112  }
113 
114  bool runOnMachineFunction(MachineFunction &MF) override;
115 
116  private:
117  void InitializeSlots();
118  void ScanForSpillSlotRefs(MachineFunction &MF);
119  bool OverlapWithAssignments(LiveInterval *li, int Color) const;
120  int ColorSlot(LiveInterval *li);
121  bool ColorSlots(MachineFunction &MF);
122  void RewriteInstruction(MachineInstr &MI, SmallVectorImpl<int> &SlotMapping,
123  MachineFunction &MF);
124  bool RemoveDeadStores(MachineBasicBlock* MBB);
125  };
126 
127 } // end anonymous namespace
128 
129 char StackSlotColoring::ID = 0;
130 
132 
133 INITIALIZE_PASS_BEGIN(StackSlotColoring, DEBUG_TYPE,
134  "Stack Slot Coloring", false, false)
138 INITIALIZE_PASS_END(StackSlotColoring, DEBUG_TYPE,
139  "Stack Slot Coloring", false, false)
140 
141 namespace {
142 
143 // IntervalSorter - Comparison predicate that sort live intervals by
144 // their weight.
147  return LHS->weight() > RHS->weight();
148  }
149 };
150 
151 } // end anonymous namespace
152 
153 /// ScanForSpillSlotRefs - Scan all the machine instructions for spill slot
154 /// references and update spill slot weights.
155 void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
156  SSRefs.resize(MFI->getObjectIndexEnd());
157 
158  // FIXME: Need the equivalent of MachineRegisterInfo for frameindex operands.
159  for (MachineBasicBlock &MBB : MF) {
160  for (MachineInstr &MI : MBB) {
161  for (const MachineOperand &MO : MI.operands()) {
162  if (!MO.isFI())
163  continue;
164  int FI = MO.getIndex();
165  if (FI < 0)
166  continue;
167  if (!LS->hasInterval(FI))
168  continue;
169  LiveInterval &li = LS->getInterval(FI);
170  if (!MI.isDebugInstr())
171  li.incrementWeight(
172  LiveIntervals::getSpillWeight(false, true, MBFI, MI));
173  }
174  for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(),
175  EE = MI.memoperands_end();
176  MMOI != EE; ++MMOI) {
177  MachineMemOperand *MMO = *MMOI;
178  if (const FixedStackPseudoSourceValue *FSV =
179  dyn_cast_or_null<FixedStackPseudoSourceValue>(
180  MMO->getPseudoValue())) {
181  int FI = FSV->getFrameIndex();
182  if (FI >= 0)
183  SSRefs[FI].push_back(MMO);
184  }
185  }
186  }
187  }
188 }
189 
190 /// InitializeSlots - Process all spill stack slot liveintervals and add them
191 /// to a sorted (by weight) list.
192 void StackSlotColoring::InitializeSlots() {
193  int LastFI = MFI->getObjectIndexEnd();
194 
195  // There is always at least one stack ID.
196  AllColors.resize(1);
197  UsedColors.resize(1);
198 
199  OrigAlignments.resize(LastFI);
200  OrigSizes.resize(LastFI);
201  AllColors[0].resize(LastFI);
202  UsedColors[0].resize(LastFI);
203  Assignments.resize(LastFI);
204 
205  using Pair = std::iterator_traits<LiveStacks::iterator>::value_type;
206 
207  SmallVector<Pair *, 16> Intervals;
208 
209  Intervals.reserve(LS->getNumIntervals());
210  for (auto &I : *LS)
211  Intervals.push_back(&I);
212  llvm::sort(Intervals,
213  [](Pair *LHS, Pair *RHS) { return LHS->first < RHS->first; });
214 
215  // Gather all spill slots into a list.
216  LLVM_DEBUG(dbgs() << "Spill slot intervals:\n");
217  for (auto *I : Intervals) {
218  LiveInterval &li = I->second;
219  LLVM_DEBUG(li.dump());
220  int FI = Register::stackSlot2Index(li.reg());
221  if (MFI->isDeadObjectIndex(FI))
222  continue;
223 
224  SSIntervals.push_back(&li);
225  OrigAlignments[FI] = MFI->getObjectAlign(FI);
226  OrigSizes[FI] = MFI->getObjectSize(FI);
227 
228  auto StackID = MFI->getStackID(FI);
229  if (StackID != 0) {
230  AllColors.resize(StackID + 1);
231  UsedColors.resize(StackID + 1);
232  AllColors[StackID].resize(LastFI);
233  UsedColors[StackID].resize(LastFI);
234  }
235 
236  AllColors[StackID].set(FI);
237  }
238  LLVM_DEBUG(dbgs() << '\n');
239 
240  // Sort them by weight.
241  llvm::stable_sort(SSIntervals, IntervalSorter());
242 
243  NextColors.resize(AllColors.size());
244 
245  // Get first "color".
246  for (unsigned I = 0, E = AllColors.size(); I != E; ++I)
247  NextColors[I] = AllColors[I].find_first();
248 }
249 
250 /// OverlapWithAssignments - Return true if LiveInterval overlaps with any
251 /// LiveIntervals that have already been assigned to the specified color.
252 bool
253 StackSlotColoring::OverlapWithAssignments(LiveInterval *li, int Color) const {
254  const SmallVectorImpl<LiveInterval *> &OtherLIs = Assignments[Color];
255  for (unsigned i = 0, e = OtherLIs.size(); i != e; ++i) {
256  LiveInterval *OtherLI = OtherLIs[i];
257  if (OtherLI->overlaps(*li))
258  return true;
259  }
260  return false;
261 }
262 
263 /// ColorSlot - Assign a "color" (stack slot) to the specified stack slot.
264 int StackSlotColoring::ColorSlot(LiveInterval *li) {
265  int Color = -1;
266  bool Share = false;
267  int FI = Register::stackSlot2Index(li->reg());
268  uint8_t StackID = MFI->getStackID(FI);
269 
270  if (!DisableSharing) {
271 
272  // Check if it's possible to reuse any of the used colors.
273  Color = UsedColors[StackID].find_first();
274  while (Color != -1) {
275  if (!OverlapWithAssignments(li, Color)) {
276  Share = true;
277  ++NumEliminated;
278  break;
279  }
280  Color = UsedColors[StackID].find_next(Color);
281  }
282  }
283 
284  if (Color != -1 && MFI->getStackID(Color) != MFI->getStackID(FI)) {
285  LLVM_DEBUG(dbgs() << "cannot share FIs with different stack IDs\n");
286  Share = false;
287  }
288 
289  // Assign it to the first available color (assumed to be the best) if it's
290  // not possible to share a used color with other objects.
291  if (!Share) {
292  assert(NextColors[StackID] != -1 && "No more spill slots?");
293  Color = NextColors[StackID];
294  UsedColors[StackID].set(Color);
295  NextColors[StackID] = AllColors[StackID].find_next(NextColors[StackID]);
296  }
297 
298  assert(MFI->getStackID(Color) == MFI->getStackID(FI));
299 
300  // Record the assignment.
301  Assignments[Color].push_back(li);
302  LLVM_DEBUG(dbgs() << "Assigning fi#" << FI << " to fi#" << Color << "\n");
303 
304  // Change size and alignment of the allocated slot. If there are multiple
305  // objects sharing the same slot, then make sure the size and alignment
306  // are large enough for all.
307  Align Alignment = OrigAlignments[FI];
308  if (!Share || Alignment > MFI->getObjectAlign(Color))
309  MFI->setObjectAlignment(Color, Alignment);
310  int64_t Size = OrigSizes[FI];
311  if (!Share || Size > MFI->getObjectSize(Color))
312  MFI->setObjectSize(Color, Size);
313  return Color;
314 }
315 
316 /// Colorslots - Color all spill stack slots and rewrite all frameindex machine
317 /// operands in the function.
318 bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
319  unsigned NumObjs = MFI->getObjectIndexEnd();
320  SmallVector<int, 16> SlotMapping(NumObjs, -1);
321  SmallVector<float, 16> SlotWeights(NumObjs, 0.0);
322  SmallVector<SmallVector<int, 4>, 16> RevMap(NumObjs);
323  BitVector UsedColors(NumObjs);
324 
325  LLVM_DEBUG(dbgs() << "Color spill slot intervals:\n");
326  bool Changed = false;
327  for (LiveInterval *li : SSIntervals) {
328  int SS = Register::stackSlot2Index(li->reg());
329  int NewSS = ColorSlot(li);
330  assert(NewSS >= 0 && "Stack coloring failed?");
331  SlotMapping[SS] = NewSS;
332  RevMap[NewSS].push_back(SS);
333  SlotWeights[NewSS] += li->weight();
334  UsedColors.set(NewSS);
335  Changed |= (SS != NewSS);
336  }
337 
338  LLVM_DEBUG(dbgs() << "\nSpill slots after coloring:\n");
339  for (LiveInterval *li : SSIntervals) {
340  int SS = Register::stackSlot2Index(li->reg());
341  li->setWeight(SlotWeights[SS]);
342  }
343  // Sort them by new weight.
344  llvm::stable_sort(SSIntervals, IntervalSorter());
345 
346 #ifndef NDEBUG
347  for (LiveInterval *li : SSIntervals)
348  LLVM_DEBUG(li->dump());
349  LLVM_DEBUG(dbgs() << '\n');
350 #endif
351 
352  if (!Changed)
353  return false;
354 
355  // Rewrite all MachineMemOperands.
356  for (unsigned SS = 0, SE = SSRefs.size(); SS != SE; ++SS) {
357  int NewFI = SlotMapping[SS];
358  if (NewFI == -1 || (NewFI == (int)SS))
359  continue;
360 
361  const PseudoSourceValue *NewSV = MF.getPSVManager().getFixedStack(NewFI);
362  SmallVectorImpl<MachineMemOperand *> &RefMMOs = SSRefs[SS];
363  for (unsigned i = 0, e = RefMMOs.size(); i != e; ++i)
364  RefMMOs[i]->setValue(NewSV);
365  }
366 
367  // Rewrite all MO_FrameIndex operands. Look for dead stores.
368  for (MachineBasicBlock &MBB : MF) {
369  for (MachineInstr &MI : MBB)
370  RewriteInstruction(MI, SlotMapping, MF);
371  RemoveDeadStores(&MBB);
372  }
373 
374  // Delete unused stack slots.
375  for (int StackID = 0, E = AllColors.size(); StackID != E; ++StackID) {
376  int NextColor = NextColors[StackID];
377  while (NextColor != -1) {
378  LLVM_DEBUG(dbgs() << "Removing unused stack object fi#" << NextColor << "\n");
379  MFI->RemoveStackObject(NextColor);
380  NextColor = AllColors[StackID].find_next(NextColor);
381  }
382  }
383 
384  return true;
385 }
386 
387 /// RewriteInstruction - Rewrite specified instruction by replacing references
388 /// to old frame index with new one.
389 void StackSlotColoring::RewriteInstruction(MachineInstr &MI,
391  MachineFunction &MF) {
392  // Update the operands.
393  for (MachineOperand &MO : MI.operands()) {
394  if (!MO.isFI())
395  continue;
396  int OldFI = MO.getIndex();
397  if (OldFI < 0)
398  continue;
399  int NewFI = SlotMapping[OldFI];
400  if (NewFI == -1 || NewFI == OldFI)
401  continue;
402 
403  assert(MFI->getStackID(OldFI) == MFI->getStackID(NewFI));
404  MO.setIndex(NewFI);
405  }
406 
407  // The MachineMemOperands have already been updated.
408 }
409 
410 /// RemoveDeadStores - Scan through a basic block and look for loads followed
411 /// by stores. If they're both using the same stack slot, then the store is
412 /// definitely dead. This could obviously be much more aggressive (consider
413 /// pairs with instructions between them), but such extensions might have a
414 /// considerable compile time impact.
415 bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
416  // FIXME: This could be much more aggressive, but we need to investigate
417  // the compile time impact of doing so.
418  bool changed = false;
419 
421 
422  for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
423  I != E; ++I) {
424  if (DCELimit != -1 && (int)NumDead >= DCELimit)
425  break;
426  int FirstSS, SecondSS;
427  if (TII->isStackSlotCopy(*I, FirstSS, SecondSS) && FirstSS == SecondSS &&
428  FirstSS != -1) {
429  ++NumDead;
430  changed = true;
431  toErase.push_back(&*I);
432  continue;
433  }
434 
435  MachineBasicBlock::iterator NextMI = std::next(I);
436  MachineBasicBlock::iterator ProbableLoadMI = I;
437 
438  unsigned LoadReg = 0;
439  unsigned StoreReg = 0;
440  unsigned LoadSize = 0;
441  unsigned StoreSize = 0;
442  if (!(LoadReg = TII->isLoadFromStackSlot(*I, FirstSS, LoadSize)))
443  continue;
444  // Skip the ...pseudo debugging... instructions between a load and store.
445  while ((NextMI != E) && NextMI->isDebugInstr()) {
446  ++NextMI;
447  ++I;
448  }
449  if (NextMI == E) continue;
450  if (!(StoreReg = TII->isStoreToStackSlot(*NextMI, SecondSS, StoreSize)))
451  continue;
452  if (FirstSS != SecondSS || LoadReg != StoreReg || FirstSS == -1 ||
453  LoadSize != StoreSize)
454  continue;
455 
456  ++NumDead;
457  changed = true;
458 
459  if (NextMI->findRegisterUseOperandIdx(LoadReg, true, nullptr) != -1) {
460  ++NumDead;
461  toErase.push_back(&*ProbableLoadMI);
462  }
463 
464  toErase.push_back(&*NextMI);
465  ++I;
466  }
467 
468  for (MachineInstr *MI : toErase)
469  MI->eraseFromParent();
470 
471  return changed;
472 }
473 
474 bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
475  LLVM_DEBUG({
476  dbgs() << "********** Stack Slot Coloring **********\n"
477  << "********** Function: " << MF.getName() << '\n';
478  });
479 
480  if (skipFunction(MF.getFunction()))
481  return false;
482 
483  MFI = &MF.getFrameInfo();
484  TII = MF.getSubtarget().getInstrInfo();
485  LS = &getAnalysis<LiveStacks>();
486  MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
487 
488  bool Changed = false;
489 
490  unsigned NumSlots = LS->getNumIntervals();
491  if (NumSlots == 0)
492  // Nothing to do!
493  return false;
494 
495  // If there are calls to setjmp or sigsetjmp, don't perform stack slot
496  // coloring. The stack could be modified before the longjmp is executed,
497  // resulting in the wrong value being used afterwards. (See
498  // <rdar://problem/8007500>.)
499  if (MF.exposesReturnsTwice())
500  return false;
501 
502  // Gather spill slot references
503  ScanForSpillSlotRefs(MF);
504  InitializeSlots();
505  Changed = ColorSlots(MF);
506 
507  for (int &Next : NextColors)
508  Next = -1;
509 
510  SSIntervals.clear();
511  for (unsigned i = 0, e = SSRefs.size(); i != e; ++i)
512  SSRefs[i].clear();
513  SSRefs.clear();
514  OrigAlignments.clear();
515  OrigSizes.clear();
516  AllColors.clear();
517  UsedColors.clear();
518  for (unsigned i = 0, e = Assignments.size(); i != e; ++i)
519  Assignments[i].clear();
520  Assignments.clear();
521 
522  return Changed;
523 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
i
i
Definition: README.txt:29
llvm::HexagonInstrInfo::isStoreToStackSlot
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
If the specified machine instruction is a direct store to a stack slot, return the virtual or physica...
Definition: HexagonInstrInfo.cpp:335
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:108
MachineInstr.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DisableSharing
static cl::opt< bool > DisableSharing("no-stack-slot-sharing", cl::init(false), cl::Hidden, cl::desc("Suppress slot sharing during stack coloring"))
Pass.h
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:93
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1182
Statistic.h
llvm::LiveInterval::weight
float weight() const
Definition: LiveInterval.h:718
llvm::MachineFunction::exposesReturnsTwice
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
Definition: MachineFunction.h:718
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
MachineBasicBlock.h
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
llvm::Register::stackSlot2Index
static int stackSlot2Index(Register Reg)
Compute the frame index from a register value representing a stack slot.
Definition: Register.h:52
TargetInstrInfo.h
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:127
llvm::MachineFunction::getPSVManager
PseudoSourceValueManager & getPSVManager() const
Definition: MachineFunction.h:616
llvm::MachineFrameInfo::setObjectSize
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
Definition: MachineFrameInfo.h:476
llvm::MachineFrameInfo::RemoveStackObject
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
Definition: MachineFrameInfo.h:768
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition: MachineFrameInfo.h:409
llvm::StackSlotColoringID
char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
Definition: StackSlotColoring.cpp:131
Coloring
Stack Slot Coloring
Definition: StackSlotColoring.cpp:139
llvm::MachineFrameInfo::setObjectAlignment
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
Definition: MachineFrameInfo.h:490
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:167
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:89
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
CommandLine.h
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::X86AS::SS
@ SS
Definition: X86.h:201
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:98
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
llvm::MachineBlockFrequencyInfo
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Definition: MachineBlockFrequencyInfo.h:33
false::IntervalSorter::operator()
bool operator()(LiveInterval *LHS, LiveInterval *RHS) const
Definition: StackSlotColoring.cpp:146
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::LiveInterval::dump
void dump() const
Definition: LiveInterval.cpp:1049
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:141
PseudoSourceValue.h
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:125
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:48
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition: MachineFrameInfo.h:723
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:625
BitVector.h
llvm::SlotIndexes
SlotIndexes pass.
Definition: SlotIndexes.h:319
llvm::BitVector
Definition: BitVector.h:75
llvm::PseudoSourceValue
Special value supplied for machine level alias analysis.
Definition: PseudoSourceValue.h:35
llvm::LiveInterval
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:686
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::MachineFrameInfo::isDeadObjectIndex
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
Definition: MachineFrameInfo.h:737
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1538
Passes.h
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
llvm::cl::opt< bool >
llvm::SlotMapping
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:32
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition: MachineFrameInfo.h:469
LiveIntervals.h
llvm::LiveInterval::incrementWeight
void incrementWeight(float Inc)
Definition: LiveInterval.h:719
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(StackSlotColoring, DEBUG_TYPE, "Stack Slot Coloring", false, false) INITIALIZE_PASS_END(StackSlotColoring
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:54
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition: MachineFrameInfo.h:483
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:439
llvm::LiveRange::overlaps
bool overlaps(const LiveRange &other) const
overlaps - Return true if the intersection of the two live ranges is not empty.
Definition: LiveInterval.h:448
false::IntervalSorter
Definition: StackSlotColoring.cpp:145
MachineFunctionPass.h
llvm::MachineInstr::mmo_iterator
ArrayRef< MachineMemOperand * >::iterator mmo_iterator
Definition: MachineInstr.h:70
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:567
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:672
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:263
llvm::AnalysisUsage::addPreservedID
AnalysisUsage & addPreservedID(const void *ID)
Definition: PassAnalysisSupport.h:88
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
TargetSubtargetInfo.h
llvm::HexagonInstrInfo::isLoadFromStackSlot
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
Definition: HexagonInstrInfo.cpp:287
llvm::LiveInterval::setWeight
void setWeight(float Value)
Definition: LiveInterval.h:720
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1752
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
llvm::LiveIntervals::getSpillWeight
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI)
Calculate the spill weight to assign to a single instruction.
Definition: LiveIntervals.cpp:859
llvm::PseudoSourceValueManager::getFixedStack
const PseudoSourceValue * getFixedStack(int FI)
Return a pseudo source value referencing a fixed stack frame entry, e.g., a spill slot.
Definition: PseudoSourceValue.cpp:123
llvm::initializeStackSlotColoringPass
void initializeStackSlotColoringPass(PassRegistry &)
MachineFrameInfo.h
DEBUG_TYPE
#define DEBUG_TYPE
Definition: StackSlotColoring.cpp:46
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
Casting.h
llvm::FixedStackPseudoSourceValue
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index.
Definition: PseudoSourceValue.h:94
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:597
LiveInterval.h
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:105
SmallVector.h
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:305
LiveStacks.h
llvm::MachineDominatorsID
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
llvm::LiveInterval::reg
Register reg() const
Definition: LiveInterval.h:717
MachineMemOperand.h
llvm::SmallVectorImpl< int >
MachineOperand.h
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
SlotIndexes.h
llvm::cl::desc
Definition: CommandLine.h:412
raw_ostream.h
MachineFunction.h
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:650
llvm::MachineInstrBundleIterator< MachineInstr >
InitializePasses.h
llvm::LiveStacks
Definition: LiveStacks.h:35
MachineBlockFrequencyInfo.h
Debug.h
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:307
DCELimit
static cl::opt< int > DCELimit("ssc-dce-limit", cl::init(-1), cl::Hidden)
llvm::MachineMemOperand::getPseudoValue
const PseudoSourceValue * getPseudoValue() const
Definition: MachineMemOperand.h:212
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38