Skip to content

[Target] Move SubRegIdxRanges from MCSubtargetInfo to TargetInfo. #86245

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
Mar 22, 2024
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
31 changes: 25 additions & 6 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,20 @@ class TargetRegisterInfo : public MCRegisterInfo {
unsigned RegSize, SpillSize, SpillAlignment;
unsigned VTListOffset;
};

/// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
/// index, -1 in any being invalid.
struct SubRegCoveredBits {
uint16_t Offset;
uint16_t Size;
};

private:
const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
const char *const *SubRegIndexNames; // Names of subreg indexes.
const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
// bit ranges array.

// Pointer to array of lane masks, one per sub-reg index.
const LaneBitmask *SubRegIndexLaneMasks;

Expand All @@ -256,12 +267,10 @@ class TargetRegisterInfo : public MCRegisterInfo {
unsigned HwMode;

protected:
TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
regclass_iterator RCB,
regclass_iterator RCE,
const char *const *SRINames,
const LaneBitmask *SRILaneMasks,
LaneBitmask CoveringLanes,
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB,
regclass_iterator RCE, const char *const *SRINames,
const SubRegCoveredBits *SubIdxRanges,
const LaneBitmask *SRILaneMasks, LaneBitmask CoveringLanes,
const RegClassInfo *const RCIs,
const MVT::SimpleValueType *const RCVTLists,
unsigned Mode = 0);
Expand Down Expand Up @@ -382,6 +391,16 @@ class TargetRegisterInfo : public MCRegisterInfo {
return SubRegIndexNames[SubIdx-1];
}

/// Get the size of the bit range covered by a sub-register index.
/// If the index isn't continuous, return the sum of the sizes of its parts.
/// If the index is used to access subregisters of different sizes, return -1.
unsigned getSubRegIdxSize(unsigned Idx) const;

/// Get the offset of the bit range covered by a sub-register index.
/// If an Offset doesn't make sense (the index isn't continuous, or is used to
/// access sub-registers at different offsets), return -1.
unsigned getSubRegIdxOffset(unsigned Idx) const;

/// Return a bitmask representing the parts of a register that are covered by
/// SubIdx \see LaneBitmask.
///
Expand Down
21 changes: 0 additions & 21 deletions llvm/include/llvm/MC/MCRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ class MCRegisterInfo {
bool operator<(DwarfLLVMRegPair RHS) const { return FromReg < RHS.FromReg; }
};

/// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
/// index, -1 in any being invalid.
struct SubRegCoveredBits {
uint16_t Offset;
uint16_t Size;
};

private:
const MCRegisterDesc *Desc; // Pointer to the descriptor array
unsigned NumRegs; // Number of entries in the array
Expand All @@ -176,8 +169,6 @@ class MCRegisterInfo {
const char *RegClassStrings; // Pointer to the class strings.
const uint16_t *SubRegIndices; // Pointer to the subreg lookup
// array.
const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
// bit ranges array.
unsigned NumSubRegIndices; // Number of subreg indices.
const uint16_t *RegEncodingTable; // Pointer to array of register
// encodings.
Expand Down Expand Up @@ -278,7 +269,6 @@ class MCRegisterInfo {
const int16_t *DL, const LaneBitmask *RUMS,
const char *Strings, const char *ClassStrings,
const uint16_t *SubIndices, unsigned NumIndices,
const SubRegCoveredBits *SubIdxRanges,
const uint16_t *RET) {
Desc = D;
NumRegs = NR;
Expand All @@ -294,7 +284,6 @@ class MCRegisterInfo {
NumRegUnits = NRU;
SubRegIndices = SubIndices;
NumSubRegIndices = NumIndices;
SubRegIdxRanges = SubIdxRanges;
RegEncodingTable = RET;

// Initialize DWARF register mapping variables
Expand Down Expand Up @@ -387,16 +376,6 @@ class MCRegisterInfo {
/// otherwise.
unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const;

/// Get the size of the bit range covered by a sub-register index.
/// If the index isn't continuous, return the sum of the sizes of its parts.
/// If the index is used to access subregisters of different sizes, return -1.
unsigned getSubRegIdxSize(unsigned Idx) const;

/// Get the offset of the bit range covered by a sub-register index.
/// If an Offset doesn't make sense (the index isn't continuous, or is used to
/// access sub-registers at different offsets), return -1.
unsigned getSubRegIdxOffset(unsigned Idx) const;

/// Return the human-readable symbolic target-specific name for the
/// specified physical register.
const char *getName(MCRegister RegNo) const {
Expand Down
36 changes: 22 additions & 14 deletions llvm/lib/CodeGen/TargetRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,16 @@ static cl::opt<unsigned>
"high compile time cost in global splitting."),
cl::init(5000));

TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
regclass_iterator RCB, regclass_iterator RCE,
const char *const *SRINames,
const LaneBitmask *SRILaneMasks,
LaneBitmask SRICoveringLanes,
const RegClassInfo *const RCIs,
const MVT::SimpleValueType *const RCVTLists,
unsigned Mode)
: InfoDesc(ID), SubRegIndexNames(SRINames),
SubRegIndexLaneMasks(SRILaneMasks),
RegClassBegin(RCB), RegClassEnd(RCE),
CoveringLanes(SRICoveringLanes),
RCInfos(RCIs), RCVTLists(RCVTLists), HwMode(Mode) {
}
TargetRegisterInfo::TargetRegisterInfo(
const TargetRegisterInfoDesc *ID, regclass_iterator RCB,
regclass_iterator RCE, const char *const *SRINames,
const SubRegCoveredBits *SubIdxRanges, const LaneBitmask *SRILaneMasks,
LaneBitmask SRICoveringLanes, const RegClassInfo *const RCIs,
const MVT::SimpleValueType *const RCVTLists, unsigned Mode)
: InfoDesc(ID), SubRegIndexNames(SRINames), SubRegIdxRanges(SubIdxRanges),
SubRegIndexLaneMasks(SRILaneMasks), RegClassBegin(RCB), RegClassEnd(RCE),
CoveringLanes(SRICoveringLanes), RCInfos(RCIs), RCVTLists(RCVTLists),
HwMode(Mode) {}

TargetRegisterInfo::~TargetRegisterInfo() = default;

Expand Down Expand Up @@ -596,6 +592,18 @@ bool TargetRegisterInfo::getCoveringSubRegIndexes(
return BestIdx;
}

unsigned TargetRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
assert(Idx && Idx < getNumSubRegIndices() &&
"This is not a subregister index");
return SubRegIdxRanges[Idx].Size;
}

unsigned TargetRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
assert(Idx && Idx < getNumSubRegIndices() &&
"This is not a subregister index");
return SubRegIdxRanges[Idx].Offset;
}

Register
TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
const MachineRegisterInfo *MRI) const {
Expand Down
12 changes: 0 additions & 12 deletions llvm/lib/MC/MCRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ unsigned MCRegisterInfo::getSubRegIndex(MCRegister Reg,
return 0;
}

unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
assert(Idx && Idx < getNumSubRegIndices() &&
"This is not a subregister index");
return SubRegIdxRanges[Idx].Size;
}

unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
assert(Idx && Idx < getNumSubRegIndices() &&
"This is not a subregister index");
return SubRegIdxRanges[Idx].Offset;
}

int MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ SIRegisterInfo::SIRegisterInfo(const GCNSubtarget &ST)
for (auto &Row : SubRegFromChannelTable)
Row.fill(AMDGPU::NoSubRegister);
for (unsigned Idx = 1; Idx < getNumSubRegIndices(); ++Idx) {
unsigned Width = AMDGPUSubRegIdxRanges[Idx].Size / 32;
unsigned Offset = AMDGPUSubRegIdxRanges[Idx].Offset / 32;
unsigned Width = getSubRegIdxSize(Idx) / 32;
unsigned Offset = getSubRegIdxOffset(Idx) / 32;
assert(Width < SubRegFromChannelTableWidthMap.size());
Width = SubRegFromChannelTableWidthMap[Width];
if (Width == 0)
Expand Down
5 changes: 3 additions & 2 deletions llvm/unittests/CodeGen/MFCommon.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class BogusRegisterInfo : public TargetRegisterInfo {
public:
BogusRegisterInfo()
: TargetRegisterInfo(nullptr, BogusRegisterClasses, BogusRegisterClasses,
nullptr, nullptr, LaneBitmask(~0u), nullptr, nullptr) {
nullptr, nullptr, nullptr, LaneBitmask(~0u), nullptr,
nullptr) {
InitMCRegisterInfo(nullptr, 0, 0, 0, nullptr, 0, nullptr, 0, nullptr,
nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr);
nullptr, nullptr, nullptr, nullptr, 0, nullptr);
}

const MCPhysReg *
Expand Down
29 changes: 13 additions & 16 deletions llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,16 +955,6 @@ void RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
SubRegIdxSeqs.emit(OS, printSubRegIndex);
OS << "};\n\n";

// Emit the table of sub-register index sizes.
OS << "extern const MCRegisterInfo::SubRegCoveredBits " << TargetName
<< "SubRegIdxRanges[] = {\n";
OS << " { " << (uint16_t)-1 << ", " << (uint16_t)-1 << " },\n";
for (const auto &Idx : SubRegIndices) {
OS << " { " << Idx.Offset << ", " << Idx.Size << " },\t// "
<< Idx.getName() << "\n";
}
OS << "};\n\n";

// Emit the string table.
RegStrings.layout();
RegStrings.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
Expand Down Expand Up @@ -1101,8 +1091,7 @@ void RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
<< TargetName << "LaneMaskLists, " << TargetName << "RegStrings, "
<< TargetName << "RegClassStrings, " << TargetName << "SubRegIdxLists, "
<< (std::distance(SubRegIndices.begin(), SubRegIndices.end()) + 1) << ",\n"
<< TargetName << "SubRegIdxRanges, " << TargetName
<< "RegEncodingTable);\n\n";
<< TargetName << "RegEncodingTable);\n\n";

EmitRegMapping(OS, Regs, false);

Expand Down Expand Up @@ -1253,6 +1242,16 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
}
OS << "\" };\n\n";

// Emit the table of sub-register index sizes.
OS << "static const TargetRegisterInfo::SubRegCoveredBits "
"SubRegIdxRangeTable[] = {\n";
OS << " { " << (uint16_t)-1 << ", " << (uint16_t)-1 << " },\n";
for (const auto &Idx : SubRegIndices) {
OS << " { " << Idx.Offset << ", " << Idx.Size << " },\t// "
<< Idx.getName() << "\n";
}
OS << "};\n\n";

// Emit SubRegIndex lane masks, including 0.
OS << "\nstatic const LaneBitmask SubRegIndexLaneMaskTable[] = {\n "
"LaneBitmask::getAll(),\n";
Expand Down Expand Up @@ -1634,8 +1633,6 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
OS << "extern const char " << TargetName << "RegClassStrings[];\n";
OS << "extern const MCPhysReg " << TargetName << "RegUnitRoots[][2];\n";
OS << "extern const uint16_t " << TargetName << "SubRegIdxLists[];\n";
OS << "extern const MCRegisterInfo::SubRegCoveredBits " << TargetName
<< "SubRegIdxRanges[];\n";
OS << "extern const uint16_t " << TargetName << "RegEncodingTable[];\n";

EmitRegMappingTables(OS, Regs, true);
Expand All @@ -1646,7 +1643,8 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
" unsigned PC, unsigned HwMode)\n"
<< " : TargetRegisterInfo(&" << TargetName << "RegInfoDesc"
<< ", RegisterClasses, RegisterClasses+" << RegisterClasses.size() << ",\n"
<< " SubRegIndexNameTable, SubRegIndexLaneMaskTable,\n"
<< " SubRegIndexNameTable, SubRegIdxRangeTable, "
"SubRegIndexLaneMaskTable,\n"
<< " ";
printMask(OS, RegBank.CoveringLanes);
OS << ", RegClassInfos, VTLists, HwMode) {\n"
Expand All @@ -1661,7 +1659,6 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
<< " " << TargetName << "RegClassStrings,\n"
<< " " << TargetName << "SubRegIdxLists,\n"
<< " " << SubRegIndicesSize + 1 << ",\n"
<< " " << TargetName << "SubRegIdxRanges,\n"
<< " " << TargetName << "RegEncodingTable);\n\n";

EmitRegMapping(OS, Regs, true);
Expand Down