From 5426da8ffa4a6d55adab21026ce6ebe8f1cc6ef2 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 31 Mar 2022 00:43:28 -0700 Subject: [PATCH] [Support/BLAKE3] Re-enable building with the simd-optimized implementations, v2 * Support compiling with clang-5 * Check for `LLVM_DISABLE_ASSEMBLY_FILES` and have it set by `compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh` which wants to receive and process only bitcode files. --- .../symbolizer/scripts/build_symbolizer.sh | 1 + llvm/lib/Support/BLAKE3/CMakeLists.txt | 48 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh index 599f063b45c9..196a876a6e7e 100755 --- a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh +++ b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh @@ -140,6 +140,7 @@ if [[ ! -d ${LLVM_BUILD} ]]; then -DLLVM_ENABLE_ZLIB=ON \ -DLLVM_ENABLE_TERMINFO=OFF \ -DLLVM_ENABLE_THREADS=OFF \ + -DLLVM_DISABLE_ASSEMBLY_FILES=ON \ $LLVM_SRC fi cd ${LLVM_BUILD} diff --git a/llvm/lib/Support/BLAKE3/CMakeLists.txt b/llvm/lib/Support/BLAKE3/CMakeLists.txt index 718dd6421648..4374a840c7e3 100644 --- a/llvm/lib/Support/BLAKE3/CMakeLists.txt +++ b/llvm/lib/Support/BLAKE3/CMakeLists.txt @@ -4,6 +4,28 @@ set(LLVM_BLAKE3_FILES blake3_portable.c ) +if (LLVM_DISABLE_ASSEMBLY_FILES) + set(CAN_USE_ASSEMBLER FALSE) +else() + set(CAN_USE_ASSEMBLER TRUE) +endif() + +# Some LLVM builders set "CC=ccache /path/to/clang" as environment variable, +# which confuses CMake thinking the assembler to use is the 'ccache' binary. +# These builders need to also set "ASM=/path/to/clang" in environment, or use +# LLVM_CCACHE_BUILD CMake variable instead, but until this happens check for +# this case and disable building the assembly files. +get_filename_component(ASM_BINARY ${CMAKE_ASM_COMPILER} NAME) +if (ASM_BINARY STREQUAL "ccache") + message(WARNING "CMake is set to use '${CMAKE_ASM_COMPILER}' as assembler " + "which is likely due to having 'CC=ccache /path/to/clang' in the environment. " + "Building the BLAKE3 SIMD-optimized assembly files is disabled, set " + "'ASM=/path/to/clang' as environment variable and do a clean re-configure, " + "or unset CC/CXX and configure with '-DLLVM_CCACHE_BUILD=YES' instead, " + "to correct this.") + set(CAN_USE_ASSEMBLER FALSE) +endif() + # The BLAKE3 team recommends using the assembly versions, from the README: # # "For each of the x86 SIMD instruction sets, four versions are available: @@ -11,13 +33,26 @@ set(LLVM_BLAKE3_FILES # version using C intrinsics. The assembly versions are generally # preferred. They perform better, they perform more consistently across # different compilers, and they build more quickly." -# FIXME: Figure out what is wrong with the builders when using the assembly files and neon. + if (MSVC) - enable_language(ASM_MASM) + check_symbol_exists(_M_X64 "" IS_X64) + check_symbol_exists(_M_ARM64 "" IS_ARM64) +else() + check_symbol_exists(__x86_64__ "" IS_X64) + check_symbol_exists(__aarch64__ "" IS_ARM64) + + if (IS_X64) + # Clang-6 needs this flag. + set_source_files_properties(blake3_avx512_x86-64_windows_gnu.S + PROPERTIES COMPILE_OPTIONS "-mavx512vl") + set_source_files_properties(blake3_avx512_x86-64_unix.S + PROPERTIES COMPILE_OPTIONS "-mavx512vl") + endif() endif() -if (FALSE)#CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") +if (IS_X64 AND CAN_USE_ASSEMBLER) if (MSVC) + enable_language(ASM_MASM) list(APPEND LLVM_BLAKE3_FILES blake3_sse2_x86-64_windows_msvc.asm blake3_sse41_x86-64_windows_msvc.asm @@ -41,14 +76,15 @@ if (FALSE)#CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") endif() endif() -if (FALSE)#CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch)") +if (IS_ARM64) list(APPEND LLVM_BLAKE3_FILES blake3_neon.c ) endif() -# FIXME: Figure out what is wrong with the builders when using the assembly files. -add_definitions(-DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_SSE2 -DBLAKE3_USE_NEON=0) +if (IS_X64 AND NOT CAN_USE_ASSEMBLER) + add_definitions(-DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_SSE2) +endif() add_library(LLVMSupportBlake3 OBJECT EXCLUDE_FROM_ALL ${LLVM_BLAKE3_FILES}) llvm_update_compile_flags(LLVMSupportBlake3)