Move register allocation preference (or hint) from LiveInterval to MachineRegisterInfo. This allows more passes to set them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73346 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp
index 29637b9..87d75dd 100644
--- a/lib/CodeGen/VirtRegMap.cpp
+++ b/lib/CodeGen/VirtRegMap.cpp
@@ -51,6 +51,7 @@
 X("virtregmap", "Virtual Register Map");
 
 bool VirtRegMap::runOnMachineFunction(MachineFunction &mf) {
+  MRI = &mf.getRegInfo();
   TII = mf.getTarget().getInstrInfo();
   TRI = mf.getTarget().getRegisterInfo();
   MF = &mf;
@@ -98,6 +99,39 @@
   ImplicitDefed.resize(LastVirtReg-TargetRegisterInfo::FirstVirtualRegister+1);
 }
 
+unsigned VirtRegMap::getRegAllocPref(unsigned virtReg) {
+  std::pair<MachineRegisterInfo::RegAllocHintType, unsigned> Hint =
+    MRI->getRegAllocationHint(virtReg);
+  switch (Hint.first) {
+  default: assert(0);
+  case MachineRegisterInfo::RA_None:
+    return 0;
+  case MachineRegisterInfo::RA_Preference:
+    if (TargetRegisterInfo::isPhysicalRegister(Hint.second))
+      return Hint.second;
+    if (hasPhys(Hint.second))
+      return getPhys(Hint.second);
+  case MachineRegisterInfo::RA_PairEven: {
+    unsigned physReg = Hint.second;
+    if (TargetRegisterInfo::isPhysicalRegister(physReg))
+      return TRI->getRegisterPairEven(*MF, physReg);
+    else if (hasPhys(physReg))
+      return TRI->getRegisterPairEven(*MF, getPhys(physReg));
+    return 0;
+  }
+  case MachineRegisterInfo::RA_PairOdd: {
+    unsigned physReg = Hint.second;
+    if (TargetRegisterInfo::isPhysicalRegister(physReg))
+      return TRI->getRegisterPairOdd(*MF, physReg);
+    else if (hasPhys(physReg))
+      return TRI->getRegisterPairOdd(*MF, getPhys(physReg));
+    return 0;
+  }
+  }
+  // Shouldn't reach here.
+  return 0;
+}
+
 int VirtRegMap::assignVirt2StackSlot(unsigned virtReg) {
   assert(TargetRegisterInfo::isVirtualRegister(virtReg));
   assert(Virt2StackSlotMap[virtReg] == NO_STACK_SLOT &&
@@ -213,8 +247,7 @@
 
 /// FindUnusedRegisters - Gather a list of allocatable registers that
 /// have not been allocated to any virtual register.
-bool VirtRegMap::FindUnusedRegisters(const TargetRegisterInfo *TRI,
-                                     LiveIntervals* LIs) {
+bool VirtRegMap::FindUnusedRegisters(LiveIntervals* LIs) {
   unsigned NumRegs = TRI->getNumRegs();
   UnusedRegs.reset();
   UnusedRegs.resize(NumRegs);