Skip to content

Commit f3cf5ca

Browse files
committed
[TableGen] Add a DenseSet to track WriteRes that are referenced by some ReadAdvance. NFC
Use this to remove a linear scan from CodeGenProcModel::hasReadOfWrite. This reduces build time of RISCVGenSubtargetInfo.inc on by machine from ~6 seconds to ~3 seconds.
1 parent 082b148 commit f3cf5ca

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/utils/TableGen/Common/CodeGenSchedule.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,13 +2129,15 @@ void CodeGenSchedModels::addWriteRes(const Record *ProcWriteResDef,
21292129
void CodeGenSchedModels::addReadAdvance(const Record *ProcReadAdvanceDef,
21302130
CodeGenProcModel &PM) {
21312131
for (const Record *ValidWrite :
2132-
ProcReadAdvanceDef->getValueAsListOfDefs("ValidWrites"))
2132+
ProcReadAdvanceDef->getValueAsListOfDefs("ValidWrites")) {
21332133
if (getSchedRWIdx(ValidWrite, /*IsRead=*/false) == 0)
21342134
PrintFatalError(
21352135
ProcReadAdvanceDef->getLoc(),
21362136
"ReadAdvance referencing a ValidWrite that is not used by "
21372137
"any instruction (" +
21382138
ValidWrite->getName() + ")");
2139+
PM.ReadOfWriteSet.insert(ValidWrite);
2140+
}
21392141

21402142
ConstRecVec &RADefs = PM.ReadAdvanceDefs;
21412143
if (is_contained(RADefs, ProcReadAdvanceDef))
@@ -2173,12 +2175,7 @@ bool CodeGenProcModel::isUnsupported(const CodeGenInstruction &Inst) const {
21732175
}
21742176

21752177
bool CodeGenProcModel::hasReadOfWrite(const Record *WriteDef) const {
2176-
for (auto &RADef : ReadAdvanceDefs) {
2177-
ConstRecVec ValidWrites = RADef->getValueAsListOfDefs("ValidWrites");
2178-
if (is_contained(ValidWrites, WriteDef))
2179-
return true;
2180-
}
2181-
return false;
2178+
return ReadOfWriteSet.count(WriteDef) != 0;
21822179
}
21832180

21842181
#ifndef NDEBUG

llvm/utils/TableGen/Common/CodeGenSchedule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ struct CodeGenProcModel {
250250
// Map from the ReadType field to the parent ReadAdvance record.
251251
DenseMap<const Record *, const Record *> ReadAdvanceMap;
252252

253+
// Set of WriteRes that are referenced by a ReadAdvance.
254+
DenseSet<const Record *> ReadOfWriteSet;
255+
253256
// Per-operand machine model resources associated with this processor.
254257
ConstRecVec ProcResourceDefs;
255258

0 commit comments

Comments
 (0)