Skip to content

Commit fb329f1

Browse files
authored
[Target] Move SubRegIdxRanges from MCSubtargetInfo to TargetInfo. (#86245)
I'm planning to add HwMode support to SubRegIdxRanges for RISC-V GPR pairs. The MC layer is currently unaware of the HwMode for registers and I'd like to keep it that way. This information is not used by the MC layer so I think it is safe to move it.
1 parent cd8286a commit fb329f1

File tree

7 files changed

+65
-73
lines changed

7 files changed

+65
-73
lines changed

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,20 @@ class TargetRegisterInfo : public MCRegisterInfo {
243243
unsigned RegSize, SpillSize, SpillAlignment;
244244
unsigned VTListOffset;
245245
};
246+
247+
/// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
248+
/// index, -1 in any being invalid.
249+
struct SubRegCoveredBits {
250+
uint16_t Offset;
251+
uint16_t Size;
252+
};
253+
246254
private:
247255
const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
248256
const char *const *SubRegIndexNames; // Names of subreg indexes.
257+
const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
258+
// bit ranges array.
259+
249260
// Pointer to array of lane masks, one per sub-reg index.
250261
const LaneBitmask *SubRegIndexLaneMasks;
251262

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

258269
protected:
259-
TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
260-
regclass_iterator RCB,
261-
regclass_iterator RCE,
262-
const char *const *SRINames,
263-
const LaneBitmask *SRILaneMasks,
264-
LaneBitmask CoveringLanes,
270+
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB,
271+
regclass_iterator RCE, const char *const *SRINames,
272+
const SubRegCoveredBits *SubIdxRanges,
273+
const LaneBitmask *SRILaneMasks, LaneBitmask CoveringLanes,
265274
const RegClassInfo *const RCIs,
266275
const MVT::SimpleValueType *const RCVTLists,
267276
unsigned Mode = 0);
@@ -382,6 +391,16 @@ class TargetRegisterInfo : public MCRegisterInfo {
382391
return SubRegIndexNames[SubIdx-1];
383392
}
384393

394+
/// Get the size of the bit range covered by a sub-register index.
395+
/// If the index isn't continuous, return the sum of the sizes of its parts.
396+
/// If the index is used to access subregisters of different sizes, return -1.
397+
unsigned getSubRegIdxSize(unsigned Idx) const;
398+
399+
/// Get the offset of the bit range covered by a sub-register index.
400+
/// If an Offset doesn't make sense (the index isn't continuous, or is used to
401+
/// access sub-registers at different offsets), return -1.
402+
unsigned getSubRegIdxOffset(unsigned Idx) const;
403+
385404
/// Return a bitmask representing the parts of a register that are covered by
386405
/// SubIdx \see LaneBitmask.
387406
///

llvm/include/llvm/MC/MCRegisterInfo.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ class MCRegisterInfo {
153153
bool operator<(DwarfLLVMRegPair RHS) const { return FromReg < RHS.FromReg; }
154154
};
155155

156-
/// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
157-
/// index, -1 in any being invalid.
158-
struct SubRegCoveredBits {
159-
uint16_t Offset;
160-
uint16_t Size;
161-
};
162-
163156
private:
164157
const MCRegisterDesc *Desc; // Pointer to the descriptor array
165158
unsigned NumRegs; // Number of entries in the array
@@ -176,8 +169,6 @@ class MCRegisterInfo {
176169
const char *RegClassStrings; // Pointer to the class strings.
177170
const uint16_t *SubRegIndices; // Pointer to the subreg lookup
178171
// array.
179-
const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
180-
// bit ranges array.
181172
unsigned NumSubRegIndices; // Number of subreg indices.
182173
const uint16_t *RegEncodingTable; // Pointer to array of register
183174
// encodings.
@@ -278,7 +269,6 @@ class MCRegisterInfo {
278269
const int16_t *DL, const LaneBitmask *RUMS,
279270
const char *Strings, const char *ClassStrings,
280271
const uint16_t *SubIndices, unsigned NumIndices,
281-
const SubRegCoveredBits *SubIdxRanges,
282272
const uint16_t *RET) {
283273
Desc = D;
284274
NumRegs = NR;
@@ -294,7 +284,6 @@ class MCRegisterInfo {
294284
NumRegUnits = NRU;
295285
SubRegIndices = SubIndices;
296286
NumSubRegIndices = NumIndices;
297-
SubRegIdxRanges = SubIdxRanges;
298287
RegEncodingTable = RET;
299288

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

390-
/// Get the size of the bit range covered by a sub-register index.
391-
/// If the index isn't continuous, return the sum of the sizes of its parts.
392-
/// If the index is used to access subregisters of different sizes, return -1.
393-
unsigned getSubRegIdxSize(unsigned Idx) const;
394-
395-
/// Get the offset of the bit range covered by a sub-register index.
396-
/// If an Offset doesn't make sense (the index isn't continuous, or is used to
397-
/// access sub-registers at different offsets), return -1.
398-
unsigned getSubRegIdxOffset(unsigned Idx) const;
399-
400379
/// Return the human-readable symbolic target-specific name for the
401380
/// specified physical register.
402381
const char *getName(MCRegister RegNo) const {

llvm/lib/CodeGen/TargetRegisterInfo.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,16 @@ static cl::opt<unsigned>
5050
"high compile time cost in global splitting."),
5151
cl::init(5000));
5252

53-
TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
54-
regclass_iterator RCB, regclass_iterator RCE,
55-
const char *const *SRINames,
56-
const LaneBitmask *SRILaneMasks,
57-
LaneBitmask SRICoveringLanes,
58-
const RegClassInfo *const RCIs,
59-
const MVT::SimpleValueType *const RCVTLists,
60-
unsigned Mode)
61-
: InfoDesc(ID), SubRegIndexNames(SRINames),
62-
SubRegIndexLaneMasks(SRILaneMasks),
63-
RegClassBegin(RCB), RegClassEnd(RCE),
64-
CoveringLanes(SRICoveringLanes),
65-
RCInfos(RCIs), RCVTLists(RCVTLists), HwMode(Mode) {
66-
}
53+
TargetRegisterInfo::TargetRegisterInfo(
54+
const TargetRegisterInfoDesc *ID, regclass_iterator RCB,
55+
regclass_iterator RCE, const char *const *SRINames,
56+
const SubRegCoveredBits *SubIdxRanges, const LaneBitmask *SRILaneMasks,
57+
LaneBitmask SRICoveringLanes, const RegClassInfo *const RCIs,
58+
const MVT::SimpleValueType *const RCVTLists, unsigned Mode)
59+
: InfoDesc(ID), SubRegIndexNames(SRINames), SubRegIdxRanges(SubIdxRanges),
60+
SubRegIndexLaneMasks(SRILaneMasks), RegClassBegin(RCB), RegClassEnd(RCE),
61+
CoveringLanes(SRICoveringLanes), RCInfos(RCIs), RCVTLists(RCVTLists),
62+
HwMode(Mode) {}
6763

6864
TargetRegisterInfo::~TargetRegisterInfo() = default;
6965

@@ -596,6 +592,18 @@ bool TargetRegisterInfo::getCoveringSubRegIndexes(
596592
return BestIdx;
597593
}
598594

595+
unsigned TargetRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
596+
assert(Idx && Idx < getNumSubRegIndices() &&
597+
"This is not a subregister index");
598+
return SubRegIdxRanges[Idx].Size;
599+
}
600+
601+
unsigned TargetRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
602+
assert(Idx && Idx < getNumSubRegIndices() &&
603+
"This is not a subregister index");
604+
return SubRegIdxRanges[Idx].Offset;
605+
}
606+
599607
Register
600608
TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
601609
const MachineRegisterInfo *MRI) const {

llvm/lib/MC/MCRegisterInfo.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ unsigned MCRegisterInfo::getSubRegIndex(MCRegister Reg,
5757
return 0;
5858
}
5959

60-
unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
61-
assert(Idx && Idx < getNumSubRegIndices() &&
62-
"This is not a subregister index");
63-
return SubRegIdxRanges[Idx].Size;
64-
}
65-
66-
unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
67-
assert(Idx && Idx < getNumSubRegIndices() &&
68-
"This is not a subregister index");
69-
return SubRegIdxRanges[Idx].Offset;
70-
}
71-
7260
int MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
7361
const DwarfLLVMRegPair *M = isEH ? EHL2DwarfRegs : L2DwarfRegs;
7462
unsigned Size = isEH ? EHL2DwarfRegsSize : L2DwarfRegsSize;

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ SIRegisterInfo::SIRegisterInfo(const GCNSubtarget &ST)
363363
for (auto &Row : SubRegFromChannelTable)
364364
Row.fill(AMDGPU::NoSubRegister);
365365
for (unsigned Idx = 1; Idx < getNumSubRegIndices(); ++Idx) {
366-
unsigned Width = AMDGPUSubRegIdxRanges[Idx].Size / 32;
367-
unsigned Offset = AMDGPUSubRegIdxRanges[Idx].Offset / 32;
366+
unsigned Width = getSubRegIdxSize(Idx) / 32;
367+
unsigned Offset = getSubRegIdxOffset(Idx) / 32;
368368
assert(Width < SubRegFromChannelTableWidthMap.size());
369369
Width = SubRegFromChannelTableWidthMap[Width];
370370
if (Width == 0)

llvm/unittests/CodeGen/MFCommon.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class BogusRegisterInfo : public TargetRegisterInfo {
2323
public:
2424
BogusRegisterInfo()
2525
: TargetRegisterInfo(nullptr, BogusRegisterClasses, BogusRegisterClasses,
26-
nullptr, nullptr, LaneBitmask(~0u), nullptr, nullptr) {
26+
nullptr, nullptr, nullptr, LaneBitmask(~0u), nullptr,
27+
nullptr) {
2728
InitMCRegisterInfo(nullptr, 0, 0, 0, nullptr, 0, nullptr, 0, nullptr,
28-
nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr);
29+
nullptr, nullptr, nullptr, nullptr, 0, nullptr);
2930
}
3031

3132
const MCPhysReg *

llvm/utils/TableGen/RegisterInfoEmitter.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -955,16 +955,6 @@ void RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
955955
SubRegIdxSeqs.emit(OS, printSubRegIndex);
956956
OS << "};\n\n";
957957

958-
// Emit the table of sub-register index sizes.
959-
OS << "extern const MCRegisterInfo::SubRegCoveredBits " << TargetName
960-
<< "SubRegIdxRanges[] = {\n";
961-
OS << " { " << (uint16_t)-1 << ", " << (uint16_t)-1 << " },\n";
962-
for (const auto &Idx : SubRegIndices) {
963-
OS << " { " << Idx.Offset << ", " << Idx.Size << " },\t// "
964-
<< Idx.getName() << "\n";
965-
}
966-
OS << "};\n\n";
967-
968958
// Emit the string table.
969959
RegStrings.layout();
970960
RegStrings.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
@@ -1101,8 +1091,7 @@ void RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
11011091
<< TargetName << "LaneMaskLists, " << TargetName << "RegStrings, "
11021092
<< TargetName << "RegClassStrings, " << TargetName << "SubRegIdxLists, "
11031093
<< (std::distance(SubRegIndices.begin(), SubRegIndices.end()) + 1) << ",\n"
1104-
<< TargetName << "SubRegIdxRanges, " << TargetName
1105-
<< "RegEncodingTable);\n\n";
1094+
<< TargetName << "RegEncodingTable);\n\n";
11061095

11071096
EmitRegMapping(OS, Regs, false);
11081097

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

1245+
// Emit the table of sub-register index sizes.
1246+
OS << "static const TargetRegisterInfo::SubRegCoveredBits "
1247+
"SubRegIdxRangeTable[] = {\n";
1248+
OS << " { " << (uint16_t)-1 << ", " << (uint16_t)-1 << " },\n";
1249+
for (const auto &Idx : SubRegIndices) {
1250+
OS << " { " << Idx.Offset << ", " << Idx.Size << " },\t// "
1251+
<< Idx.getName() << "\n";
1252+
}
1253+
OS << "};\n\n";
1254+
12561255
// Emit SubRegIndex lane masks, including 0.
12571256
OS << "\nstatic const LaneBitmask SubRegIndexLaneMaskTable[] = {\n "
12581257
"LaneBitmask::getAll(),\n";
@@ -1634,8 +1633,6 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
16341633
OS << "extern const char " << TargetName << "RegClassStrings[];\n";
16351634
OS << "extern const MCPhysReg " << TargetName << "RegUnitRoots[][2];\n";
16361635
OS << "extern const uint16_t " << TargetName << "SubRegIdxLists[];\n";
1637-
OS << "extern const MCRegisterInfo::SubRegCoveredBits " << TargetName
1638-
<< "SubRegIdxRanges[];\n";
16391636
OS << "extern const uint16_t " << TargetName << "RegEncodingTable[];\n";
16401637

16411638
EmitRegMappingTables(OS, Regs, true);
@@ -1646,7 +1643,8 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
16461643
" unsigned PC, unsigned HwMode)\n"
16471644
<< " : TargetRegisterInfo(&" << TargetName << "RegInfoDesc"
16481645
<< ", RegisterClasses, RegisterClasses+" << RegisterClasses.size() << ",\n"
1649-
<< " SubRegIndexNameTable, SubRegIndexLaneMaskTable,\n"
1646+
<< " SubRegIndexNameTable, SubRegIdxRangeTable, "
1647+
"SubRegIndexLaneMaskTable,\n"
16501648
<< " ";
16511649
printMask(OS, RegBank.CoveringLanes);
16521650
OS << ", RegClassInfos, VTLists, HwMode) {\n"
@@ -1661,7 +1659,6 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
16611659
<< " " << TargetName << "RegClassStrings,\n"
16621660
<< " " << TargetName << "SubRegIdxLists,\n"
16631661
<< " " << SubRegIndicesSize + 1 << ",\n"
1664-
<< " " << TargetName << "SubRegIdxRanges,\n"
16651662
<< " " << TargetName << "RegEncodingTable);\n\n";
16661663

16671664
EmitRegMapping(OS, Regs, true);

0 commit comments

Comments
 (0)