@@ -367,7 +367,7 @@ class X86DomainReassignment : public MachineFunctionPass {
367
367
const X86InstrInfo *TII = nullptr ;
368
368
369
369
// / All edges that are included in some closure
370
- BitVector EnclosedEdges{ 8 , false } ;
370
+ DenseMap<Register, unsigned > EnclosedEdges ;
371
371
372
372
// / All instructions that are included in some closure.
373
373
DenseMap<MachineInstr *, unsigned > EnclosedInstrs;
@@ -399,14 +399,16 @@ class X86DomainReassignment : public MachineFunctionPass {
399
399
void buildClosure (Closure &, Register Reg);
400
400
401
401
// / Enqueue \p Reg to be considered for addition to the closure.
402
- void visitRegister (Closure &, Register Reg, RegDomain &Domain,
402
+ // / Return false if the closure becomes invalid.
403
+ bool visitRegister (Closure &, Register Reg, RegDomain &Domain,
403
404
SmallVectorImpl<unsigned > &Worklist);
404
405
405
406
// / Reassign the closure to \p Domain.
406
407
void reassign (const Closure &C, RegDomain Domain) const ;
407
408
408
409
// / Add \p MI to the closure.
409
- void encloseInstr (Closure &C, MachineInstr *MI);
410
+ // / Return false if the closure becomes invalid.
411
+ bool encloseInstr (Closure &C, MachineInstr *MI);
410
412
411
413
// / /returns true if it is profitable to reassign the closure to \p Domain.
412
414
bool isReassignmentProfitable (const Closure &C, RegDomain Domain) const ;
@@ -419,37 +421,46 @@ char X86DomainReassignment::ID = 0;
419
421
420
422
} // End anonymous namespace.
421
423
422
- void X86DomainReassignment::visitRegister (Closure &C, Register Reg,
424
+ bool X86DomainReassignment::visitRegister (Closure &C, Register Reg,
423
425
RegDomain &Domain,
424
426
SmallVectorImpl<unsigned > &Worklist) {
425
427
if (!Reg.isVirtual ())
426
- return ;
428
+ return true ;
427
429
428
- if (EnclosedEdges.test (Register::virtReg2Index (Reg)))
429
- return ;
430
+ auto I = EnclosedEdges.find (Reg);
431
+ if (I != EnclosedEdges.end ()) {
432
+ if (I->second != C.getID ()) {
433
+ C.setAllIllegal ();
434
+ return false ;
435
+ }
436
+ return true ;
437
+ }
430
438
431
439
if (!MRI->hasOneDef (Reg))
432
- return ;
440
+ return true ;
433
441
434
442
RegDomain RD = getDomain (MRI->getRegClass (Reg), MRI->getTargetRegisterInfo ());
435
443
// First edge in closure sets the domain.
436
444
if (Domain == NoDomain)
437
445
Domain = RD;
438
446
439
447
if (Domain != RD)
440
- return ;
448
+ return true ;
441
449
442
450
Worklist.push_back (Reg);
451
+ return true ;
443
452
}
444
453
445
- void X86DomainReassignment::encloseInstr (Closure &C, MachineInstr *MI) {
454
+ bool X86DomainReassignment::encloseInstr (Closure &C, MachineInstr *MI) {
446
455
auto I = EnclosedInstrs.find (MI);
447
456
if (I != EnclosedInstrs.end ()) {
448
- if (I->second != C.getID ())
457
+ if (I->second != C.getID ()) {
449
458
// Instruction already belongs to another closure, avoid conflicts between
450
459
// closure and mark this closure as illegal.
451
460
C.setAllIllegal ();
452
- return ;
461
+ return false ;
462
+ }
463
+ return true ;
453
464
}
454
465
455
466
EnclosedInstrs[MI] = C.getID ();
@@ -465,6 +476,7 @@ void X86DomainReassignment::encloseInstr(Closure &C, MachineInstr *MI) {
465
476
C.setIllegal ((RegDomain)i);
466
477
}
467
478
}
479
+ return C.hasLegalDstDomain ();
468
480
}
469
481
470
482
double X86DomainReassignment::calculateCost (const Closure &C,
@@ -543,10 +555,11 @@ void X86DomainReassignment::buildClosure(Closure &C, Register Reg) {
543
555
// Register already in this closure.
544
556
if (!C.insertEdge (CurReg))
545
557
continue ;
546
- EnclosedEdges. set ( Register::virtReg2Index (Reg) );
558
+ EnclosedEdges[Reg] = C. getID ( );
547
559
548
560
MachineInstr *DefMI = MRI->getVRegDef (CurReg);
549
- encloseInstr (C, DefMI);
561
+ if (!encloseInstr (C, DefMI))
562
+ return ;
550
563
551
564
// Add register used by the defining MI to the worklist.
552
565
// Do not add registers which are used in address calculation, they will be
@@ -565,7 +578,8 @@ void X86DomainReassignment::buildClosure(Closure &C, Register Reg) {
565
578
auto &Op = DefMI->getOperand (OpIdx);
566
579
if (!Op.isReg () || !Op.isUse ())
567
580
continue ;
568
- visitRegister (C, Op.getReg (), Domain, Worklist);
581
+ if (!visitRegister (C, Op.getReg (), Domain, Worklist))
582
+ return ;
569
583
}
570
584
571
585
// Expand closure through register uses.
@@ -574,9 +588,10 @@ void X86DomainReassignment::buildClosure(Closure &C, Register Reg) {
574
588
// as this should remain in GPRs.
575
589
if (usedAsAddr (UseMI, CurReg, TII)) {
576
590
C.setAllIllegal ();
577
- continue ;
591
+ return ;
578
592
}
579
- encloseInstr (C, &UseMI);
593
+ if (!encloseInstr (C, &UseMI))
594
+ return ;
580
595
581
596
for (auto &DefOp : UseMI.defs ()) {
582
597
if (!DefOp.isReg ())
@@ -585,9 +600,10 @@ void X86DomainReassignment::buildClosure(Closure &C, Register Reg) {
585
600
Register DefReg = DefOp.getReg ();
586
601
if (!DefReg.isVirtual ()) {
587
602
C.setAllIllegal ();
588
- continue ;
603
+ return ;
589
604
}
590
- visitRegister (C, DefReg, Domain, Worklist);
605
+ if (!visitRegister (C, DefReg, Domain, Worklist))
606
+ return ;
591
607
}
592
608
}
593
609
}
@@ -775,7 +791,6 @@ bool X86DomainReassignment::runOnMachineFunction(MachineFunction &MF) {
775
791
bool Changed = false ;
776
792
777
793
EnclosedEdges.clear ();
778
- EnclosedEdges.resize (MRI->getNumVirtRegs ());
779
794
EnclosedInstrs.clear ();
780
795
781
796
std::vector<Closure> Closures;
@@ -795,7 +810,7 @@ bool X86DomainReassignment::runOnMachineFunction(MachineFunction &MF) {
795
810
continue ;
796
811
797
812
// Register already in closure.
798
- if (EnclosedEdges.test (Idx ))
813
+ if (EnclosedEdges.contains (Reg ))
799
814
continue ;
800
815
801
816
// Calculate closure starting with Reg.
0 commit comments