Skip to content

[MC][CodeGen] Move FirstStackSlot and VirtualRegFlag from MCRegister to Register. NFC #128444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/RDFRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ struct RegisterRef {
static constexpr bool isMaskId(unsigned Id) { return Register(Id).isStack(); }

static constexpr RegisterId toUnitId(unsigned Idx) {
return Idx | MCRegister::VirtualRegFlag;
return Idx | Register::VirtualRegFlag;
}

static constexpr unsigned toIdx(RegisterId Id) {
// Not using virtReg2Index or stackSlot2Index, because they are
// not constexpr.
if (isUnitId(Id))
return Id & ~MCRegister::VirtualRegFlag;
return Id & ~Register::VirtualRegFlag;
// RegId and MaskId are unchanged.
return Id;
}
Expand Down
16 changes: 9 additions & 7 deletions llvm/include/llvm/CodeGen/Register.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ class Register {
// 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 FirstStackSlot = 1u << 30;
static_assert(FirstStackSlot >= MCRegister::LastPhysicalReg);
static constexpr unsigned VirtualRegFlag = 1u << 31;

/// Return true if this is a stack slot.
constexpr bool isStack() const {
return MCRegister::FirstStackSlot <= Reg &&
Reg < MCRegister::VirtualRegFlag;
return Register::FirstStackSlot <= Reg && Reg < Register::VirtualRegFlag;
}

/// Convert a non-negative frame index to a stack slot register value.
static Register index2StackSlot(int FI) {
assert(FI >= 0 && "Cannot hold a negative frame index.");
return Register(FI + MCRegister::FirstStackSlot);
return Register(FI + Register::FirstStackSlot);
}

/// Return true if the specified register number is in
Expand All @@ -57,14 +59,14 @@ class Register {
/// Return true if the specified register number is in
/// the virtual register namespace.
static constexpr bool isVirtualRegister(unsigned Reg) {
return Reg & MCRegister::VirtualRegFlag;
return Reg & Register::VirtualRegFlag;
}

/// Convert a 0-based index to a virtual register number.
/// This is the inverse operation of VirtReg2IndexFunctor below.
static Register index2VirtReg(unsigned Index) {
assert(Index < (1u << 31) && "Index too large for virtual register range.");
return Index | MCRegister::VirtualRegFlag;
return Index | Register::VirtualRegFlag;
}

/// Return true if the specified register number is in the virtual register
Expand All @@ -79,13 +81,13 @@ class Register {
/// register in a function will get the index 0.
unsigned virtRegIndex() const {
assert(isVirtual() && "Not a virtual register");
return Reg & ~MCRegister::VirtualRegFlag;
return Reg & ~Register::VirtualRegFlag;
}

/// Compute the frame index from a register value representing a stack slot.
int stackSlotIndex() const {
assert(isStack() && "Not a stack slot");
return static_cast<int>(Reg - MCRegister::FirstStackSlot);
return static_cast<int>(Reg - Register::FirstStackSlot);
}

constexpr operator unsigned() const { return Reg; }
Expand Down
5 changes: 2 additions & 3 deletions llvm/include/llvm/MC/MCRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ class MCRegister {
"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;
static constexpr unsigned LastPhysicalReg = (1u << 30) - 1;

/// Return true if the specified register number is in
/// the physical register namespace.
static constexpr bool isPhysicalRegister(unsigned Reg) {
return FirstPhysicalReg <= Reg && Reg < FirstStackSlot;
return FirstPhysicalReg <= Reg && Reg <= LastPhysicalReg;
}

/// Return true if the specified register number is in the physical register
Expand Down