From 144dffc4c8561608ef3ee706fb2066a34cbe0fb8 Mon Sep 17 00:00:00 2001 From: Liam Semeria Date: Thu, 17 Sep 2026 13:14:28 +0200 Subject: [PATCH] mlir: specify the mtriple in llvm target --- .../mlir/MlirTarget/MlirLLVMTarget.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/xtc/backends/mlir/MlirTarget/MlirLLVMTarget.py b/src/xtc/backends/mlir/MlirTarget/MlirLLVMTarget.py index dd9ca109..01ef7a28 100644 --- a/src/xtc/backends/mlir/MlirTarget/MlirLLVMTarget.py +++ b/src/xtc/backends/mlir/MlirTarget/MlirLLVMTarget.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2024-2026 The XTC Project Authors # +import subprocess + from typing_extensions import override from xtc.utils.host_tools import target_triple @@ -80,16 +82,33 @@ def cmd_opt(self): + [f"-march={self._config.arch}", f"--mcpu={self._config.cpu}"] ) + @property + def _native_target_triple(self) -> str | None: + # llc's implicit default triple isn't reliable across installs; + # ask the install directly instead. + cached = getattr(self, "_native_target_triple_cache", None) + if cached is not None: + return cached or None + llvm_config = f"{self._config.llvm_install_dir}/bin/llvm-config" + try: + result = self.execute_command(cmd=[llvm_config, "--host-target"]) + triple = result.stdout.strip() if result.returncode == 0 else "" + except (OSError, subprocess.SubprocessError): + triple = "" + self._native_target_triple_cache = triple + return triple or None + @property def cmd_llc(self): llc = [f"{self._config.llvm_install_dir}/bin/llc"] if self._config.arch == "native": llc_arch = [f"--mcpu={self._config.cpu}"] + triple = self._native_target_triple else: llc_arch = [f"-march={self._config.arch}", f"--mcpu={self._config.cpu}"] triple = target_triple(self._config.arch) - if triple: - llc_arch += [f"--mtriple={triple}"] + if triple: + llc_arch += [f"--mtriple={triple}"] return llc + llc_opts + llc_arch @property