Skip to content

[TableGen][MCSched] Update error messages on the range of Acquire/ReleaseAtCycle #131908

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

Conversation

mshockwave
Copy link
Member

I was looking at the value range of AcquireAtCycle / ReleaseAtCycle, and I noticed that while the TableGen error messages said AcquireAtCycle has to be less than ReleaseAtCycle, in reality they are actually allowed to be the same. This patch fixes it and add more test cases.

@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-tablegen

Author: Min-Yih Hsu (mshockwave)

Changes

I was looking at the value range of AcquireAtCycle / ReleaseAtCycle, and I noticed that while the TableGen error messages said AcquireAtCycle has to be less than ReleaseAtCycle, in reality they are actually allowed to be the same. This patch fixes it and add more test cases.


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

2 Files Affected:

  • (modified) llvm/test/TableGen/AcquireAtCycle.td (+11-2)
  • (modified) llvm/utils/TableGen/SubtargetEmitter.cpp (+1-1)
diff --git a/llvm/test/TableGen/AcquireAtCycle.td b/llvm/test/TableGen/AcquireAtCycle.td
index d9d4ccef54769..d1b0a65b5057b 100644
--- a/llvm/test/TableGen/AcquireAtCycle.td
+++ b/llvm/test/TableGen/AcquireAtCycle.td
@@ -26,6 +26,7 @@ def ResX2 : ProcResource<1>; // X2
 let OutOperandList = (outs), InOperandList = (ins) in {
   def Inst_A : Instruction;
   def Inst_B : Instruction;
+  def Inst_C : Instruction;
 }
 
 let CompleteModel = 0 in {
@@ -34,6 +35,7 @@ let CompleteModel = 0 in {
 
 def WriteInst_A : SchedWrite;
 def WriteInst_B : SchedWrite;
+def WriteInst_C : SchedWrite;
 
 let SchedModel = SchedModel_A in {
 // Check the generated data when there are no semantic issues.
@@ -49,9 +51,15 @@ def : WriteRes<WriteInst_A, [ResX0, ResX1, ResX2]> {
 }
 def : WriteRes<WriteInst_B, [ResX2]> {
 // If unspecified, AcquireAtCycle is set to 0.
-// CORRECT-NEXT: { 3, 1, 0} // #4
+// CORRECT-NEXT: { 3, 1, 0}, // #4
     let ReleaseAtCycles = [1];
 }
+def : WriteRes<WriteInst_C, [ResX0]> {
+// Both AcquireAtCycle and ReleaseAtCycle are allowed
+// to be zero at the same time.
+// CORRECT-NEXT: { 1, 0, 0} // #5
+    let ReleaseAtCycles = [0];
+}
 #endif // CORRECT
 
 #ifdef WRONG_SIZE
@@ -63,7 +71,7 @@ def : WriteRes<WriteInst_A, [ResX0, ResX1, ResX2]> {
 #endif
 
 #ifdef WRONG_VALUE
-// WRONG_VALUE: AcquireAtCycle.td:[[@LINE+1]]:1: error: Inconsistent resource cycles: AcquireAtCycles < ReleaseAtCycles must hold
+// WRONG_VALUE: AcquireAtCycle.td:[[@LINE+1]]:1: error: Inconsistent resource cycles: AcquireAtCycles <= ReleaseAtCycles must hold
 def : WriteRes<WriteInst_A, [ResX0, ResX1, ResX2]> {
     let ReleaseAtCycles = [2, 4, 3];
     let AcquireAtCycles = [0, 1, 8];
@@ -80,6 +88,7 @@ def : WriteRes<WriteInst_A, [ResX0]> {
 
 def : InstRW<[WriteInst_A], (instrs Inst_A)>;
 def : InstRW<[WriteInst_B], (instrs Inst_B)>;
+def : InstRW<[WriteInst_C], (instrs Inst_C)>;
 }
 
 def ProcessorA: ProcessorModel<"ProcessorA", SchedModel_A, []>;
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index c398b6f9bf7cd..8d2fc99f84670 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1245,7 +1245,7 @@ void SubtargetEmitter::genSchedClassTables(const CodeGenProcModel &ProcModel,
             PrintFatalError(
                 WriteRes->getLoc(),
                 Twine("Inconsistent resource cycles: AcquireAtCycles "
-                      "< ReleaseAtCycles must hold."));
+                      "<= ReleaseAtCycles must hold."));
           }
           if (AcquireAtCycles[PRIdx] < 0) {
             PrintFatalError(WriteRes->getLoc(),

@mshockwave
Copy link
Member Author

ping

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

@mshockwave mshockwave merged commit 7fa104e into llvm:main Mar 24, 2025
11 checks passed
@mshockwave mshockwave deleted the patch/tblgen-acquire-at-cycle-invariant branch March 24, 2025 20:42
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.

3 participants