[llvm-commits] [llvm] r121306 - /llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Dec 8 14:57:16 PST 2010


Author: stoklund
Date: Wed Dec  8 16:57:16 2010
New Revision: 121306

URL: http://llvm.org/viewvc/llvm-project?rev=121306&view=rev
Log:
Implement very primitive hinting support in RegAllocGreedy.

The hint is simply tried first and then forgotten if it couldn't be allocated
immediately.

Modified:
    llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp

Modified: llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp?rev=121306&r1=121305&r2=121306&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp Wed Dec  8 16:57:16 2010
@@ -70,7 +70,7 @@
 
   virtual Spiller &spiller() { return *SpillerInstance; }
 
-  virtual float getPriority(LiveInterval *LI) { return LI->weight; }
+  virtual float getPriority(LiveInterval *LI);
 
   virtual unsigned selectOrSplit(LiveInterval &VirtReg,
                                  SmallVectorImpl<LiveInterval*> &SplitVRegs);
@@ -126,6 +126,22 @@
   RegAllocBase::releaseMemory();
 }
 
+float RAGreedy::getPriority(LiveInterval *LI) {
+  float Priority = LI->weight;
+
+  // Prioritize hinted registers so they are allocated first.
+  std::pair<unsigned, unsigned> Hint;
+  if (Hint.first || Hint.second) {
+    // The hint can be target specific, a virtual register, or a physreg.
+    Priority *= 2;
+
+    // Prefer physreg hints above anything else.
+    if (Hint.first == 0 && TargetRegisterInfo::isPhysicalRegister(Hint.second))
+      Priority *= 2;
+  }
+  return Priority;
+}
+
 unsigned RAGreedy::selectOrSplit(LiveInterval &VirtReg,
                                 SmallVectorImpl<LiveInterval*> &SplitVRegs) {
   // Populate a list of physical register spill candidates.
@@ -135,6 +151,14 @@
   const TargetRegisterClass *TRC = MRI->getRegClass(VirtReg.reg);
   DEBUG(dbgs() << "RegClass: " << TRC->getName() << ' ');
 
+  // Preferred physical register computed from hints.
+  unsigned Hint = VRM->getRegAllocPref(VirtReg.reg);
+
+  // Try a hinted allocation.
+  if (Hint && !ReservedRegs.test(Hint) && TRC->contains(Hint) &&
+      checkPhysRegInterference(VirtReg, Hint) == 0)
+    return Hint;
+
   for (TargetRegisterClass::iterator I = TRC->allocation_order_begin(*MF),
          E = TRC->allocation_order_end(*MF);
        I != E; ++I) {





More information about the llvm-commits mailing list