Skip to content

Commit 6053ca0

Browse files
authored
[MC][CodeGen] Move FirstStackSlot and VirtualRegFlag from MCRegister to Register. NFC (#128444)
These concepts don't exist for MCRegister. I think there is a need for virtual registers in MCRegister for NVPTX, SPIR-V and WebAssembly, but those should not be confused with Register's virtual register. I will try to make a separate proposal for that with a real interface.
1 parent 8b1d384 commit 6053ca0

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

llvm/include/llvm/CodeGen/RDFRegisters.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ struct RegisterRef {
119119
static constexpr bool isMaskId(unsigned Id) { return Register(Id).isStack(); }
120120

121121
static constexpr RegisterId toUnitId(unsigned Idx) {
122-
return Idx | MCRegister::VirtualRegFlag;
122+
return Idx | Register::VirtualRegFlag;
123123
}
124124

125125
static constexpr unsigned toIdx(RegisterId Id) {
126126
// Not using virtReg2Index or stackSlot2Index, because they are
127127
// not constexpr.
128128
if (isUnitId(Id))
129-
return Id & ~MCRegister::VirtualRegFlag;
129+
return Id & ~Register::VirtualRegFlag;
130130
// RegId and MaskId are unchanged.
131131
return Id;
132132
}

llvm/include/llvm/CodeGen/Register.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ class Register {
3535
// DenseMapInfo<unsigned> uses -1u and -2u.
3636
static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
3737
"Reg isn't large enough to hold full range.");
38+
static constexpr unsigned FirstStackSlot = 1u << 30;
39+
static_assert(FirstStackSlot >= MCRegister::LastPhysicalReg);
40+
static constexpr unsigned VirtualRegFlag = 1u << 31;
3841

3942
/// Return true if this is a stack slot.
4043
constexpr bool isStack() const {
41-
return MCRegister::FirstStackSlot <= Reg &&
42-
Reg < MCRegister::VirtualRegFlag;
44+
return Register::FirstStackSlot <= Reg && Reg < Register::VirtualRegFlag;
4345
}
4446

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

5153
/// Return true if the specified register number is in
@@ -57,14 +59,14 @@ class Register {
5759
/// Return true if the specified register number is in
5860
/// the virtual register namespace.
5961
static constexpr bool isVirtualRegister(unsigned Reg) {
60-
return Reg & MCRegister::VirtualRegFlag;
62+
return Reg & Register::VirtualRegFlag;
6163
}
6264

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

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

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

9193
constexpr operator unsigned() const { return Reg; }

llvm/include/llvm/MC/MCRegister.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ class MCRegister {
5151
"Reg isn't large enough to hold full range.");
5252
static constexpr unsigned NoRegister = 0u;
5353
static constexpr unsigned FirstPhysicalReg = 1u;
54-
static constexpr unsigned FirstStackSlot = 1u << 30;
55-
static constexpr unsigned VirtualRegFlag = 1u << 31;
54+
static constexpr unsigned LastPhysicalReg = (1u << 30) - 1;
5655

5756
/// Return true if the specified register number is in
5857
/// the physical register namespace.
5958
static constexpr bool isPhysicalRegister(unsigned Reg) {
60-
return FirstPhysicalReg <= Reg && Reg < FirstStackSlot;
59+
return FirstPhysicalReg <= Reg && Reg <= LastPhysicalReg;
6160
}
6261

6362
/// Return true if the specified register number is in the physical register

0 commit comments

Comments
 (0)