Add a version of FindUnusedReg that restrict search to a specific set of registers.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 1 Mar 2007 08:56:24 +0000 (08:56 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 1 Mar 2007 08:56:24 +0000 (08:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34784 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c8e2862f053296608ef5e7c253cd290358e50a7f..733c9e549dd49b0d34ec24a2e6ac2813a889b679 100644 (file)
@@ -78,6 +78,11 @@ public:
   void setUnused(unsigned Reg)   { RegStates.set(Reg); }
   void setUnused(BitVector Regs) { RegStates |= Regs; }
 
+  /// FindUnusedReg - Find a unused register of the specified register class
+  /// from the specified set of registers. It return 0 is none is found.
+  unsigned FindUnusedReg(const TargetRegisterClass *RegClass,
+                         const BitVector &Candidates) const;
+
   /// FindUnusedReg - Find a unused register of the specified register class.
   /// Exclude callee saved registers if directed. It return 0 is none is found.
   unsigned FindUnusedReg(const TargetRegisterClass *RegClass,
index 8f5f4408ac702d45060bf519546883687a1336ac..7efae9ca5c089f816e2ad1fcdee5ea4bb3d3c3b5 100644 (file)
@@ -156,6 +156,21 @@ static void CreateRegClassMask(const TargetRegisterClass *RC, BitVector &Mask) {
     Mask.set(*I);
 }
 
+unsigned RegScavenger::FindUnusedReg(const TargetRegisterClass *RegClass,
+                                     const BitVector &Candidates) const {
+  // Mask off the registers which are not in the TargetRegisterClass.
+  BitVector RegStatesCopy(NumPhysRegs, false);
+  CreateRegClassMask(RegClass, RegStatesCopy);
+  RegStatesCopy &= RegStates;
+
+  // Restrict the search to candidates.
+  RegStatesCopy &= Candidates;
+
+  // Returns the first unused (bit is set) register, or 0 is none is found.
+  int Reg = RegStatesCopy.find_first();
+  return (Reg == -1) ? 0 : Reg;
+}
+
 unsigned RegScavenger::FindUnusedReg(const TargetRegisterClass *RegClass,
                                      bool ExCalleeSaved) const {
   // Mask off the registers which are not in the TargetRegisterClass.