Skip to content

[AArch64] Use GenericTable PrimaryKey to remove one of the SearchIndexes for SysRegs. NFC #122001

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
Jan 8, 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
21 changes: 7 additions & 14 deletions llvm/lib/Target/AArch64/AArch64SystemOperands.td
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,6 @@ defm : TLBI<"VMALLWS2E1OS", 0b100, 0b1000, 0b0101, 0b010, 0>;
class SysReg<string name, bits<2> op0, bits<3> op1, bits<4> crn, bits<4> crm,
bits<3> op2> {
string Name = name;
string AltName = name;
bits<16> Encoding;
let Encoding{15-14} = op0;
let Encoding{13-11} = op1;
Expand All @@ -1018,20 +1017,18 @@ def SysRegValues : GenericEnum {

def SysRegsList : GenericTable {
let FilterClass = "SysReg";
let Fields = ["Name", "AltName", "Encoding", "Readable", "Writeable",
"Requires"];
let Fields = ["Name", "Encoding", "Readable", "Writeable", "Requires"];

let PrimaryKey = ["Encoding"];
let PrimaryKeyName = "lookupSysRegByEncoding";
let PrimaryKeyReturnRange = true;
}

def lookupSysRegByName : SearchIndex {
let Table = SysRegsList;
let Key = ["Name"];
}

def lookupSysRegByEncoding : SearchIndex {
let Table = SysRegsList;
let Key = ["Encoding"];
}

class RWSysReg<string name, bits<2> op0, bits<3> op1, bits<4> crn, bits<4> crm,
bits<3> op2>
: SysReg<name, op0, op1, crn, crm, op2> {
Expand Down Expand Up @@ -1317,9 +1314,7 @@ def : RWSysReg<"TTBR0_EL1", 0b11, 0b000, 0b0010, 0b0000, 0b000>;
def : RWSysReg<"TTBR0_EL3", 0b11, 0b110, 0b0010, 0b0000, 0b000>;

let Requires = [{ {AArch64::FeatureEL2VMSA} }] in {
def : RWSysReg<"TTBR0_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000> {
let AltName = "VSCTLR_EL2";
}
def : RWSysReg<"TTBR0_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000>;
def : RWSysReg<"VTTBR_EL2", 0b11, 0b100, 0b0010, 0b0001, 0b000>;
}

Expand Down Expand Up @@ -1706,9 +1701,7 @@ def : RWSysReg<"ICH_LR15_EL2", 0b11, 0b100, 0b1100, 0b1101, 0b111>;
let Requires = [{ {AArch64::HasV8_0rOps} }] in {
//Virtualization System Control Register
// Op0 Op1 CRn CRm Op2
def : RWSysReg<"VSCTLR_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000> {
let AltName = "TTBR0_EL2";
}
def : RWSysReg<"VSCTLR_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000>;

//MPU Type Register
// Op0 Op1 CRn CRm Op2
Expand Down
29 changes: 14 additions & 15 deletions llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,26 +1874,25 @@ void AArch64InstPrinter::printBarriernXSOption(const MCInst *MI, unsigned OpNo,
markup(O, Markup::Immediate) << "#" << Val;
}

static bool isValidSysReg(const AArch64SysReg::SysReg *Reg, bool Read,
static bool isValidSysReg(const AArch64SysReg::SysReg &Reg, bool Read,
const MCSubtargetInfo &STI) {
return (Reg && (Read ? Reg->Readable : Reg->Writeable) &&
Reg->haveFeatures(STI.getFeatureBits()));
return (Read ? Reg.Readable : Reg.Writeable) &&
Reg.haveFeatures(STI.getFeatureBits());
}

// Looks up a system register either by encoding or by name. Some system
// Looks up a system register either by encoding. Some system
// registers share the same encoding between different architectures,
// therefore a tablegen lookup by encoding will return an entry regardless
// of the register's predication on a specific subtarget feature. To work
// around this problem we keep an alternative name for such registers and
// look them up by that name if the first lookup was unsuccessful.
// to work around this tablegen will return a range of registers with the same
// encodings. We need to check each register in the range to see if it valid.
static const AArch64SysReg::SysReg *lookupSysReg(unsigned Val, bool Read,
const MCSubtargetInfo &STI) {
const AArch64SysReg::SysReg *Reg = AArch64SysReg::lookupSysRegByEncoding(Val);

if (Reg && !isValidSysReg(Reg, Read, STI))
Reg = AArch64SysReg::lookupSysRegByName(Reg->AltName);
auto Range = AArch64SysReg::lookupSysRegByEncoding(Val);
for (auto &Reg : Range) {
if (isValidSysReg(Reg, Read, STI))
return &Reg;
}

return Reg;
return nullptr;
}

void AArch64InstPrinter::printMRSSystemRegister(const MCInst *MI, unsigned OpNo,
Expand All @@ -1917,7 +1916,7 @@ void AArch64InstPrinter::printMRSSystemRegister(const MCInst *MI, unsigned OpNo,

const AArch64SysReg::SysReg *Reg = lookupSysReg(Val, true /*Read*/, STI);

if (isValidSysReg(Reg, true /*Read*/, STI))
if (Reg)
O << Reg->Name;
else
O << AArch64SysReg::genericRegisterString(Val);
Expand All @@ -1944,7 +1943,7 @@ void AArch64InstPrinter::printMSRSystemRegister(const MCInst *MI, unsigned OpNo,

const AArch64SysReg::SysReg *Reg = lookupSysReg(Val, false /*Read*/, STI);

if (isValidSysReg(Reg, false /*Read*/, STI))
if (Reg)
O << Reg->Name;
else
O << AArch64SysReg::genericRegisterString(Val);
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ AArch64StringToVectorLayout(StringRef LayoutStr) {
namespace AArch64SysReg {
struct SysReg {
const char Name[32];
const char AltName[32];
unsigned Encoding;
bool Readable;
bool Writeable;
Expand All @@ -736,9 +735,6 @@ namespace AArch64SysReg {
#define GET_SysRegValues_DECL
#include "AArch64GenSystemOperands.inc"

const SysReg *lookupSysRegByName(StringRef);
const SysReg *lookupSysRegByEncoding(uint16_t);

uint32_t parseGenericRegister(StringRef Name);
std::string genericRegisterString(uint32_t Bits);
}
Expand Down
Loading