Skip to content

[MCA] Use MCInstrAnalysis to analyse call/return instructions #123882

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 22, 2025

Conversation

wangpc-pp
Copy link
Contributor

The flag set in MCInstrDesc is not accurate and we should use
the result of MCInstrAnalysis.

@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2025

@llvm/pr-subscribers-backend-systemz

@llvm/pr-subscribers-tools-llvm-mca

Author: Pengcheng Wang (wangpc-pp)

Changes

The flag set in MCInstrDesc is not accurate and we should use
the result of MCInstrAnalysis.


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

1 Files Affected:

  • (modified) llvm/lib/MCA/InstrBuilder.cpp (+8-8)
diff --git a/llvm/lib/MCA/InstrBuilder.cpp b/llvm/lib/MCA/InstrBuilder.cpp
index 933ede71746e06..9304e6c57a3859 100644
--- a/llvm/lib/MCA/InstrBuilder.cpp
+++ b/llvm/lib/MCA/InstrBuilder.cpp
@@ -219,11 +219,10 @@ static void initializeUsedResources(InstrDesc &ID,
   });
 }
 
-static void computeMaxLatency(InstrDesc &ID, const MCInstrDesc &MCDesc,
-                              const MCSchedClassDesc &SCDesc,
-                              const MCSubtargetInfo &STI,
-                              unsigned CallLatency) {
-  if (MCDesc.isCall()) {
+static void computeMaxLatency(InstrDesc &ID, const MCSchedClassDesc &SCDesc,
+                              const MCSubtargetInfo &STI, unsigned CallLatency,
+                              bool IsCall) {
+  if (IsCall) {
     // We cannot estimate how long this call will take.
     // Artificially set an arbitrarily high latency.
     ID.MaxLatency = CallLatency;
@@ -599,7 +598,8 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
   ID->NumMicroOps = SCDesc.NumMicroOps;
   ID->SchedClassID = SchedClassID;
 
-  if (MCDesc.isCall() && FirstCallInst) {
+  bool IsCall = MCIA->isCall(MCI);
+  if (IsCall && FirstCallInst) {
     // We don't correctly model calls.
     WithColor::warning() << "found a call in the input assembly sequence.\n";
     WithColor::note() << "call instructions are not correctly modeled. "
@@ -607,7 +607,7 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
     FirstCallInst = false;
   }
 
-  if (MCDesc.isReturn() && FirstReturnInst) {
+  if (MCIA->isReturn(MCI) && FirstReturnInst) {
     WithColor::warning() << "found a return instruction in the input"
                          << " assembly sequence.\n";
     WithColor::note() << "program counter updates are ignored.\n";
@@ -615,7 +615,7 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
   }
 
   initializeUsedResources(*ID, SCDesc, STI, ProcResourceMasks);
-  computeMaxLatency(*ID, MCDesc, SCDesc, STI, CallLatency);
+  computeMaxLatency(*ID, SCDesc, STI, CallLatency, IsCall);
 
   if (Error Err = verifyOperands(MCDesc, MCI))
     return std::move(Err);

@topperc
Copy link
Collaborator

topperc commented Jan 22, 2025

Is this testable?

@wangpc-pp wangpc-pp force-pushed the main-mca-use-MCInstrAnalysis branch from 03a04f2 to 6c6435d Compare January 22, 2025 05:44
@wangpc-pp
Copy link
Contributor Author

Is this testable?

Yes, I added a precommit test and you can see the second commit.

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

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

LGTM

wangpc-pp added a commit that referenced this pull request Jan 22, 2025
Add MCA test for jump instructions.
The flag set in `MCInstrDesc` is not accurate and we should use
the result of `MCInstrAnalysis`.
@wangpc-pp wangpc-pp force-pushed the main-mca-use-MCInstrAnalysis branch from 6c6435d to e0f9ac8 Compare January 22, 2025 11:09
@wangpc-pp wangpc-pp merged commit 9d676e2 into llvm:main Jan 22, 2025
5 of 7 checks passed
@wangpc-pp wangpc-pp deleted the main-mca-use-MCInstrAnalysis branch January 22, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants