aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-03-01 08:56:24 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-03-01 08:56:24 +0000
commit5196b3680cf8df32b6c763e3d97e963e45150e5a (patch)
tree14b3b8e4b51d71f931e91e8cc37ae6f5a4d1a070
parentf49407b790d8664d8ff9c103931b115ebe9cc96e (diff)
Add a version of FindUnusedReg that restrict search to a specific set of registers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34784 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/RegisterScavenging.h5
-rw-r--r--lib/CodeGen/RegisterScavenging.cpp15
2 files changed, 20 insertions, 0 deletions
diff --git a/include/llvm/CodeGen/RegisterScavenging.h b/include/llvm/CodeGen/RegisterScavenging.h
index c8e2862f05..733c9e549d 100644
--- a/include/llvm/CodeGen/RegisterScavenging.h
+++ b/include/llvm/CodeGen/RegisterScavenging.h
@@ -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,
diff --git a/lib/CodeGen/RegisterScavenging.cpp b/lib/CodeGen/RegisterScavenging.cpp
index 8f5f4408ac..7efae9ca5c 100644
--- a/lib/CodeGen/RegisterScavenging.cpp
+++ b/lib/CodeGen/RegisterScavenging.cpp
@@ -157,6 +157,21 @@ static void CreateRegClassMask(const TargetRegisterClass *RC, BitVector &Mask) {
}
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.
BitVector RegStatesCopy(NumPhysRegs, false);