@@ -580,14 +580,47 @@ NodeAddr<BlockNode*> FuncNode::getEntryBlock(const DataFlowGraph &G) {
580
580
581
581
// Register aliasing information.
582
582
//
583
- // In theory, the lane information could be used to determine register
584
- // covering (and aliasing), but depending on the sub-register structure,
585
- // the lane mask information may be missing. The covering information
586
- // must be available for this framework to work, so relying solely on
587
- // the lane data is not sufficient.
583
+
584
+ LaneBitmask RegisterAliasInfo::getLaneMask (RegisterRef RR,
585
+ const DataFlowGraph &DFG) const {
586
+ assert (TargetRegisterInfo::isPhysicalRegister (RR.Reg ));
587
+ const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass (RR.Reg );
588
+ return (RR.Sub != 0 ) ? DFG.getLaneMaskForIndex (RR.Sub ) : RC->LaneMask ;
589
+ }
590
+
591
+ RegisterAliasInfo::CommonRegister::CommonRegister (
592
+ unsigned RegA, LaneBitmask LA, unsigned RegB, LaneBitmask LB,
593
+ const TargetRegisterInfo &TRI) {
594
+ if (RegA == RegB) {
595
+ SuperReg = RegA;
596
+ MaskA = LA;
597
+ MaskB = LB;
598
+ return ;
599
+ }
600
+
601
+ // Find a common super-register.
602
+ SuperReg = 0 ;
603
+ for (MCSuperRegIterator SA (RegA, &TRI, true ); SA.isValid (); ++SA) {
604
+ if (!TRI.isSubRegisterEq (*SA, RegB))
605
+ continue ;
606
+ SuperReg = *SA;
607
+ break ;
608
+ }
609
+ if (SuperReg == 0 )
610
+ return ;
611
+
612
+ if (unsigned SubA = TRI.getSubRegIndex (SuperReg, RegA))
613
+ LA = TRI.composeSubRegIndexLaneMask (SubA, LA);
614
+ if (unsigned SubB = TRI.getSubRegIndex (SuperReg, RegB))
615
+ LB = TRI.composeSubRegIndexLaneMask (SubB, LB);
616
+
617
+ MaskA = LA;
618
+ MaskB = LB;
619
+ }
588
620
589
621
// Determine whether RA covers RB.
590
- bool RegisterAliasInfo::covers (RegisterRef RA, RegisterRef RB) const {
622
+ bool RegisterAliasInfo::covers (RegisterRef RA, RegisterRef RB,
623
+ const DataFlowGraph &DFG) const {
591
624
if (RA == RB)
592
625
return true ;
593
626
if (TargetRegisterInfo::isVirtualRegister (RA.Reg )) {
@@ -601,13 +634,17 @@ bool RegisterAliasInfo::covers(RegisterRef RA, RegisterRef RB) const {
601
634
602
635
assert (TargetRegisterInfo::isPhysicalRegister (RA.Reg ) &&
603
636
TargetRegisterInfo::isPhysicalRegister (RB.Reg ));
604
- uint32_t A = RA.Sub != 0 ? TRI.getSubReg (RA.Reg , RA.Sub ) : RA.Reg ;
605
- uint32_t B = RB.Sub != 0 ? TRI.getSubReg (RB.Reg , RB.Sub ) : RB.Reg ;
606
- return TRI.isSubRegister (A, B);
637
+
638
+ CommonRegister CR (RA.Reg , getLaneMask (RA, DFG),
639
+ RB.Reg , getLaneMask (RB, DFG), TRI);
640
+ if (CR.SuperReg == 0 )
641
+ return false ;
642
+ return (CR.MaskA & CR.MaskB ) == CR.MaskB ;
607
643
}
608
644
609
645
// Determine whether RR is covered by the set of references RRs.
610
- bool RegisterAliasInfo::covers (const RegisterSet &RRs, RegisterRef RR) const {
646
+ bool RegisterAliasInfo::covers (const RegisterSet &RRs, RegisterRef RR,
647
+ const DataFlowGraph &DFG) const {
611
648
if (RRs.count (RR))
612
649
return true ;
613
650
@@ -630,7 +667,7 @@ bool RegisterAliasInfo::covers(const RegisterSet &RRs, RegisterRef RR) const {
630
667
return false ;
631
668
}
632
669
633
- // Get the list of references aliased to RR.
670
+ // Get the list of references aliased to RR. Lane masks are ignored.
634
671
std::vector<RegisterRef> RegisterAliasInfo::getAliasSet (RegisterRef RR) const {
635
672
// Do not include RR in the alias set. For virtual registers return an
636
673
// empty set.
@@ -648,16 +685,17 @@ std::vector<RegisterRef> RegisterAliasInfo::getAliasSet(RegisterRef RR) const {
648
685
}
649
686
650
687
// Check whether RA and RB are aliased.
651
- bool RegisterAliasInfo::alias (RegisterRef RA, RegisterRef RB) const {
652
- bool VirtA = TargetRegisterInfo::isVirtualRegister (RA.Reg );
653
- bool VirtB = TargetRegisterInfo::isVirtualRegister (RB.Reg );
654
- bool PhysA = TargetRegisterInfo::isPhysicalRegister (RA.Reg );
655
- bool PhysB = TargetRegisterInfo::isPhysicalRegister (RB.Reg );
656
-
657
- if (VirtA != VirtB)
688
+ bool RegisterAliasInfo::alias (RegisterRef RA, RegisterRef RB,
689
+ const DataFlowGraph &DFG) const {
690
+ bool IsVirtA = TargetRegisterInfo::isVirtualRegister (RA.Reg );
691
+ bool IsVirtB = TargetRegisterInfo::isVirtualRegister (RB.Reg );
692
+ bool IsPhysA = TargetRegisterInfo::isPhysicalRegister (RA.Reg );
693
+ bool IsPhysB = TargetRegisterInfo::isPhysicalRegister (RB.Reg );
694
+
695
+ if (IsVirtA != IsVirtB)
658
696
return false ;
659
697
660
- if (VirtA ) {
698
+ if (IsVirtA ) {
661
699
if (RA.Reg != RB.Reg )
662
700
return false ;
663
701
// RA and RB refer to the same register. If any of them refer to the
@@ -675,14 +713,14 @@ bool RegisterAliasInfo::alias(RegisterRef RA, RegisterRef RB) const {
675
713
return false ;
676
714
}
677
715
678
- assert (PhysA && PhysB );
679
- (void )PhysA , (void )PhysB ;
680
- uint32_t A = RA. Sub ? TRI. getSubReg (RA. Reg , RA. Sub ) : RA. Reg ;
681
- uint32_t B = RB. Sub ? TRI. getSubReg (RB .Reg , RB. Sub ) : RB. Reg ;
682
- for (MCRegAliasIterator I (A, &TRI, true ); I. isValid (); ++I)
683
- if (B == *I )
684
- return true ;
685
- return false ;
716
+ assert (IsPhysA && IsPhysB );
717
+ (void )IsPhysA , (void )IsPhysB ;
718
+
719
+ CommonRegister CR (RA .Reg , getLaneMask (RA, DFG),
720
+ RB. Reg , getLaneMask (RB, DFG), TRI);
721
+ if (CR. SuperReg == 0 )
722
+ return false ;
723
+ return (CR. MaskA & CR. MaskB ) != 0 ;
686
724
}
687
725
688
726
@@ -1213,7 +1251,7 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
1213
1251
if (!UseOp.isReg () || !UseOp.isUse () || UseOp.isUndef ())
1214
1252
continue ;
1215
1253
RegisterRef UR = { UseOp.getReg (), UseOp.getSubReg () };
1216
- if (RAI.alias (DR, UR))
1254
+ if (RAI.alias (DR, UR, * this ))
1217
1255
return false ;
1218
1256
}
1219
1257
return true ;
@@ -1398,7 +1436,7 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, BlockRefsMap &RefM,
1398
1436
1399
1437
auto MaxCoverIn = [this ] (RegisterRef RR, RegisterSet &RRs) -> RegisterRef {
1400
1438
for (auto I : RRs)
1401
- if (I != RR && RAI.covers (I, RR))
1439
+ if (I != RR && RAI.covers (I, RR, * this ))
1402
1440
RR = I;
1403
1441
return RR;
1404
1442
};
@@ -1425,7 +1463,7 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, BlockRefsMap &RefM,
1425
1463
auto Aliased = [this ,&MaxRefs](RegisterRef RR,
1426
1464
std::vector<unsigned > &Closure) -> bool {
1427
1465
for (auto I : Closure)
1428
- if (RAI.alias (RR, MaxRefs[I]))
1466
+ if (RAI.alias (RR, MaxRefs[I], * this ))
1429
1467
return true ;
1430
1468
return false ;
1431
1469
};
@@ -1544,9 +1582,9 @@ void DataFlowGraph::linkRefUp(NodeAddr<InstrNode*> IA, NodeAddr<T> TA,
1544
1582
for (auto I = DS.top (), E = DS.bottom (); I != E; I.down ()) {
1545
1583
RegisterRef QR = I->Addr ->getRegRef ();
1546
1584
auto AliasQR = [QR,this ] (RegisterRef RR) -> bool {
1547
- return RAI.alias (QR, RR);
1585
+ return RAI.alias (QR, RR, * this );
1548
1586
};
1549
- bool PrecUp = RAI.covers (QR, RR);
1587
+ bool PrecUp = RAI.covers (QR, RR, * this );
1550
1588
// Skip all defs that are aliased to any of the defs that we have already
1551
1589
// seen. If we encounter a covering def, stop the stack traversal early.
1552
1590
if (any_of (Defs, AliasQR)) {
0 commit comments