Files
llvm-project/mlir/lib/ExecutionEngine/ArmSMEStubs.cpp
Benjamin Maxwell b37a607933 [compiler-rt] Don't provide __arm_sme_state for baremetal targets (#191434)
Previously, we required baremetal runtimes to implement an undocumented
`__aarch64_sme_accessible` hook to check if SME is available (as
checking CPU features may vary across targets).

This allowed us to provide a generic `__arm_sme_state` implementation
but caused some friction for toolchains that depend on compiler-rt.

This patch instead removes the implementation of `__arm_sme_state` for
baremetal. This makes it the responsibility of the runtime (e.g. libc)
to provide this function for baremetal targets.

The requirements of this function are documented in the AAPCS64:
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#811__arm_sme_state

All other SME ABI rountines are still provided by compiler-rt.
2026-04-20 10:00:18 +01:00

59 lines
2.0 KiB
C++

//===- ArmSMEStub.cpp - ArmSME ABI routine stubs --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <iostream>
#if (defined(_WIN32) || defined(__CYGWIN__))
#ifndef MLIR_ARMSMEABISTUBS_EXPORTED
#ifdef mlir_arm_sme_abi_stubs_EXPORTS
// We are building this library
#define MLIR_ARMSMEABISTUBS_EXPORTED __declspec(dllexport)
#else
// We are using this library
#define MLIR_ARMSMEABISTUBS_EXPORTED __declspec(dllimport)
#endif // mlir_arm_sme_abi_stubs_EXPORTS
#endif // MLIR_ARMSMEABISTUBS_EXPORTED
#else
#define MLIR_ARMSMEABISTUBS_EXPORTED \
__attribute__((visibility("default"))) LLVM_ATTRIBUTE_WEAK
#endif // (defined(_WIN32) || defined(__CYGWIN__))
// The actual implementation of these routines is in:
// compiler-rt/lib/builtins/aarch64/sme-abi.S. These stubs allow the current
// ArmSME tests to run without depending on compiler-rt. This works as we don't
// rely on nested ZA-enabled calls at the moment. The use of these stubs can be
// overridden by setting the ARM_SME_ABI_ROUTINES_SHLIB CMake cache variable to
// a path to an alternate implementation.
extern "C" {
struct sme_state {
int64_t x0;
int64_t x1;
};
sme_state MLIR_ARMSMEABISTUBS_EXPORTED __arm_sme_state() {
std::cerr << "[warning] __arm_sme_state() stubbed!\n";
return sme_state{};
}
void MLIR_ARMSMEABISTUBS_EXPORTED __arm_tpidr2_restore() {
std::cerr << "[warning] __arm_tpidr2_restore() stubbed!\n";
}
void MLIR_ARMSMEABISTUBS_EXPORTED __arm_tpidr2_save() {
std::cerr << "[warning] __arm_tpidr2_save() stubbed!\n";
}
void MLIR_ARMSMEABISTUBS_EXPORTED __arm_za_disable() {
std::cerr << "[warning] __arm_za_disable() stubbed!\n";
}
}