Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit cede038

Browse files
committed
Avoid extra DenseMap lookups in StackColoring::calculateLocalLiveness.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175487 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8a20844 commit cede038

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

lib/CodeGen/StackColoring.cpp

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -316,30 +316,44 @@ void StackColoring::calculateLocalLiveness() {
316316
MachineBasicBlock *BB = *PI;
317317
if (!BBSet.count(BB)) continue;
318318

319+
// Use an iterator to avoid repeated lookups.
320+
DenseMap<MachineBasicBlock*, BlockLifetimeInfo>::iterator BI =
321+
BlockLiveness.find(BB);
322+
assert(BI != BlockLiveness.end() && "Block not found");
323+
BlockLifetimeInfo &BlockInfo = BI->second;
324+
319325
BitVector LocalLiveIn;
320326
BitVector LocalLiveOut;
321327

322328
// Forward propagation from begins to ends.
323-
for (MachineBasicBlock::pred_iterator PI = BB->pred_begin(),
324-
PE = BB->pred_end(); PI != PE; ++PI)
325-
LocalLiveIn |= BlockLiveness[*PI].LiveOut;
326-
LocalLiveIn |= BlockLiveness[BB].End;
327-
LocalLiveIn.reset(BlockLiveness[BB].Begin);
329+
for (MachineBasicBlock::const_pred_iterator PI = BB->pred_begin(),
330+
PE = BB->pred_end(); PI != PE; ++PI) {
331+
DenseMap<MachineBasicBlock*, BlockLifetimeInfo>::const_iterator I =
332+
BlockLiveness.find(*PI);
333+
assert(I != BlockLiveness.end() && "Predecessor not found");
334+
LocalLiveIn |= I->second.LiveOut;
335+
}
336+
LocalLiveIn |= BlockInfo.End;
337+
LocalLiveIn.reset(BlockInfo.Begin);
328338

329339
// Reverse propagation from ends to begins.
330-
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
331-
SE = BB->succ_end(); SI != SE; ++SI)
332-
LocalLiveOut |= BlockLiveness[*SI].LiveIn;
333-
LocalLiveOut |= BlockLiveness[BB].Begin;
334-
LocalLiveOut.reset(BlockLiveness[BB].End);
340+
for (MachineBasicBlock::const_succ_iterator SI = BB->succ_begin(),
341+
SE = BB->succ_end(); SI != SE; ++SI) {
342+
DenseMap<MachineBasicBlock*, BlockLifetimeInfo>::const_iterator I =
343+
BlockLiveness.find(*SI);
344+
assert(I != BlockLiveness.end() && "Successor not found");
345+
LocalLiveOut |= I->second.LiveIn;
346+
}
347+
LocalLiveOut |= BlockInfo.Begin;
348+
LocalLiveOut.reset(BlockInfo.End);
335349

336350
LocalLiveIn |= LocalLiveOut;
337351
LocalLiveOut |= LocalLiveIn;
338352

339353
// After adopting the live bits, we need to turn-off the bits which
340354
// are de-activated in this block.
341-
LocalLiveOut.reset(BlockLiveness[BB].End);
342-
LocalLiveIn.reset(BlockLiveness[BB].Begin);
355+
LocalLiveOut.reset(BlockInfo.End);
356+
LocalLiveIn.reset(BlockInfo.Begin);
343357

344358
// If we have both BEGIN and END markers in the same basic block then
345359
// we know that the BEGIN marker comes after the END, because we already
@@ -348,23 +362,23 @@ void StackColoring::calculateLocalLiveness() {
348362
// Want to enable the LIVE_IN and LIVE_OUT of slots that have both
349363
// BEGIN and END because it means that the value lives before and after
350364
// this basic block.
351-
BitVector LocalEndBegin = BlockLiveness[BB].End;
352-
LocalEndBegin &= BlockLiveness[BB].Begin;
365+
BitVector LocalEndBegin = BlockInfo.End;
366+
LocalEndBegin &= BlockInfo.Begin;
353367
LocalLiveIn |= LocalEndBegin;
354368
LocalLiveOut |= LocalEndBegin;
355369

356-
if (LocalLiveIn.test(BlockLiveness[BB].LiveIn)) {
370+
if (LocalLiveIn.test(BlockInfo.LiveIn)) {
357371
changed = true;
358-
BlockLiveness[BB].LiveIn |= LocalLiveIn;
372+
BlockInfo.LiveIn |= LocalLiveIn;
359373

360374
for (MachineBasicBlock::pred_iterator PI = BB->pred_begin(),
361375
PE = BB->pred_end(); PI != PE; ++PI)
362376
NextBBSet.insert(*PI);
363377
}
364378

365-
if (LocalLiveOut.test(BlockLiveness[BB].LiveOut)) {
379+
if (LocalLiveOut.test(BlockInfo.LiveOut)) {
366380
changed = true;
367-
BlockLiveness[BB].LiveOut |= LocalLiveOut;
381+
BlockInfo.LiveOut |= LocalLiveOut;
368382

369383
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
370384
SE = BB->succ_end(); SI != SE; ++SI)

0 commit comments

Comments
 (0)