[llvm] [MCA] Fix -mcpu=help flag (PR #173399)

Amina Chabane via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 24 02:09:56 PST 2025


https://github.com/Amichaxx updated https://github.com/llvm/llvm-project/pull/173399

>From 8fa1001a2bc103faec8d45b9544463c8f31e0ed1 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Mon, 22 Dec 2025 14:20:00 +0000
Subject: [PATCH 1/3] [MCA] Fix -mcpu=help flag

Previously, using the 'mcpu=help' flag would require an empty stdin to be passed to print the CPU/Features list.

This patch moves the MemoryBuffer::getFileOrSTDIN call below an early return.

A test mcpu-help.test is included which tests the flag with a missing file. Previously, this would have resulted in an error with
no outputted help list, but now provides the help list and ignores the missing file input.
---
 llvm/test/tools/llvm-mca/mcpu-help.test |  9 +++++++++
 llvm/tools/llvm-mca/llvm-mca.cpp        | 17 ++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/tools/llvm-mca/mcpu-help.test

diff --git a/llvm/test/tools/llvm-mca/mcpu-help.test b/llvm/test/tools/llvm-mca/mcpu-help.test
new file mode 100644
index 0000000000000..b1eabaf791d4e
--- /dev/null
+++ b/llvm/test/tools/llvm-mca/mcpu-help.test
@@ -0,0 +1,9 @@
+# REQUIRES: aarch64-registered-target
+
+# RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=help %t.no-input 2>&1 | FileCheck %s
+
+// Ensures -mcpu=help prints target info without erroring on missing input.
+
+# CHECK: Available CPUs for this target:
+# CHECK: Available features for this target:
+# CHECK-NOT: error:
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index a64539c09b81e..c4aa081a095f8 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -392,13 +392,6 @@ int main(int argc, char **argv) {
   if (!TheTarget)
     return 1;
 
-  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename);
-  if (std::error_code EC = BufferPtr.getError()) {
-    WithColor::error() << InputFilename << ": " << EC.message() << '\n';
-    return 1;
-  }
-
   if (MCPU == "native")
     MCPU = std::string(llvm::sys::getHostCPUName());
 
@@ -418,9 +411,19 @@ int main(int argc, char **argv) {
     return 1;
   }
 
+  if (MCPU == "help")
+    return 0;
+
   if (!STI->isCPUStringValid(MCPU))
     return 1;
 
+  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
+      MemoryBuffer::getFileOrSTDIN(InputFilename);
+  if (std::error_code EC = BufferPtr.getError()) {
+    WithColor::error() << InputFilename << ": " << EC.message() << '\n';
+    return 1;
+  }
+
   if (!STI->getSchedModel().hasInstrSchedModel()) {
     WithColor::error()
         << "unable to find instruction-level scheduling information for"

>From c72eb9ab0b1b7d2e39c4ff2844f018f6454ae7f1 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Tue, 23 Dec 2025 17:27:30 +0000
Subject: [PATCH 2/3] wip

---
 llvm/test/tools/llvm-mca/mcpu-help.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-mca/mcpu-help.test b/llvm/test/tools/llvm-mca/mcpu-help.test
index b1eabaf791d4e..2cb1be660f65f 100644
--- a/llvm/test/tools/llvm-mca/mcpu-help.test
+++ b/llvm/test/tools/llvm-mca/mcpu-help.test
@@ -2,7 +2,7 @@
 
 # RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=help %t.no-input 2>&1 | FileCheck %s
 
-// Ensures -mcpu=help prints target info without erroring on missing input.
+// Ensures -mcpu=help still prints the CPU/features lists even when the input file after the flag is nonexistent.
 
 # CHECK: Available CPUs for this target:
 # CHECK: Available features for this target:

>From ff8eea258e9172f369cc8ff9855f2069c329ffa9 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Wed, 24 Dec 2025 10:09:42 +0000
Subject: [PATCH 3/3] Asserts CPUs in mcpu-help.test

---
 llvm/test/tools/llvm-mca/mcpu-help.test | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/test/tools/llvm-mca/mcpu-help.test b/llvm/test/tools/llvm-mca/mcpu-help.test
index 2cb1be660f65f..55168b4080c0c 100644
--- a/llvm/test/tools/llvm-mca/mcpu-help.test
+++ b/llvm/test/tools/llvm-mca/mcpu-help.test
@@ -5,5 +5,7 @@
 // Ensures -mcpu=help still prints the CPU/features lists even when the input file after the flag is nonexistent.
 
 # CHECK: Available CPUs for this target:
+# CHECK: a64fx           - Select the a64fx processor.
+# CHECK: ampere1         - Select the ampere1 processor.
 # CHECK: Available features for this target:
 # CHECK-NOT: error:



More information about the llvm-commits mailing list