Add a version of FindUnusedReg that restrict search to a specific set of registers.
[oota-llvm.git] / lib / CodeGen / RegisterScavenging.cpp
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.