Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/StackSlotColoring.cpp
Line
Count
Source (jump to first uncovered line)
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"
16
#include "llvm/CodeGen/LiveInterval.h"
17
#include "llvm/CodeGen/LiveIntervals.h"
18
#include "llvm/CodeGen/LiveStacks.h"
19
#include "llvm/CodeGen/MachineBasicBlock.h"
20
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
21
#include "llvm/CodeGen/MachineFrameInfo.h"
22
#include "llvm/CodeGen/MachineFunction.h"
23
#include "llvm/CodeGen/MachineFunctionPass.h"
24
#include "llvm/CodeGen/MachineInstr.h"
25
#include "llvm/CodeGen/MachineMemOperand.h"
26
#include "llvm/CodeGen/MachineOperand.h"
27
#include "llvm/CodeGen/Passes.h"
28
#include "llvm/CodeGen/PseudoSourceValue.h"
29
#include "llvm/CodeGen/SlotIndexes.h"
30
#include "llvm/CodeGen/TargetInstrInfo.h"
31
#include "llvm/CodeGen/TargetRegisterInfo.h"
32
#include "llvm/CodeGen/TargetSubtargetInfo.h"
33
#include "llvm/Pass.h"
34
#include "llvm/Support/Casting.h"
35
#include "llvm/Support/CommandLine.h"
36
#include "llvm/Support/Debug.h"
37
#include "llvm/Support/raw_ostream.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.
73
    SmallVector<SmallVector<MachineMemOperand *, 8>, 16> SSRefs;
74
75
    // OrigAlignments - Alignments of stack objects before coloring.
76
    SmallVector<unsigned, 16> OrigAlignments;
77
78
    // OrigSizes - Sizess 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.
94
    SmallVector<SmallVector<LiveInterval*,4>, 16> Assignments;
95
96
  public:
97
    static char ID; // Pass identification
98
99
34.0k
    StackSlotColoring() : MachineFunctionPass(ID) {
100
34.0k
      initializeStackSlotColoringPass(*PassRegistry::getPassRegistry());
101
34.0k
    }
102
103
33.8k
    void getAnalysisUsage(AnalysisUsage &AU) const override {
104
33.8k
      AU.setPreservesCFG();
105
33.8k
      AU.addRequired<SlotIndexes>();
106
33.8k
      AU.addPreserved<SlotIndexes>();
107
33.8k
      AU.addRequired<LiveStacks>();
108
33.8k
      AU.addRequired<MachineBlockFrequencyInfo>();
109
33.8k
      AU.addPreserved<MachineBlockFrequencyInfo>();
110
33.8k
      AU.addPreservedID(MachineDominatorsID);
111
33.8k
      MachineFunctionPass::getAnalysisUsage(AU);
112
33.8k
    }
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
131
char &llvm::StackSlotColoringID = StackSlotColoring::ID;
132
133
42.3k
INITIALIZE_PASS_BEGIN(StackSlotColoring, DEBUG_TYPE,
134
42.3k
                "Stack Slot Coloring", false, false)
135
42.3k
INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
136
42.3k
INITIALIZE_PASS_DEPENDENCY(LiveStacks)
137
42.3k
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
138
42.3k
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.
145
struct IntervalSorter {
146
907k
  bool operator()(LiveInterval* LHS, LiveInterval* RHS) const {
147
907k
    return LHS->weight > RHS->weight;
148
907k
  }
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
25.4k
void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
156
25.4k
  SSRefs.resize(MFI->getObjectIndexEnd());
157
25.4k
158
25.4k
  // FIXME: Need the equivalent of MachineRegisterInfo for frameindex operands.
159
25.4k
  for (MachineFunction::iterator MBBI = MF.begin(), E = MF.end();
160
1.05M
       MBBI != E; 
++MBBI1.03M
) {
161
1.03M
    MachineBasicBlock *MBB = &*MBBI;
162
1.03M
    for (MachineBasicBlock::iterator MII = MBB->begin(), EE = MBB->end();
163
8.64M
         MII != EE; 
++MII7.60M
) {
164
7.60M
      MachineInstr &MI = *MII;
165
34.1M
      for (unsigned i = 0, e = MI.getNumOperands(); i != e; 
++i26.5M
) {
166
26.5M
        MachineOperand &MO = MI.getOperand(i);
167
26.5M
        if (!MO.isFI())
168
25.9M
          continue;
169
634k
        int FI = MO.getIndex();
170
634k
        if (FI < 0)
171
11.2k
          continue;
172
623k
        if (!LS->hasInterval(FI))
173
277k
          continue;
174
346k
        LiveInterval &li = LS->getInterval(FI);
175
346k
        if (!MI.isDebugValue())
176
346k
          li.weight += LiveIntervals::getSpillWeight(false, true, MBFI, MI);
177
346k
      }
178
7.60M
      for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(),
179
7.60M
                                      EE = MI.memoperands_end();
180
9.29M
           MMOI != EE; 
++MMOI1.68M
) {
181
1.68M
        MachineMemOperand *MMO = *MMOI;
182
1.68M
        if (const FixedStackPseudoSourceValue *FSV =
183
364k
            dyn_cast_or_null<FixedStackPseudoSourceValue>(
184
364k
                MMO->getPseudoValue())) {
185
364k
          int FI = FSV->getFrameIndex();
186
364k
          if (FI >= 0)
187
353k
            SSRefs[FI].push_back(MMO);
188
364k
        }
189
1.68M
      }
190
7.60M
    }
191
1.03M
  }
192
25.4k
}
193
194
/// InitializeSlots - Process all spill stack slot liveintervals and add them
195
/// to a sorted (by weight) list.
196
25.4k
void StackSlotColoring::InitializeSlots() {
197
25.4k
  int LastFI = MFI->getObjectIndexEnd();
198
25.4k
199
25.4k
  // There is always at least one stack ID.
200
25.4k
  AllColors.resize(1);
201
25.4k
  UsedColors.resize(1);
202
25.4k
203
25.4k
  OrigAlignments.resize(LastFI);
204
25.4k
  OrigSizes.resize(LastFI);
205
25.4k
  AllColors[0].resize(LastFI);
206
25.4k
  UsedColors[0].resize(LastFI);
207
25.4k
  Assignments.resize(LastFI);
208
25.4k
209
25.4k
  using Pair = std::iterator_traits<LiveStacks::iterator>::value_type;
210
25.4k
211
25.4k
  SmallVector<Pair *, 16> Intervals;
212
25.4k
213
25.4k
  Intervals.reserve(LS->getNumIntervals());
214
25.4k
  for (auto &I : *LS)
215
121k
    Intervals.push_back(&I);
216
25.4k
  llvm::sort(Intervals,
217
367k
             [](Pair *LHS, Pair *RHS) { return LHS->first < RHS->first; });
218
25.4k
219
25.4k
  // Gather all spill slots into a list.
220
25.4k
  LLVM_DEBUG(dbgs() << "Spill slot intervals:\n");
221
121k
  for (auto *I : Intervals) {
222
121k
    LiveInterval &li = I->second;
223
121k
    LLVM_DEBUG(li.dump());
224
121k
    int FI = TargetRegisterInfo::stackSlot2Index(li.reg);
225
121k
    if (MFI->isDeadObjectIndex(FI))
226
0
      continue;
227
121k
228
121k
    SSIntervals.push_back(&li);
229
121k
    OrigAlignments[FI] = MFI->getObjectAlignment(FI);
230
121k
    OrigSizes[FI]      = MFI->getObjectSize(FI);
231
121k
232
121k
    auto StackID = MFI->getStackID(FI);
233
121k
    if (StackID != 0) {
234
249
      AllColors.resize(StackID + 1);
235
249
      UsedColors.resize(StackID + 1);
236
249
      AllColors[StackID].resize(LastFI);
237
249
      UsedColors[StackID].resize(LastFI);
238
249
    }
239
121k
240
121k
    AllColors[StackID].set(FI);
241
121k
  }
242
25.4k
  LLVM_DEBUG(dbgs() << '\n');
243
25.4k
244
25.4k
  // Sort them by weight.
245
25.4k
  llvm::stable_sort(SSIntervals, IntervalSorter());
246
25.4k
247
25.4k
  NextColors.resize(AllColors.size());
248
25.4k
249
25.4k
  // Get first "color".
250
51.0k
  for (unsigned I = 0, E = AllColors.size(); I != E; 
++I25.5k
)
251
25.5k
    NextColors[I] = AllColors[I].find_first();
252
25.4k
}
253
254
/// OverlapWithAssignments - Return true if LiveInterval overlaps with any
255
/// LiveIntervals that have already been assigned to the specified color.
256
bool
257
6.01M
StackSlotColoring::OverlapWithAssignments(LiveInterval *li, int Color) const {
258
6.01M
  const SmallVectorImpl<LiveInterval *> &OtherLIs = Assignments[Color];
259
7.33M
  for (unsigned i = 0, e = OtherLIs.size(); i != e; 
++i1.32M
) {
260
7.30M
    LiveInterval *OtherLI = OtherLIs[i];
261
7.30M
    if (OtherLI->overlaps(*li))
262
5.98M
      return true;
263
7.30M
  }
264
6.01M
  
return false24.4k
;
265
6.01M
}
266
267
/// ColorSlot - Assign a "color" (stack slot) to the specified stack slot.
268
121k
int StackSlotColoring::ColorSlot(LiveInterval *li) {
269
121k
  int Color = -1;
270
121k
  bool Share = false;
271
121k
  int FI = TargetRegisterInfo::stackSlot2Index(li->reg);
272
121k
  uint8_t StackID = MFI->getStackID(FI);
273
121k
274
121k
  if (!DisableSharing) {
275
121k
276
121k
    // Check if it's possible to reuse any of the used colors.
277
121k
    Color = UsedColors[StackID].find_first();
278
6.10M
    while (Color != -1) {
279
6.01M
      if (!OverlapWithAssignments(li, Color)) {
280
24.4k
        Share = true;
281
24.4k
        ++NumEliminated;
282
24.4k
        break;
283
24.4k
      }
284
5.98M
      Color = UsedColors[StackID].find_next(Color);
285
5.98M
    }
286
121k
  }
287
121k
288
121k
  if (Color != -1 && 
MFI->getStackID(Color) != MFI->getStackID(FI)24.4k
) {
289
0
    LLVM_DEBUG(dbgs() << "cannot share FIs with different stack IDs\n");
290
0
    Share = false;
291
0
  }
292
121k
293
121k
  // Assign it to the first available color (assumed to be the best) if it's
294
121k
  // not possible to share a used color with other objects.
295
121k
  if (!Share) {
296
97.2k
    assert(NextColors[StackID] != -1 && "No more spill slots?");
297
97.2k
    Color = NextColors[StackID];
298
97.2k
    UsedColors[StackID].set(Color);
299
97.2k
    NextColors[StackID] = AllColors[StackID].find_next(NextColors[StackID]);
300
97.2k
  }
301
121k
302
121k
  assert(MFI->getStackID(Color) == MFI->getStackID(FI));
303
121k
304
121k
  // Record the assignment.
305
121k
  Assignments[Color].push_back(li);
306
121k
  LLVM_DEBUG(dbgs() << "Assigning fi#" << FI << " to fi#" << Color << "\n");
307
121k
308
121k
  // Change size and alignment of the allocated slot. If there are multiple
309
121k
  // objects sharing the same slot, then make sure the size and alignment
310
121k
  // are large enough for all.
311
121k
  unsigned Align = OrigAlignments[FI];
312
121k
  if (!Share || 
Align > MFI->getObjectAlignment(Color)24.4k
)
313
99.8k
    MFI->setObjectAlignment(Color, Align);
314
121k
  int64_t Size = OrigSizes[FI];
315
121k
  if (!Share || 
Size > MFI->getObjectSize(Color)24.4k
)
316
99.8k
    MFI->setObjectSize(Color, Size);
317
121k
  return Color;
318
121k
}
319
320
/// Colorslots - Color all spill stack slots and rewrite all frameindex machine
321
/// operands in the function.
322
25.4k
bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
323
25.4k
  unsigned NumObjs = MFI->getObjectIndexEnd();
324
25.4k
  SmallVector<int, 16> SlotMapping(NumObjs, -1);
325
25.4k
  SmallVector<float, 16> SlotWeights(NumObjs, 0.0);
326
25.4k
  SmallVector<SmallVector<int, 4>, 16> RevMap(NumObjs);
327
25.4k
  BitVector UsedColors(NumObjs);
328
25.4k
329
25.4k
  LLVM_DEBUG(dbgs() << "Color spill slot intervals:\n");
330
25.4k
  bool Changed = false;
331
147k
  for (unsigned i = 0, e = SSIntervals.size(); i != e; 
++i121k
) {
332
121k
    LiveInterval *li = SSIntervals[i];
333
121k
    int SS = TargetRegisterInfo::stackSlot2Index(li->reg);
334
121k
    int NewSS = ColorSlot(li);
335
121k
    assert(NewSS >= 0 && "Stack coloring failed?");
336
121k
    SlotMapping[SS] = NewSS;
337
121k
    RevMap[NewSS].push_back(SS);
338
121k
    SlotWeights[NewSS] += li->weight;
339
121k
    UsedColors.set(NewSS);
340
121k
    Changed |= (SS != NewSS);
341
121k
  }
342
25.4k
343
25.4k
  LLVM_DEBUG(dbgs() << "\nSpill slots after coloring:\n");
344
147k
  for (unsigned i = 0, e = SSIntervals.size(); i != e; 
++i121k
) {
345
121k
    LiveInterval *li = SSIntervals[i];
346
121k
    int SS = TargetRegisterInfo::stackSlot2Index(li->reg);
347
121k
    li->weight = SlotWeights[SS];
348
121k
  }
349
25.4k
  // Sort them by new weight.
350
25.4k
  llvm::stable_sort(SSIntervals, IntervalSorter());
351
25.4k
352
#ifndef NDEBUG
353
  for (unsigned i = 0, e = SSIntervals.size(); i != e; ++i)
354
    LLVM_DEBUG(SSIntervals[i]->dump());
355
  LLVM_DEBUG(dbgs() << '\n');
356
#endif
357
358
25.4k
  if (!Changed)
359
17.5k
    return false;
360
7.87k
361
7.87k
  // Rewrite all MachineMemOperands.
362
120k
  
for (unsigned SS = 0, SE = SSRefs.size(); 7.87k
SS != SE;
++SS112k
) {
363
112k
    int NewFI = SlotMapping[SS];
364
112k
    if (NewFI == -1 || 
(NewFI == (int)SS)89.4k
)
365
38.8k
      continue;
366
73.9k
367
73.9k
    const PseudoSourceValue *NewSV = MF.getPSVManager().getFixedStack(NewFI);
368
73.9k
    SmallVectorImpl<MachineMemOperand *> &RefMMOs = SSRefs[SS];
369
292k
    for (unsigned i = 0, e = RefMMOs.size(); i != e; 
++i218k
)
370
218k
      RefMMOs[i]->setValue(NewSV);
371
73.9k
  }
372
7.87k
373
7.87k
  // Rewrite all MO_FrameIndex operands.  Look for dead stores.
374
470k
  for (MachineBasicBlock &MBB : MF) {
375
470k
    for (MachineInstr &MI : MBB)
376
3.93M
      RewriteInstruction(MI, SlotMapping, MF);
377
470k
    RemoveDeadStores(&MBB);
378
470k
  }
379
7.87k
380
7.87k
  // Delete unused stack slots.
381
15.7k
  for (int StackID = 0, E = AllColors.size(); StackID != E; 
++StackID7.88k
) {
382
7.88k
    int NextColor = NextColors[StackID];
383
32.3k
    while (NextColor != -1) {
384
24.4k
      LLVM_DEBUG(dbgs() << "Removing unused stack object fi#" << NextColor << "\n");
385
24.4k
      MFI->RemoveStackObject(NextColor);
386
24.4k
      NextColor = AllColors[StackID].find_next(NextColor);
387
24.4k
    }
388
7.88k
  }
389
7.87k
390
7.87k
  return true;
391
7.87k
}
392
393
/// RewriteInstruction - Rewrite specified instruction by replacing references
394
/// to old frame index with new one.
395
void StackSlotColoring::RewriteInstruction(MachineInstr &MI,
396
                                           SmallVectorImpl<int> &SlotMapping,
397
3.93M
                                           MachineFunction &MF) {
398
3.93M
  // Update the operands.
399
17.5M
  for (unsigned i = 0, ee = MI.getNumOperands(); i != ee; 
++i13.6M
) {
400
13.6M
    MachineOperand &MO = MI.getOperand(i);
401
13.6M
    if (!MO.isFI())
402
13.2M
      continue;
403
416k
    int OldFI = MO.getIndex();
404
416k
    if (OldFI < 0)
405
6.91k
      continue;
406
409k
    int NewFI = SlotMapping[OldFI];
407
409k
    if (NewFI == -1 || 
NewFI == OldFI264k
)
408
190k
      continue;
409
219k
410
219k
    assert(MFI->getStackID(OldFI) == MFI->getStackID(NewFI));
411
219k
    MO.setIndex(NewFI);
412
219k
  }
413
3.93M
414
3.93M
  // The MachineMemOperands have already been updated.
415
3.93M
}
416
417
/// RemoveDeadStores - Scan through a basic block and look for loads followed
418
/// by stores.  If they're both using the same stack slot, then the store is
419
/// definitely dead.  This could obviously be much more aggressive (consider
420
/// pairs with instructions between them), but such extensions might have a
421
/// considerable compile time impact.
422
470k
bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
423
470k
  // FIXME: This could be much more aggressive, but we need to investigate
424
470k
  // the compile time impact of doing so.
425
470k
  bool changed = false;
426
470k
427
470k
  SmallVector<MachineInstr*, 4> toErase;
428
470k
429
470k
  for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
430
4.40M
       I != E; 
++I3.93M
) {
431
3.93M
    if (DCELimit != -1 && 
(int)NumDead >= DCELimit0
)
432
0
      break;
433
3.93M
    int FirstSS, SecondSS;
434
3.93M
    if (TII->isStackSlotCopy(*I, FirstSS, SecondSS) && 
FirstSS == SecondSS1
&&
435
3.93M
        
FirstSS != -11
) {
436
1
      ++NumDead;
437
1
      changed = true;
438
1
      toErase.push_back(&*I);
439
1
      continue;
440
1
    }
441
3.93M
442
3.93M
    MachineBasicBlock::iterator NextMI = std::next(I);
443
3.93M
    MachineBasicBlock::iterator ProbableLoadMI = I;
444
3.93M
445
3.93M
    unsigned LoadReg = 0;
446
3.93M
    unsigned StoreReg = 0;
447
3.93M
    unsigned LoadSize = 0;
448
3.93M
    unsigned StoreSize = 0;
449
3.93M
    if (!(LoadReg = TII->isLoadFromStackSlot(*I, FirstSS, LoadSize)))
450
3.76M
      continue;
451
173k
    // Skip the ...pseudo debugging... instructions between a load and store.
452
173k
    while ((NextMI != E) && 
NextMI->isDebugInstr()169k
) {
453
0
      ++NextMI;
454
0
      ++I;
455
0
    }
456
173k
    if (NextMI == E) 
continue4.09k
;
457
169k
    if (!(StoreReg = TII->isStoreToStackSlot(*NextMI, SecondSS, StoreSize)))
458
164k
      continue;
459
4.33k
    if (FirstSS != SecondSS || 
LoadReg != StoreReg75
||
FirstSS == -159
||
460
4.33k
        
LoadSize != StoreSize59
)
461
4.28k
      continue;
462
57
463
57
    ++NumDead;
464
57
    changed = true;
465
57
466
57
    if (NextMI->findRegisterUseOperandIdx(LoadReg, true, nullptr) != -1) {
467
29
      ++NumDead;
468
29
      toErase.push_back(&*ProbableLoadMI);
469
29
    }
470
57
471
57
    toErase.push_back(&*NextMI);
472
57
    ++I;
473
57
  }
474
470k
475
470k
  for (SmallVectorImpl<MachineInstr *>::iterator I = toErase.begin(),
476
470k
       E = toErase.end(); I != E; 
++I87
)
477
87
    (*I)->eraseFromParent();
478
470k
479
470k
  return changed;
480
470k
}
481
482
485k
bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
483
485k
  LLVM_DEBUG({
484
485k
    dbgs() << "********** Stack Slot Coloring **********\n"
485
485k
           << "********** Function: " << MF.getName() << '\n';
486
485k
  });
487
485k
488
485k
  if (skipFunction(MF.getFunction()))
489
250
    return false;
490
485k
491
485k
  MFI = &MF.getFrameInfo();
492
485k
  TII = MF.getSubtarget().getInstrInfo();
493
485k
  LS = &getAnalysis<LiveStacks>();
494
485k
  MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
495
485k
496
485k
  bool Changed = false;
497
485k
498
485k
  unsigned NumSlots = LS->getNumIntervals();
499
485k
  if (NumSlots == 0)
500
459k
    // Nothing to do!
501
459k
    return false;
502
25.4k
503
25.4k
  // If there are calls to setjmp or sigsetjmp, don't perform stack slot
504
25.4k
  // coloring. The stack could be modified before the longjmp is executed,
505
25.4k
  // resulting in the wrong value being used afterwards. (See
506
25.4k
  // <rdar://problem/8007500>.)
507
25.4k
  if (MF.exposesReturnsTwice())
508
6
    return false;
509
25.4k
510
25.4k
  // Gather spill slot references
511
25.4k
  ScanForSpillSlotRefs(MF);
512
25.4k
  InitializeSlots();
513
25.4k
  Changed = ColorSlots(MF);
514
25.4k
515
25.4k
  for (int &Next : NextColors)
516
25.5k
    Next = -1;
517
25.4k
518
25.4k
  SSIntervals.clear();
519
183k
  for (unsigned i = 0, e = SSRefs.size(); i != e; 
++i158k
)
520
158k
    SSRefs[i].clear();
521
25.4k
  SSRefs.clear();
522
25.4k
  OrigAlignments.clear();
523
25.4k
  OrigSizes.clear();
524
25.4k
  AllColors.clear();
525
25.4k
  UsedColors.clear();
526
183k
  for (unsigned i = 0, e = Assignments.size(); i != e; 
++i158k
)
527
158k
    Assignments[i].clear();
528
25.4k
  Assignments.clear();
529
25.4k
530
25.4k
  return Changed;
531
25.4k
}