[llvm] 67beebf - [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to CodeGenProcModel (#92032)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 14:15:23 PDT 2024
Author: Michael Maitland
Date: 2024-05-14T17:15:19-04:00
New Revision: 67beebfcb9a267cc1e443aa4d3788adbfcf02639
URL: https://github.com/llvm/llvm-project/commit/67beebfcb9a267cc1e443aa4d3788adbfcf02639
DIFF: https://github.com/llvm/llvm-project/commit/67beebfcb9a267cc1e443aa4d3788adbfcf02639.diff
LOG: [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to CodeGenProcModel (#92032)
SubtargetEmitter::GenSchedClassTables takes a CodeGenProcModel, but
calls hasReadOfWrite which loops over all ProcModels. We move
hasReadOfWrite to CodeGenProcModel and remove the loop over all
ProcModels. This leads to a 144% speedup on the RISC-V backend of our
downstream.
Added:
Modified:
llvm/utils/TableGen/Common/CodeGenSchedule.cpp
llvm/utils/TableGen/Common/CodeGenSchedule.h
llvm/utils/TableGen/SubtargetEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index 0e81623a6aa38..2ec0812320d14 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -746,18 +746,6 @@ unsigned CodeGenSchedModels::getSchedRWIdx(const Record *Def,
return I == RWVec.end() ? 0 : std::distance(RWVec.begin(), I);
}
-bool CodeGenSchedModels::hasReadOfWrite(Record *WriteDef) const {
- for (auto &ProcModel : ProcModels) {
- const RecVec &RADefs = ProcModel.ReadAdvanceDefs;
- for (auto &RADef : RADefs) {
- RecVec ValidWrites = RADef->getValueAsListOfDefs("ValidWrites");
- if (is_contained(ValidWrites, WriteDef))
- return true;
- }
- }
- return false;
-}
-
static void splitSchedReadWrites(const RecVec &RWDefs, RecVec &WriteDefs,
RecVec &ReadDefs) {
for (Record *RWDef : RWDefs) {
@@ -2226,6 +2214,15 @@ bool CodeGenProcModel::isUnsupported(const CodeGenInstruction &Inst) const {
return false;
}
+bool CodeGenProcModel::hasReadOfWrite(Record *WriteDef) const {
+ for (auto &RADef : ReadAdvanceDefs) {
+ RecVec ValidWrites = RADef->getValueAsListOfDefs("ValidWrites");
+ if (is_contained(ValidWrites, WriteDef))
+ return true;
+ }
+ return false;
+}
+
#ifndef NDEBUG
void CodeGenProcModel::dump() const {
dbgs() << Index << ": " << ModelName << " "
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.h b/llvm/utils/TableGen/Common/CodeGenSchedule.h
index 61980e7e196e5..10ec7f41f56ff 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.h
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.h
@@ -277,6 +277,9 @@ struct CodeGenProcModel {
bool isUnsupported(const CodeGenInstruction &Inst) const;
+ // Return true if the given write record is referenced by a ReadAdvance.
+ bool hasReadOfWrite(Record *WriteDef) const;
+
#ifndef NDEBUG
void dump() const;
#endif
@@ -536,9 +539,6 @@ class CodeGenSchedModels {
unsigned getSchedRWIdx(const Record *Def, bool IsRead) const;
- // Return true if the given write record is referenced by a ReadAdvance.
- bool hasReadOfWrite(Record *WriteDef) const;
-
// Get a SchedClass from its index.
CodeGenSchedClass &getSchedClass(unsigned Idx) {
assert(Idx < SchedClasses.size() && "bad SchedClass index");
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index b6b7641cfb929..9e32d2de19b2c 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1122,10 +1122,8 @@ void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name);
// If this Write is not referenced by a ReadAdvance, don't distinguish it
// from other WriteLatency entries.
- if (!SchedModels.hasReadOfWrite(
- SchedModels.getSchedWrite(WriteID).TheDef)) {
+ if (!ProcModel.hasReadOfWrite(SchedModels.getSchedWrite(WriteID).TheDef))
WriteID = 0;
- }
WLEntry.WriteResourceID = WriteID;
for (unsigned WS : WriteSeq) {
More information about the llvm-commits
mailing list