[llvm] Mcpu check fix - buildbot failure (PR #173995)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 30 07:16:27 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Amina Chabane (Amichaxx)

<details>
<summary>Changes</summary>

#<!-- -->173399 failed on buildbot llvm-clang-ubuntu-x-aarch64-pauth. This patch aims to rectify this.

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


2 Files Affected:

- (added) llvm/test/tools/llvm-mca/AArch64/mcpu-help.test (+11) 
- (modified) llvm/tools/llvm-mca/llvm-mca.cpp (+45-15) 


``````````diff
diff --git a/llvm/test/tools/llvm-mca/AArch64/mcpu-help.test b/llvm/test/tools/llvm-mca/AArch64/mcpu-help.test
new file mode 100644
index 0000000000000..55168b4080c0c
--- /dev/null
+++ b/llvm/test/tools/llvm-mca/AArch64/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..fcd85a489736f 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -392,16 +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());
-
   // Package up features to be passed to target/subtarget
   std::string FeaturesStr;
   if (MATTRS.size()) {
@@ -411,16 +401,56 @@ int main(int argc, char **argv) {
     FeaturesStr = Features.getString();
   }
 
-  std::unique_ptr<MCSubtargetInfo> STI(
-      TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr));
-  if (!STI) {
-    WithColor::error() << "unable to create subtarget info\n";
-    return 1;
+  auto CreateSubtargetInfo = [&](StringRef CPU) {
+    return std::unique_ptr<MCSubtargetInfo>(
+        TheTarget->createMCSubtargetInfo(TheTriple, CPU, FeaturesStr));
+  };
+
+  std::unique_ptr<MCSubtargetInfo> STI;
+  if (MCPU == "native") {
+    std::string HostCPU = std::string(llvm::sys::getHostCPUName());
+    STI = CreateSubtargetInfo("");
+    if (!STI) {
+      WithColor::error() << "unable to create subtarget info\n";
+      return 1;
+    }
+    if (!HostCPU.empty() && STI->isCPUStringValid(HostCPU)) {
+      // Only utilise the detected host CPU when it exists for the requested triple.
+      STI = CreateSubtargetInfo(HostCPU);
+      if (!STI) {
+        WithColor::error() << "unable to create subtarget info\n";
+        return 1;
+      }
+      MCPU = HostCPU;
+    } else {
+      MCPU.clear();
+    }
+  } else {
+    STI = CreateSubtargetInfo(MCPU);
+    if (!STI) {
+      WithColor::error() << "unable to create subtarget info\n";
+      return 1;
+    }
   }
 
+  if (MCPU.empty())
+    // MCPU being empty here means the target default was selected above,
+    // which avoids forwarding incompatible host CPUs when cross-compiling.
+    MCPU = std::string(STI->getCPU());
+
+  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"

``````````

</details>


https://github.com/llvm/llvm-project/pull/173995


More information about the llvm-commits mailing list