@@ -2623,6 +2623,55 @@ CodeGenRegBank::getMinimalPhysRegClass(const Record *RegRecord,
2623
2623
return BestRC;
2624
2624
}
2625
2625
2626
+ const CodeGenRegisterClass *
2627
+ CodeGenRegBank::getSuperRegForSubReg (const ValueTypeByHwMode &ValueTy,
2628
+ const CodeGenSubRegIndex *SubIdx,
2629
+ bool MustBeAllocatable) const {
2630
+ std::vector<const CodeGenRegisterClass *> Candidates;
2631
+ auto &RegClasses = getRegClasses ();
2632
+
2633
+ // Try to find a register class which supports ValueTy, and also contains
2634
+ // SubIdx.
2635
+ for (const CodeGenRegisterClass &RC : RegClasses) {
2636
+ // Is there a subclass of this class which contains this subregister index?
2637
+ const CodeGenRegisterClass *SubClassWithSubReg =
2638
+ RC.getSubClassWithSubReg (SubIdx);
2639
+ if (!SubClassWithSubReg)
2640
+ continue ;
2641
+
2642
+ // We have a class. Check if it supports this value type.
2643
+ if (!llvm::is_contained (SubClassWithSubReg->VTs , ValueTy))
2644
+ continue ;
2645
+
2646
+ // If necessary, check that it is allocatable.
2647
+ if (MustBeAllocatable && !SubClassWithSubReg->Allocatable )
2648
+ continue ;
2649
+
2650
+ // We have a register class which supports both the value type and
2651
+ // subregister index. Remember it.
2652
+ Candidates.push_back (SubClassWithSubReg);
2653
+ }
2654
+
2655
+ // If we didn't find anything, we're done.
2656
+ if (Candidates.empty ())
2657
+ return nullptr ;
2658
+
2659
+ // Find and return the largest of our candidate classes.
2660
+ llvm::stable_sort (Candidates, [&](const CodeGenRegisterClass *A,
2661
+ const CodeGenRegisterClass *B) {
2662
+ if (A->getMembers ().size () > B->getMembers ().size ())
2663
+ return true ;
2664
+
2665
+ if (A->getMembers ().size () < B->getMembers ().size ())
2666
+ return false ;
2667
+
2668
+ // Order by name as a tie-breaker.
2669
+ return StringRef (A->getName ()) < B->getName ();
2670
+ });
2671
+
2672
+ return Candidates[0 ];
2673
+ }
2674
+
2626
2675
BitVector
2627
2676
CodeGenRegBank::computeCoveredRegisters (ArrayRef<const Record *> Regs) {
2628
2677
SetVector<const CodeGenRegister *> Set;
0 commit comments