Teach the register scavenger to take subregs into account when finding a free register.
authorJim Grosbach <grosbach@apple.com>
Sat, 5 Mar 2011 00:20:19 +0000 (00:20 +0000)
committerJim Grosbach <grosbach@apple.com>
Sat, 5 Mar 2011 00:20:19 +0000 (00:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127049 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/RegisterScavenging.h
lib/CodeGen/RegisterScavenging.cpp

index 246831c034d4c5f4781b735b9da6a6105d135eef..26b6773c05304c4e478ff7d51c22ffee412635ea 100644 (file)
@@ -100,7 +100,7 @@ public:
 
   /// getRegsAvailable - Return all available registers in the register class
   /// in Mask.
-  void getRegsAvailable(const TargetRegisterClass *RC, BitVector &Mask);
+  BitVector getRegsAvailable(const TargetRegisterClass *RC);
 
   /// FindUnusedReg - Find a unused register of the specified register class.
   /// Return 0 if none is found.
index a2580b85bcc335b753db48d814c2f72dd5f43f49..b9dd28e5c7841db95e5a1ba215ee40d1612aaea5 100644 (file)
@@ -241,12 +241,13 @@ unsigned RegScavenger::FindUnusedReg(const TargetRegisterClass *RC) const {
 
 /// getRegsAvailable - Return all available registers in the register class
 /// in Mask.
-void RegScavenger::getRegsAvailable(const TargetRegisterClass *RC,
-                                    BitVector &Mask) {
+BitVector RegScavenger::getRegsAvailable(const TargetRegisterClass *RC) {
+  BitVector Mask(TRI->getNumRegs());
   for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
        I != E; ++I)
     if (!isAliasUsed(*I))
       Mask.set(*I);
+  return Mask;
 }
 
 /// findSurvivorReg - Return the candidate register that is unused for the
@@ -335,9 +336,13 @@ unsigned RegScavenger::scavengeRegister(const TargetRegisterClass *RC,
   }
 
   // Try to find a register that's unused if there is one, as then we won't
-  // have to spill.
-  if ((Candidates & RegsAvailable).any())
-     Candidates &= RegsAvailable;
+  // have to spill. Search explicitly rather than masking out based on
+  // RegsAvailable, as RegsAvailable does not take aliases into account.
+  // That's what getRegsAvailable() is for.
+  BitVector Available = getRegsAvailable(RC);
+
+  if ((Candidates & Available).any())
+     Candidates &= Available;
 
   // Find the register whose use is furthest away.
   MachineBasicBlock::iterator UseMI;