Skip to content

Commit

Permalink
[RDF] Add RegisterRef::idx and make toUnitId constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Parzyszek committed Jun 13, 2023
1 parent 623295a commit dbee656
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions llvm/include/llvm/CodeGen/RDFRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct RegisterRef {
constexpr bool isUnit() const { return isUnitId(Reg); }
constexpr bool isMask() const { return isMaskId(Reg); }

constexpr unsigned idx() const { return toIdx(Reg); }

constexpr operator bool() const {
return !isReg() || (Reg != 0 && Mask.any());
}
Expand All @@ -103,10 +105,18 @@ struct RegisterRef {
return Register::isStackSlot(Id);
}

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

static constexpr unsigned toIdx(RegisterId Id) {
// Not using virtReg2Index or stackSlot2Index, because they are
// not constexpr.
if (isUnitId(Id))
return Id & ~MCRegister::VirtualRegFlag;
// RegId and MaskId are unchanged.
return Id;
}
static unsigned toRegUnit(RegisterId U) { return Register::virtReg2Index(U); }

bool operator<(RegisterRef) const = delete;
bool operator==(RegisterRef) const = delete;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/RDFRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ bool PhysicalRegisterInfo::less(RegisterRef A, RegisterRef B) const {

void PhysicalRegisterInfo::print(raw_ostream &OS, RegisterRef A) const {
if (A.Reg == 0 || A.isReg()) {
if (0 < A.Reg && A.Reg < TRI.getNumRegs())
OS << TRI.getName(A.Reg);
if (0 < A.idx() && A.idx() < TRI.getNumRegs())
OS << TRI.getName(A.idx());
else
OS << printReg(A.Reg, &TRI);
OS << PrintLaneMaskShort(A.Mask);
} else if (A.isUnit()) {
OS << printRegUnit(A.toRegUnit(A.Reg), &TRI);
OS << printRegUnit(A.idx(), &TRI);
} else {
assert(A.isMask());
OS << '#' << format("%08x", A.Reg);
Expand Down

0 comments on commit dbee656

Please sign in to comment.