@@ -67,9 +67,9 @@ void CriticalAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
67
67
for (const MachineBasicBlock *Succ : BB->successors ())
68
68
for (const auto &LI : Succ->liveins ()) {
69
69
for (MCRegAliasIterator AI (LI.PhysReg , TRI, true ); AI.isValid (); ++AI) {
70
- unsigned Reg = ( *AI). id () ;
71
- Classes[Reg] = reinterpret_cast <TargetRegisterClass *>(-1 );
72
- KillIndices[Reg] = BBSize;
70
+ MCRegister Reg = *AI;
71
+ Classes[Reg. id () ] = reinterpret_cast <TargetRegisterClass *>(-1 );
72
+ KillIndices[Reg. id () ] = BBSize;
73
73
DefIndices[Reg] = ~0u ;
74
74
}
75
75
}
@@ -85,10 +85,10 @@ void CriticalAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
85
85
if (!IsReturnBlock && !Pristine.test (Reg))
86
86
continue ;
87
87
for (MCRegAliasIterator AI (*I, TRI, true ); AI.isValid (); ++AI) {
88
- unsigned Reg = ( *AI). id () ;
89
- Classes[Reg] = reinterpret_cast <TargetRegisterClass *>(-1 );
90
- KillIndices[Reg] = BBSize;
91
- DefIndices[Reg] = ~0u ;
88
+ MCRegister Reg = *AI;
89
+ Classes[Reg. id () ] = reinterpret_cast <TargetRegisterClass *>(-1 );
90
+ KillIndices[Reg. id () ] = BBSize;
91
+ DefIndices[Reg. id () ] = ~0u ;
92
92
}
93
93
}
94
94
}
@@ -182,7 +182,8 @@ void CriticalAntiDepBreaker::PrescanInstruction(MachineInstr &MI) {
182
182
MachineOperand &MO = MI.getOperand (i);
183
183
if (!MO.isReg ()) continue ;
184
184
Register Reg = MO.getReg ();
185
- if (Reg == 0 ) continue ;
185
+ if (!Reg)
186
+ continue ;
186
187
const TargetRegisterClass *NewRC = nullptr ;
187
188
188
189
if (i < MI.getDesc ().getNumOperands ())
@@ -278,7 +279,8 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
278
279
279
280
if (!MO.isReg ()) continue ;
280
281
Register Reg = MO.getReg ();
281
- if (Reg == 0 ) continue ;
282
+ if (!Reg)
283
+ continue ;
282
284
if (!MO.isDef ()) continue ;
283
285
284
286
// Ignore two-addr defs.
@@ -308,7 +310,8 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
308
310
MachineOperand &MO = MI.getOperand (i);
309
311
if (!MO.isReg ()) continue ;
310
312
Register Reg = MO.getReg ();
311
- if (Reg == 0 ) continue ;
313
+ if (!Reg)
314
+ continue ;
312
315
if (!MO.isUse ()) continue ;
313
316
314
317
const TargetRegisterClass *NewRC = nullptr ;
@@ -327,10 +330,10 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
327
330
// It wasn't previously live but now it is, this is a kill.
328
331
// Repeat for all aliases.
329
332
for (MCRegAliasIterator AI (Reg, TRI, true ); AI.isValid (); ++AI) {
330
- unsigned AliasReg = ( *AI). id () ;
331
- if (KillIndices[AliasReg] == ~0u ) {
332
- KillIndices[AliasReg] = Count;
333
- DefIndices[AliasReg] = ~0u ;
333
+ MCRegister AliasReg = *AI;
334
+ if (KillIndices[AliasReg. id () ] == ~0u ) {
335
+ KillIndices[AliasReg. id () ] = Count;
336
+ DefIndices[AliasReg. id () ] = ~0u ;
334
337
}
335
338
}
336
339
}
@@ -347,10 +350,9 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
347
350
// RegRefs because the def is inserted by PrescanInstruction and not erased
348
351
// during ScanInstruction. So checking for an instruction with definitions of
349
352
// both NewReg and AntiDepReg covers it.
350
- bool
351
- CriticalAntiDepBreaker::isNewRegClobberedByRefs (RegRefIter RegRefBegin,
352
- RegRefIter RegRefEnd,
353
- unsigned NewReg) {
353
+ bool CriticalAntiDepBreaker::isNewRegClobberedByRefs (RegRefIter RegRefBegin,
354
+ RegRefIter RegRefEnd,
355
+ MCRegister NewReg) {
354
356
for (RegRefIter I = RegRefBegin; I != RegRefEnd; ++I ) {
355
357
MachineOperand *RefOper = I->second ;
356
358
@@ -389,15 +391,12 @@ CriticalAntiDepBreaker::isNewRegClobberedByRefs(RegRefIter RegRefBegin,
389
391
return false ;
390
392
}
391
393
392
- unsigned CriticalAntiDepBreaker::
393
- findSuitableFreeRegister (RegRefIter RegRefBegin,
394
- RegRefIter RegRefEnd,
395
- unsigned AntiDepReg,
396
- unsigned LastNewReg,
397
- const TargetRegisterClass *RC,
398
- SmallVectorImpl<unsigned > &Forbid) {
394
+ MCRegister CriticalAntiDepBreaker::findSuitableFreeRegister (
395
+ RegRefIter RegRefBegin, RegRefIter RegRefEnd, MCRegister AntiDepReg,
396
+ MCRegister LastNewReg, const TargetRegisterClass *RC,
397
+ const SmallVectorImpl<Register> &Forbid) {
399
398
ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder (RC);
400
- for (unsigned NewReg : Order) {
399
+ for (MCRegister NewReg : Order) {
401
400
// Don't replace a register with itself.
402
401
if (NewReg == AntiDepReg) continue ;
403
402
// Don't replace a register with one that was recently used to repair
@@ -410,17 +409,18 @@ findSuitableFreeRegister(RegRefIter RegRefBegin,
410
409
if (isNewRegClobberedByRefs (RegRefBegin, RegRefEnd, NewReg)) continue ;
411
410
// If NewReg is dead and NewReg's most recent def is not before
412
411
// AntiDepReg's kill, it's safe to replace AntiDepReg with NewReg.
413
- assert (((KillIndices[AntiDepReg] == ~0u ) != (DefIndices[AntiDepReg] == ~0u ))
414
- && " Kill and Def maps aren't consistent for AntiDepReg!" );
412
+ assert (((KillIndices[AntiDepReg.id ()] == ~0u ) !=
413
+ (DefIndices[AntiDepReg.id ()] == ~0u )) &&
414
+ " Kill and Def maps aren't consistent for AntiDepReg!" );
415
415
assert (((KillIndices[NewReg] == ~0u ) != (DefIndices[NewReg] == ~0u ))
416
416
&& " Kill and Def maps aren't consistent for NewReg!" );
417
417
if (KillIndices[NewReg] != ~0u ||
418
418
Classes[NewReg] == reinterpret_cast <TargetRegisterClass *>(-1 ) ||
419
- KillIndices[AntiDepReg] > DefIndices[NewReg])
419
+ KillIndices[AntiDepReg. id () ] > DefIndices[NewReg])
420
420
continue ;
421
421
// If NewReg overlaps any of the forbidden registers, we can't use it.
422
422
bool Forbidden = false ;
423
- for (unsigned R : Forbid)
423
+ for (Register R : Forbid)
424
424
if (TRI->regsOverlap (NewReg, R)) {
425
425
Forbidden = true ;
426
426
break ;
@@ -430,7 +430,7 @@ findSuitableFreeRegister(RegRefIter RegRefBegin,
430
430
}
431
431
432
432
// No registers are free and available!
433
- return 0 ;
433
+ return MCRegister () ;
434
434
}
435
435
436
436
unsigned CriticalAntiDepBreaker::
@@ -517,7 +517,7 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
517
517
// fix that remaining critical edge too. This is a little more involved,
518
518
// because unlike the most recent register, less recent registers should
519
519
// still be considered, though only if no other registers are available.
520
- std::vector<unsigned > LastNewReg (TRI->getNumRegs (), 0 );
520
+ std::vector<MCRegister > LastNewReg (TRI->getNumRegs (), MCRegister () );
521
521
522
522
// Attempt to break anti-dependence edges on the critical path. Walk the
523
523
// instructions from the bottom up, tracking information about liveness
@@ -549,22 +549,22 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
549
549
// anti-dependencies. The current code here only knows how to break one
550
550
// edge per instruction. Note that we'd have to be able to break all of
551
551
// the anti-dependencies in an instruction in order to be effective.
552
- unsigned AntiDepReg = 0 ;
552
+ MCRegister AntiDepReg;
553
553
if (&MI == CriticalPathMI) {
554
554
if (const SDep *Edge = CriticalPathStep (CriticalPathSU)) {
555
555
const SUnit *NextSU = Edge->getSUnit ();
556
556
557
557
// Only consider anti-dependence edges.
558
558
if (Edge->getKind () == SDep::Anti) {
559
- AntiDepReg = Edge->getReg ();
560
- assert (AntiDepReg != 0 && " Anti-dependence on reg0?" );
559
+ AntiDepReg = Edge->getReg (). asMCReg () ;
560
+ assert (AntiDepReg && " Anti-dependence on reg0?" );
561
561
if (!MRI.isAllocatable (AntiDepReg))
562
562
// Don't break anti-dependencies on non-allocatable registers.
563
- AntiDepReg = 0 ;
564
- else if (KeepRegs.test (AntiDepReg))
563
+ AntiDepReg = MCRegister () ;
564
+ else if (KeepRegs.test (AntiDepReg. id () ))
565
565
// Don't break anti-dependencies if a use down below requires
566
566
// this exact register.
567
- AntiDepReg = 0 ;
567
+ AntiDepReg = MCRegister () ;
568
568
else {
569
569
// If the SUnit has other dependencies on the SUnit that it
570
570
// anti-depends on, don't bother breaking the anti-dependency
@@ -579,7 +579,7 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
579
579
? (P.getKind () != SDep::Anti || P.getReg () != AntiDepReg)
580
580
: (P.getKind () == SDep::Data &&
581
581
P.getReg () == AntiDepReg)) {
582
- AntiDepReg = 0 ;
582
+ AntiDepReg = MCRegister () ;
583
583
break ;
584
584
}
585
585
}
@@ -595,15 +595,15 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
595
595
596
596
PrescanInstruction (MI);
597
597
598
- SmallVector<unsigned , 2 > ForbidRegs;
598
+ SmallVector<Register , 2 > ForbidRegs;
599
599
600
600
// If MI's defs have a special allocation requirement, don't allow
601
601
// any def registers to be changed. Also assume all registers
602
602
// defined in a call must not be changed (ABI).
603
603
if (MI.isCall () || MI.hasExtraDefRegAllocReq () || TII->isPredicated (MI))
604
604
// If this instruction's defs have special allocation requirement, don't
605
605
// break this anti-dependency.
606
- AntiDepReg = 0 ;
606
+ AntiDepReg = MCRegister () ;
607
607
else if (AntiDepReg) {
608
608
// If this instruction has a use of AntiDepReg, breaking it
609
609
// is invalid. If the instruction defines other registers,
@@ -612,9 +612,10 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
612
612
for (const MachineOperand &MO : MI.operands ()) {
613
613
if (!MO.isReg ()) continue ;
614
614
Register Reg = MO.getReg ();
615
- if (Reg == 0 ) continue ;
615
+ if (!Reg)
616
+ continue ;
616
617
if (MO.isUse () && TRI->regsOverlap (AntiDepReg, Reg)) {
617
- AntiDepReg = 0 ;
618
+ AntiDepReg = MCRegister () ;
618
619
break ;
619
620
}
620
621
if (MO.isDef () && Reg != AntiDepReg)
@@ -624,34 +625,35 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
624
625
625
626
// Determine AntiDepReg's register class, if it is live and is
626
627
// consistently used within a single class.
627
- const TargetRegisterClass *RC = AntiDepReg != 0 ? Classes[AntiDepReg]
628
- : nullptr ;
629
- assert ((AntiDepReg == 0 || RC != nullptr ) &&
628
+ const TargetRegisterClass *RC =
629
+ AntiDepReg ? Classes[AntiDepReg. id ()] : nullptr ;
630
+ assert ((! AntiDepReg || RC != nullptr ) &&
630
631
" Register should be live if it's causing an anti-dependence!" );
631
632
if (RC == reinterpret_cast <TargetRegisterClass *>(-1 ))
632
- AntiDepReg = 0 ;
633
+ AntiDepReg = MCRegister () ;
633
634
634
635
// Look for a suitable register to use to break the anti-dependence.
635
636
//
636
637
// TODO: Instead of picking the first free register, consider which might
637
638
// be the best.
638
- if (AntiDepReg != 0 ) {
639
- std::pair<std::multimap<unsigned , MachineOperand *>::iterator,
640
- std::multimap<unsigned , MachineOperand *>::iterator>
641
- Range = RegRefs.equal_range (AntiDepReg);
642
- if (unsigned NewReg = findSuitableFreeRegister (Range.first , Range.second ,
643
- AntiDepReg,
644
- LastNewReg[AntiDepReg],
645
- RC, ForbidRegs)) {
639
+ if (AntiDepReg) {
640
+ std::pair<std::multimap<MCRegister, MachineOperand *>::iterator,
641
+ std::multimap<MCRegister, MachineOperand *>::iterator>
642
+ Range = RegRefs.equal_range (AntiDepReg);
643
+ if (MCRegister NewReg = findSuitableFreeRegister (
644
+ Range.first , Range.second , AntiDepReg, LastNewReg[AntiDepReg], RC,
645
+ ForbidRegs)) {
646
646
LLVM_DEBUG (dbgs () << " Breaking anti-dependence edge on "
647
647
<< printReg (AntiDepReg, TRI) << " with "
648
648
<< RegRefs.count (AntiDepReg) << " references"
649
649
<< " using " << printReg (NewReg, TRI) << " !\n " );
650
650
651
651
// Update the references to the old register to refer to the new
652
652
// register.
653
- for (std::multimap<unsigned , MachineOperand *>::iterator
654
- Q = Range.first , QE = Range.second ; Q != QE; ++Q) {
653
+ for (std::multimap<MCRegister, MachineOperand *>::iterator
654
+ Q = Range.first ,
655
+ QE = Range.second ;
656
+ Q != QE; ++Q) {
655
657
Q->second ->setReg (NewReg);
656
658
// If the SU for the instruction being updated has debug information
657
659
// related to the anti-dependency register, make sure to update that
@@ -665,22 +667,22 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
665
667
// We just went back in time and modified history; the
666
668
// liveness information for the anti-dependence reg is now
667
669
// inconsistent. Set the state as if it were dead.
668
- Classes[NewReg] = Classes[AntiDepReg];
669
- DefIndices[NewReg] = DefIndices[AntiDepReg];
670
- KillIndices[NewReg] = KillIndices[AntiDepReg];
671
- assert (((KillIndices[NewReg] == ~0u ) !=
672
- (DefIndices[NewReg] == ~0u )) &&
673
- " Kill and Def maps aren't consistent for NewReg!" );
674
-
675
- Classes[AntiDepReg] = nullptr ;
676
- DefIndices[AntiDepReg] = KillIndices[AntiDepReg];
677
- KillIndices[AntiDepReg] = ~0u ;
678
- assert (((KillIndices[AntiDepReg] == ~0u ) !=
679
- (DefIndices[AntiDepReg] == ~0u )) &&
680
- " Kill and Def maps aren't consistent for AntiDepReg!" );
670
+ Classes[NewReg. id () ] = Classes[AntiDepReg. id () ];
671
+ DefIndices[NewReg. id () ] = DefIndices[AntiDepReg. id () ];
672
+ KillIndices[NewReg. id () ] = KillIndices[AntiDepReg. id () ];
673
+ assert (((KillIndices[NewReg. id () ] == ~0u ) !=
674
+ (DefIndices[NewReg. id () ] == ~0u )) &&
675
+ " Kill and Def maps aren't consistent for NewReg!" );
676
+
677
+ Classes[AntiDepReg. id () ] = nullptr ;
678
+ DefIndices[AntiDepReg. id () ] = KillIndices[AntiDepReg. id () ];
679
+ KillIndices[AntiDepReg. id () ] = ~0u ;
680
+ assert (((KillIndices[AntiDepReg. id () ] == ~0u ) !=
681
+ (DefIndices[AntiDepReg. id () ] == ~0u )) &&
682
+ " Kill and Def maps aren't consistent for AntiDepReg!" );
681
683
682
684
RegRefs.erase (AntiDepReg);
683
- LastNewReg[AntiDepReg] = NewReg;
685
+ LastNewReg[AntiDepReg. id () ] = NewReg;
684
686
++Broken;
685
687
}
686
688
}
0 commit comments