Skip to content

Commit e19261f

Browse files
authored
[TableGen] Add a SmallPtrSet to track WriteRes that are referenced by some ReadAdvance. NFC (#124160)
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 0b7cbd2 commit e19261f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-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);
21822179
}
21832180

21842181
#ifndef NDEBUG

llvm/utils/TableGen/Common/CodeGenSchedule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/DenseMap.h"
2020
#include "llvm/ADT/DenseSet.h"
2121
#include "llvm/ADT/STLExtras.h"
22+
#include "llvm/ADT/SmallPtrSet.h"
2223
#include "llvm/ADT/StringRef.h"
2324
#include "llvm/TableGen/Record.h"
2425
#include "llvm/TableGen/SetTheory.h"
@@ -250,6 +251,9 @@ struct CodeGenProcModel {
250251
// Map from the ReadType field to the parent ReadAdvance record.
251252
DenseMap<const Record *, const Record *> ReadAdvanceMap;
252253

254+
// Set of WriteRes that are referenced by a ReadAdvance.
255+
SmallPtrSet<const Record *, 8> ReadOfWriteSet;
256+
253257
// Per-operand machine model resources associated with this processor.
254258
ConstRecVec ProcResourceDefs;
255259

0 commit comments

Comments
 (0)