//
// Further sentinels can be allocated from the small negative integers.
// DenseMapInfo<unsigned> uses -1u and -2u.
+ static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
+ "Reg isn't large enough to hold full range.");
/// isStackSlot - Sometimes it is useful the be able to store a non-negative
/// frame index in a variable that normally holds a register. isStackSlot()
/// 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 << 30));
+ return int(Reg - MCRegister::FirstStackSlot);
}
/// 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 << 30);
+ return FI + MCRegister::FirstStackSlot;
}
/// Return true if the specified register number is in
/// the virtual register namespace.
static bool isVirtualRegister(unsigned Reg) {
assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
- return int(Reg) < 0;
+ return Reg & MCRegister::VirtualRegFlag;
}
/// 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) {
assert(isVirtualRegister(Reg) && "Not a virtual register");
- return Reg & ~(1u << 31);
+ return Reg & ~MCRegister::VirtualRegFlag;
}
/// 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 | (1u << 31);
+ assert(Index < (1u << 31) && "Index too large for virtual register range.");
+ return Index | MCRegister::VirtualRegFlag;
}
/// Return true if the specified register number is in the virtual register
return MCRegister(Reg);
}
- bool isValid() const {
- return Reg != 0;
- }
+ bool isValid() const { return Reg != MCRegister::NoRegister; }
/// Comparisons between register objects
bool operator==(const Register &Other) const { return Reg == Other.Reg; }
//
// Further sentinels can be allocated from the small negative integers.
// DenseMapInfo<unsigned> uses -1u and -2u.
+ static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
+ "Reg isn't large enough to hold full range.");
+ static constexpr unsigned NoRegister = 0u;
+ static constexpr unsigned FirstPhysicalReg = 1u;
+ static constexpr unsigned FirstStackSlot = 1u << 30;
+ static constexpr unsigned VirtualRegFlag = 1u << 31;
/// This is the portion of the positive number space that is not a physical
/// register. StackSlot values do not exist in the MC layer, see
/// slots, so if a variable may contains a stack slot, always check
/// isStackSlot() first.
static bool isStackSlot(unsigned Reg) {
- return int(Reg) >= (1 << 30);
+ return !(Reg & VirtualRegFlag) &&
+ uint32_t(Reg & ~VirtualRegFlag) >= FirstStackSlot;
}
/// Return true if the specified register number is in
/// the physical register namespace.
static bool isPhysicalRegister(unsigned Reg) {
assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
- return int(Reg) > 0;
+ return Reg >= FirstPhysicalReg && !(Reg & VirtualRegFlag);
}
/// Return true if the specified register number is in the physical register
return Reg;
}
- bool isValid() const {
- return Reg != 0;
- }
+ bool isValid() const { return Reg != NoRegister; }
/// Comparisons between register objects
bool operator==(const MCRegister &Other) const { return Reg == Other.Reg; }