diff --git a/llvm/include/llvm/Target/TargetRegisterInfo.h b/llvm/include/llvm/Target/TargetRegisterInfo.h index c2a973e0db0c..d6887ead01b8 100644 --- a/llvm/include/llvm/Target/TargetRegisterInfo.h +++ b/llvm/include/llvm/Target/TargetRegisterInfo.h @@ -297,65 +297,61 @@ public: enum { // Define some target independent constants /// NoRegister - This physical register is not a real target register. It - /// is useful as a sentinal. - NoRegister = 0, - - /// FirstVirtualRegister - This is the first register number that is - /// considered to be a 'virtual' register, which is part of the SSA - /// namespace. This must be the same for all targets, which means that each - /// target is limited to this fixed number of registers. - FirstVirtualRegister = 16384 + /// is useful as a sentinel. + NoRegister = 0 }; /// isStackSlot - Sometimes it is useful the be able to store a non-negative /// frame index in a variable that normally holds a register. isStackSlot() /// returns true if Reg is in the range used for stack slots. /// - /// Note that isVirtualRegister() and isPhysicalRegister() may also return - /// true for such a value. In that case, isStackSlot() takes precedence. + /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack + /// slots, so if a variable may contains a stack slot, always check + /// isStackSlot() first. /// static bool isStackSlot(unsigned Reg) { - return Reg >= (1u << 31); + return int(Reg) >= (1 << 30); } /// stackSlot2Index - Compute the frame index from a register value /// representing a stack slot. static int stackSlot2Index(unsigned Reg) { assert(isStackSlot(Reg) && "Not a stack slot"); - return int(Reg - (1u << 31)); + return int(Reg - (1u << 30)); } /// index2StackSlot - Convert a non-negative frame index to a stack slot /// register value. static unsigned index2StackSlot(int FI) { assert(FI >= 0 && "Cannot hold a negative frame index."); - return FI + (1u << 31); + return FI + (1u << 30); } /// isPhysicalRegister - Return true if the specified register number is in /// the physical register namespace. static bool isPhysicalRegister(unsigned Reg) { - assert(Reg && "this is not a register!"); - return Reg < FirstVirtualRegister; + assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first."); + return int(Reg) > 0; } /// isVirtualRegister - Return true if the specified register number is in /// the virtual register namespace. static bool isVirtualRegister(unsigned Reg) { - assert(!isStackSlot(Reg) && "this is not a register!"); - return Reg >= FirstVirtualRegister; + assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first."); + return int(Reg) < 0; } /// virtReg2Index - Convert a virtual register number to a 0-based index. /// The first virtual register in a function will get the index 0. static unsigned virtReg2Index(unsigned Reg) { - return Reg - FirstVirtualRegister; + assert(isVirtualRegister(Reg) && "Not a virtual register"); + return Reg - (1u << 31); } /// index2VirtReg - Convert a 0-based index to a virtual register number. /// This is the inverse operation of VirtReg2IndexFunctor below. static unsigned index2VirtReg(unsigned Index) { - return Index + FirstVirtualRegister; + return Index + (1u << 31); } /// getMinimalPhysRegClass - Returns the Register Class of a physical