Skip to content

[TableGen] Add a SmallPtrSet to track WriteRes that are referenced by some ReadAdvance. NFC #124160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Jan 23, 2025

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.

…me 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.
@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-tablegen

Author: Craig Topper (topperc)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/124160.diff

2 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+4-7)
  • (modified) llvm/utils/TableGen/Common/CodeGenSchedule.h (+3)
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index 8919a278f352bf..631b24ce2ad129 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -2129,13 +2129,15 @@ void CodeGenSchedModels::addWriteRes(const Record *ProcWriteResDef,
 void CodeGenSchedModels::addReadAdvance(const Record *ProcReadAdvanceDef,
                                         CodeGenProcModel &PM) {
   for (const Record *ValidWrite :
-       ProcReadAdvanceDef->getValueAsListOfDefs("ValidWrites"))
+       ProcReadAdvanceDef->getValueAsListOfDefs("ValidWrites")) {
     if (getSchedRWIdx(ValidWrite, /*IsRead=*/false) == 0)
       PrintFatalError(
           ProcReadAdvanceDef->getLoc(),
           "ReadAdvance referencing a ValidWrite that is not used by "
           "any instruction (" +
               ValidWrite->getName() + ")");
+    PM.ReadOfWriteSet.insert(ValidWrite);
+  }
 
   ConstRecVec &RADefs = PM.ReadAdvanceDefs;
   if (is_contained(RADefs, ProcReadAdvanceDef))
@@ -2173,12 +2175,7 @@ bool CodeGenProcModel::isUnsupported(const CodeGenInstruction &Inst) const {
 }
 
 bool CodeGenProcModel::hasReadOfWrite(const Record *WriteDef) const {
-  for (auto &RADef : ReadAdvanceDefs) {
-    ConstRecVec ValidWrites = RADef->getValueAsListOfDefs("ValidWrites");
-    if (is_contained(ValidWrites, WriteDef))
-      return true;
-  }
-  return false;
+  return ReadOfWriteSet.count(WriteDef) != 0;
 }
 
 #ifndef NDEBUG
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.h b/llvm/utils/TableGen/Common/CodeGenSchedule.h
index 5d5aa44d882e59..67979e7cbfe758 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.h
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.h
@@ -250,6 +250,9 @@ struct CodeGenProcModel {
   // Map from the ReadType field to the parent ReadAdvance record.
   DenseMap<const Record *, const Record *> ReadAdvanceMap;
 
+  // Set of WriteRes that are referenced by a ReadAdvance.
+  DenseSet<const Record *> ReadOfWriteSet;
+
   // Per-operand machine model resources associated with this processor.
   ConstRecVec ProcResourceDefs;
 

Copy link
Contributor

@michaelmaitland michaelmaitland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc topperc changed the title [TableGen] Add a DenseSet to track WriteRes that are referenced by some ReadAdvance. NFC [TableGen] Add a SmallPtrSet to track WriteRes that are referenced by some ReadAdvance. NFC Jan 23, 2025
Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc topperc merged commit e19261f into llvm:main Jan 23, 2025
6 of 7 checks passed
@topperc topperc deleted the pr/hasReadOfWrite branch January 23, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants