Skip to content

Commit b05be2a

Browse files
authored
[AArch64] Use GenericTable PrimaryKey to remove one of the SearchIndexes for SysRegs. NFC (llvm#122001)
Use PrimaryKeyReturnRange to get all of the registers with the same encoding. This allows AltName to be removed.
1 parent 3972ed5 commit b05be2a

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

llvm/lib/Target/AArch64/AArch64SystemOperands.td

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ defm : TLBI<"VMALLWS2E1OS", 0b100, 0b1000, 0b0101, 0b010, 0>;
998998
class SysReg<string name, bits<2> op0, bits<3> op1, bits<4> crn, bits<4> crm,
999999
bits<3> op2> {
10001000
string Name = name;
1001-
string AltName = name;
10021001
bits<16> Encoding;
10031002
let Encoding{15-14} = op0;
10041003
let Encoding{13-11} = op1;
@@ -1018,20 +1017,18 @@ def SysRegValues : GenericEnum {
10181017

10191018
def SysRegsList : GenericTable {
10201019
let FilterClass = "SysReg";
1021-
let Fields = ["Name", "AltName", "Encoding", "Readable", "Writeable",
1022-
"Requires"];
1020+
let Fields = ["Name", "Encoding", "Readable", "Writeable", "Requires"];
1021+
1022+
let PrimaryKey = ["Encoding"];
1023+
let PrimaryKeyName = "lookupSysRegByEncoding";
1024+
let PrimaryKeyReturnRange = true;
10231025
}
10241026

10251027
def lookupSysRegByName : SearchIndex {
10261028
let Table = SysRegsList;
10271029
let Key = ["Name"];
10281030
}
10291031

1030-
def lookupSysRegByEncoding : SearchIndex {
1031-
let Table = SysRegsList;
1032-
let Key = ["Encoding"];
1033-
}
1034-
10351032
class RWSysReg<string name, bits<2> op0, bits<3> op1, bits<4> crn, bits<4> crm,
10361033
bits<3> op2>
10371034
: SysReg<name, op0, op1, crn, crm, op2> {
@@ -1317,9 +1314,7 @@ def : RWSysReg<"TTBR0_EL1", 0b11, 0b000, 0b0010, 0b0000, 0b000>;
13171314
def : RWSysReg<"TTBR0_EL3", 0b11, 0b110, 0b0010, 0b0000, 0b000>;
13181315

13191316
let Requires = [{ {AArch64::FeatureEL2VMSA} }] in {
1320-
def : RWSysReg<"TTBR0_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000> {
1321-
let AltName = "VSCTLR_EL2";
1322-
}
1317+
def : RWSysReg<"TTBR0_EL2", 0b11, 0b100, 0b0010, 0b0000, 0b000>;
13231318
def : RWSysReg<"VTTBR_EL2", 0b11, 0b100, 0b0010, 0b0001, 0b000>;
13241319
}
13251320

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

17131706
//MPU Type Register
17141707
// Op0 Op1 CRn CRm Op2

llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,26 +1874,25 @@ void AArch64InstPrinter::printBarriernXSOption(const MCInst *MI, unsigned OpNo,
18741874
markup(O, Markup::Immediate) << "#" << Val;
18751875
}
18761876

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

1883-
// Looks up a system register either by encoding or by name. Some system
1883+
// Looks up a system register either by encoding. Some system
18841884
// registers share the same encoding between different architectures,
1885-
// therefore a tablegen lookup by encoding will return an entry regardless
1886-
// of the register's predication on a specific subtarget feature. To work
1887-
// around this problem we keep an alternative name for such registers and
1888-
// look them up by that name if the first lookup was unsuccessful.
1885+
// to work around this tablegen will return a range of registers with the same
1886+
// encodings. We need to check each register in the range to see if it valid.
18891887
static const AArch64SysReg::SysReg *lookupSysReg(unsigned Val, bool Read,
18901888
const MCSubtargetInfo &STI) {
1891-
const AArch64SysReg::SysReg *Reg = AArch64SysReg::lookupSysRegByEncoding(Val);
1892-
1893-
if (Reg && !isValidSysReg(Reg, Read, STI))
1894-
Reg = AArch64SysReg::lookupSysRegByName(Reg->AltName);
1889+
auto Range = AArch64SysReg::lookupSysRegByEncoding(Val);
1890+
for (auto &Reg : Range) {
1891+
if (isValidSysReg(Reg, Read, STI))
1892+
return &Reg;
1893+
}
18951894

1896-
return Reg;
1895+
return nullptr;
18971896
}
18981897

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

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

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

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

1947-
if (isValidSysReg(Reg, false /*Read*/, STI))
1946+
if (Reg)
19481947
O << Reg->Name;
19491948
else
19501949
O << AArch64SysReg::genericRegisterString(Val);

llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,6 @@ AArch64StringToVectorLayout(StringRef LayoutStr) {
719719
namespace AArch64SysReg {
720720
struct SysReg {
721721
const char Name[32];
722-
const char AltName[32];
723722
unsigned Encoding;
724723
bool Readable;
725724
bool Writeable;
@@ -735,9 +734,6 @@ namespace AArch64SysReg {
735734
#define GET_SysRegValues_DECL
736735
#include "AArch64GenSystemOperands.inc"
737736

738-
const SysReg *lookupSysRegByName(StringRef);
739-
const SysReg *lookupSysRegByEncoding(uint16_t);
740-
741737
uint32_t parseGenericRegister(StringRef Name);
742738
std::string genericRegisterString(uint32_t Bits);
743739
}

0 commit comments

Comments
 (0)