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

Amina Chabane via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 23 09:25:32 PST 2025


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

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

- Moves the `MemoryBuffer::getFileOrSTDIN` call below an early return.
- Adds 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.

>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] [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"



More information about the llvm-commits mailing list