[llvm] f78d143 - [MCA] Fix -mcpu=help flag (#173399)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 30 01:16:04 PST 2025
Author: Amina Chabane
Date: 2025-12-30T09:16:00Z
New Revision: f78d143ecd28f432ecb2066d04b1406301f1579d
URL: https://github.com/llvm/llvm-project/commit/f78d143ecd28f432ecb2066d04b1406301f1579d
DIFF: https://github.com/llvm/llvm-project/commit/f78d143ecd28f432ecb2066d04b1406301f1579d.diff
LOG: [MCA] Fix -mcpu=help flag (#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.
Added:
llvm/test/tools/llvm-mca/mcpu-help.test
Modified:
llvm/tools/llvm-mca/llvm-mca.cpp
Removed:
################################################################################
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..55168b4080c0c
--- /dev/null
+++ b/llvm/test/tools/llvm-mca/mcpu-help.test
@@ -0,0 +1,11 @@
+# REQUIRES: aarch64-registered-target
+
+# RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=help %t.no-input 2>&1 | FileCheck %s
+
+// 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:
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