[Mlir-commits] [mlir] [mlir][ArmSME] Make use of backend function attributes for enabling ZA storage (PR #71044)

Cullen Rhodes llvmlistbot at llvm.org
Fri Nov 3 03:01:10 PDT 2023


================
@@ -177,6 +178,39 @@ if(LLVM_ENABLE_PIC)
     target_link_options(mlir_async_runtime PRIVATE "-Wl,-exclude-libs,ALL")
   endif()
 
+  if (MLIR_RUN_ARM_SME_TESTS)
+    if (NOT DEFINED LLVM_MAIN_SRC_DIR)
+      message(FATAL_ERROR "LLVM_MAIN_SRC_DIR must be provided to build the ArmSME runtime.")
+    endif()
+
+    if (NOT DEFINED MLIR_ARM_SME__CAN_ASSEMBLE_ARM_SME)
+      # This should work on an AArch64 host with a recent version of clang.
+      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/has_arm_sme_check.S
+      ".arch armv9-a+sme
+      .global main
+      .type   main, %function
+      main: smstart
+      .size   main, .-main")
+      try_compile(MLIR_ARM_SME__CAN_ASSEMBLE_ARM_SME ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/has_arm_sme_check.S)
+    endif()
+
+    if (NOT MLIR_ARM_SME__CAN_ASSEMBLE_ARM_SME)
+      message(FATAL_ERROR "Host compiler must be able to assemble AArch64 SME instructions to build the ArmSME runtime.")
+    endif()
+
+    # FIXME: This is very far from ideal, but enabling compiler-rt in the main
----------------
c-rhodes wrote:

I managed to build a minimal (aarch64 builtins only) standalone compiler-rt on aarch64 with the following:
```
# Get recent clang with SME support. This is the most recent but older versions (within reason) should work as well.
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/clang+llvm-17.0.4-aarch64-linux-gnu.tar.xz
tar xvf clang+llvm-17.0.4-aarch64-linux-gnu.tar.xz

cd <path-to-llvm-project>

cmake -G Ninja \
  -S compiler-rt -B build-compiler-rt \
  -DCMAKE_C_COMPILER=<path-to>/clang+llvm-17.0.4-aarch64-linux-gnu/bin/clang-17 \
  -DCMAKE_CXX_COMPILER=<path-to>/clang+llvm-17.0.4-aarch64-linux-gnu/bin/clang++ \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=<install-path> \
  -DLLVM_CMAKE_DIR=cmake \
  -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
  -DCMAKE_C_COMPILER_TARGET=aarch64-linux-gnu \
  -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
  -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
  -DCOMPILER_RT_BUILD_MEMPROF=OFF \
  -DCOMPILER_RT_BUILD_ORC=OFF \
  -DCOMPILER_RT_BUILD_PROFILE=OFF \
  -DCOMPILER_RT_BUILD_SANITIZERS=OFF \
  -DCOMPILER_RT_BUILD_XRAY=OFF

ninja -C build-compiler-rt install

tree <install-path>
install
└── lib
    └── linux
        ├── clang_rt.crtbegin-aarch64.o
        ├── clang_rt.crtend-aarch64.o
        └── libclang_rt.builtins-aarch64.a
```

As far as I can tell there's three approaches here:

1. Build compiler-rt together with llvm+clang+mlir.
2. Build standalone compiler-rt separately (as above).
3. Build minimal SME runtime from sources when building llvm+mlir (as you're doing here).

All options require recent host toolchain with SME support.

Options 1 and 3 the runtime is integrated into normal build. I guess for both these options it wouldn't be necessary to add a CMake flag to specify the path to the runtime. Option 2 the runtime is built separately and a CMake flag would be necessary.

Options 1 and 3 may require updating existing build to update host toolchain if current doesn't support SME. Option 2 existing builds wouldn't need to change, except for adding the CMake flag with path to runtime lib.

Option 1 requires building Clang. I like this option the least, it requires building much more than we need as you say.

Comparing options 2 and 3. Option 2 requires fewer changes to MLIR, most (all?) of the changes in this CMake file could be removed? Option 2 would also be insulated from changes to the SME runtime implementation in compiler-rt if it were to ever change.

Food for thought. I'm gravitating towards Option 2, let us know if I've missed anything or what you think.

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


More information about the Mlir-commits mailing list