From 3ad8ab7b61332ca76967ce9f100ab2694d39530f Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Mon, 26 Mar 2007 22:23:54 +0000 Subject: [PATCH] Fix reversed logic in getRegsUsed. Rename RegStates to RegsAvailable to hopefully forestall similar errors. llvm-svn: 35362 --- include/llvm/CodeGen/RegisterScavenging.h | 16 ++++++------ lib/CodeGen/RegisterScavenging.cpp | 30 +++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/llvm/CodeGen/RegisterScavenging.h b/include/llvm/CodeGen/RegisterScavenging.h index f66cf156e6c..6c717bb2ddc 100644 --- a/include/llvm/CodeGen/RegisterScavenging.h +++ b/include/llvm/CodeGen/RegisterScavenging.h @@ -47,10 +47,10 @@ class RegScavenger { /// const TargetRegisterClass *ScavengedRC; - /// RegStates - The current state of all the physical registers immediately + /// RegsAvailable - The current state of all the physical registers immediately /// before MBBI. One bit per physical register. If bit is set that means it's /// available, unset means the register is currently being used. - BitVector RegStates; + BitVector RegsAvailable; public: RegScavenger() @@ -88,18 +88,18 @@ public: /// isUsed / isUsed - Test if a register is currently being used. /// - bool isUsed(unsigned Reg) const { return !RegStates[Reg]; } - bool isUnused(unsigned Reg) const { return RegStates[Reg]; } + bool isUsed(unsigned Reg) const { return !RegsAvailable[Reg]; } + bool isUnused(unsigned Reg) const { return RegsAvailable[Reg]; } /// getRegsUsed - return all registers currently in use in used. void getRegsUsed(BitVector &used, bool includeReserved); /// setUsed / setUnused - Mark the state of one or a number of registers. /// - void setUsed(unsigned Reg) { RegStates.reset(Reg); } - void setUsed(BitVector Regs) { RegStates &= ~Regs; } - void setUnused(unsigned Reg) { RegStates.set(Reg); } - void setUnused(BitVector Regs) { RegStates |= Regs; } + void setUsed(unsigned Reg) { RegsAvailable.reset(Reg); } + void setUsed(BitVector Regs) { RegsAvailable &= ~Regs; } + void setUnused(unsigned Reg) { RegsAvailable.set(Reg); } + void setUnused(BitVector Regs) { RegsAvailable |= Regs; } /// FindUnusedReg - Find a unused register of the specified register class /// from the specified set of registers. It return 0 is none is found. diff --git a/lib/CodeGen/RegisterScavenging.cpp b/lib/CodeGen/RegisterScavenging.cpp index e5729abdf49..06368639b8c 100644 --- a/lib/CodeGen/RegisterScavenging.cpp +++ b/lib/CodeGen/RegisterScavenging.cpp @@ -36,7 +36,7 @@ void RegScavenger::enterBasicBlock(MachineBasicBlock *mbb) { if (!MBB) { NumPhysRegs = RegInfo->getNumRegs(); - RegStates.resize(NumPhysRegs); + RegsAvailable.resize(NumPhysRegs); // Create reserved registers bitvector. ReservedRegs = RegInfo->getReservedRegs(MF); @@ -54,10 +54,10 @@ void RegScavenger::enterBasicBlock(MachineBasicBlock *mbb) { ScavengedRC = NULL; // All registers started out unused. - RegStates.set(); + RegsAvailable.set(); // Reserved registers are always used. - RegStates ^= ReservedRegs; + RegsAvailable ^= ReservedRegs; // Live-in registers are in use. if (!MBB->livein_empty()) @@ -182,9 +182,9 @@ void RegScavenger::backward() { void RegScavenger::getRegsUsed(BitVector &used, bool includeReserved) { if (includeReserved) - used = RegStates; + used = ~RegsAvailable; else - used = RegStates & ~ReservedRegs; + used = ~RegsAvailable & ~ReservedRegs; } /// CreateRegClassMask - Set the bits that represent the registers in the @@ -198,32 +198,32 @@ 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; + BitVector RegsAvailableCopy(NumPhysRegs, false); + CreateRegClassMask(RegClass, RegsAvailableCopy); + RegsAvailableCopy &= RegsAvailable; // Restrict the search to candidates. - RegStatesCopy &= Candidates; + RegsAvailableCopy &= Candidates; // Returns the first unused (bit is set) register, or 0 is none is found. - int Reg = RegStatesCopy.find_first(); + int Reg = RegsAvailableCopy.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); - CreateRegClassMask(RegClass, RegStatesCopy); - RegStatesCopy &= RegStates; + BitVector RegsAvailableCopy(NumPhysRegs, false); + CreateRegClassMask(RegClass, RegsAvailableCopy); + RegsAvailableCopy &= RegsAvailable; // If looking for a non-callee-saved register, mask off all the callee-saved // registers. if (ExCalleeSaved) - RegStatesCopy &= ~CalleeSavedRegs; + RegsAvailableCopy &= ~CalleeSavedRegs; // Returns the first unused (bit is set) register, or 0 is none is found. - int Reg = RegStatesCopy.find_first(); + int Reg = RegsAvailableCopy.find_first(); return (Reg == -1) ? 0 : Reg; }