Skip to content

Commit f7f8bae

Browse files
authored
[TableGen][NFCI] Speed up generating *GenRegisterInfo.inc files on builds with expensive checks. (llvm#67340)
This is mostly AMDGPU-specific. When the expensive checks are enabled, generating of AMDGPUGenRegisterInfo.inc currently takes about 20 minutes on my machine for release+asserts builds, which effectively prevents such testing from regular use. This patch fixes this by reducing the time to about 2 minutes. Generation times for AMDGPUGenRegisterInfo.inc without expensive checks and other *GenRegisterInfo.inc files with and without the expensive checks remain approximately the same. The patch doesn't cause any changes in the contents of the generated files. The root cause of the current poor performance is that where glibcxx is used, enabling the expensive checks defines _GLIBCXX_DEBUG, which enables various consistency checks in the library. One such check is in std::binary_search() to make sure the range is ordered. As CodeGenRegisterClass::contains() relies on std::binary_search() and it is called very a large number of times from within CodeGenRegBank::inferMatchingSuperRegClass(), the libcxx checks heavily affect the runtimes.
1 parent fff1680 commit f7f8bae

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

llvm/utils/TableGen/CodeGenRegisters.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,8 +2297,8 @@ void CodeGenRegBank::inferSubClassWithSubReg(CodeGenRegisterClass *RC) {
22972297

22982298
void CodeGenRegBank::inferMatchingSuperRegClass(CodeGenRegisterClass *RC,
22992299
std::list<CodeGenRegisterClass>::iterator FirstSubRegRC) {
2300-
SmallVector<std::pair<const CodeGenRegister*,
2301-
const CodeGenRegister*>, 16> SSPairs;
2300+
DenseMap<const CodeGenRegister *, std::vector<const CodeGenRegister *>>
2301+
SubToSuperRegs;
23022302
BitVector TopoSigs(getNumTopoSigs());
23032303

23042304
// Iterate in SubRegIndex numerical order to visit synthetic indices last.
@@ -2310,12 +2310,12 @@ void CodeGenRegBank::inferMatchingSuperRegClass(CodeGenRegisterClass *RC,
23102310
continue;
23112311

23122312
// Build list of (Super, Sub) pairs for this SubIdx.
2313-
SSPairs.clear();
2313+
SubToSuperRegs.clear();
23142314
TopoSigs.reset();
23152315
for (const auto Super : RC->getMembers()) {
23162316
const CodeGenRegister *Sub = Super->getSubRegs().find(&SubIdx)->second;
23172317
assert(Sub && "Missing sub-register");
2318-
SSPairs.push_back(std::make_pair(Super, Sub));
2318+
SubToSuperRegs[Sub].push_back(Super);
23192319
TopoSigs.set(Sub->getTopoSig());
23202320
}
23212321

@@ -2334,16 +2334,20 @@ void CodeGenRegBank::inferMatchingSuperRegClass(CodeGenRegisterClass *RC,
23342334
continue;
23352335
// Compute the subset of RC that maps into SubRC.
23362336
CodeGenRegister::Vec SubSetVec;
2337-
for (unsigned i = 0, e = SSPairs.size(); i != e; ++i)
2338-
if (SubRC.contains(SSPairs[i].second))
2339-
SubSetVec.push_back(SSPairs[i].first);
2337+
for (const CodeGenRegister *R : SubRC.getMembers()) {
2338+
auto It = SubToSuperRegs.find(R);
2339+
if (It != SubToSuperRegs.end()) {
2340+
const std::vector<const CodeGenRegister *> &SuperRegs = It->second;
2341+
SubSetVec.insert(SubSetVec.end(), SuperRegs.begin(), SuperRegs.end());
2342+
}
2343+
}
23402344

23412345
if (SubSetVec.empty())
23422346
continue;
23432347

23442348
// RC injects completely into SubRC.
23452349
sortAndUniqueRegisters(SubSetVec);
2346-
if (SubSetVec.size() == SSPairs.size()) {
2350+
if (SubSetVec.size() == RC->getMembers().size()) {
23472351
SubRC.addSuperRegClass(&SubIdx, RC);
23482352
continue;
23492353
}

0 commit comments

Comments
 (0)