diff options
author | Tue Ly <lntue.h@gmail.com> | 2022-05-08 20:47:08 +0300 |
---|---|---|
committer | Tue Ly <lntue@google.com> | 2022-06-03 08:21:20 +0300 |
commit | 614567a7bf4a7a4c2570ad9a499b77155dfb54ce (patch) | |
tree | d166f692528f18a441e583835588aa81f42f16b9 /libc/cmake/modules/LLVMLibCObjectRules.cmake | |
parent | 78b16ccf2b5c4ba4ebd7f1e2a2fc1dcad0e1a343 (diff) |
[libc] Automatically add -mfma flag for architectures supporting FMA.
Detect if the architecture supports FMA instructions and if
the targets depend on fma.
Reviewed By: gchatelet
Differential Revision: https://reviews.llvm.org/D123615
Diffstat (limited to 'libc/cmake/modules/LLVMLibCObjectRules.cmake')
-rw-r--r-- | libc/cmake/modules/LLVMLibCObjectRules.cmake | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index c73a2d37c1aa..85a8c542ea7f 100644 --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -1,6 +1,14 @@ set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY") -function(_get_common_compile_options output_var) +function(_get_common_compile_options output_var flags) + list(FIND flags ${FMA_OPT_FLAG} fma) + if(${fma} LESS 0) + list(FIND flags "${FMA_OPT_FLAG}__ONLY" fma) + endif() + if((${fma} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "FMA")) + set(ADD_FMA_FLAG TRUE) + endif() + set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN}) if(NOT ${LIBC_TARGET_OS} STREQUAL "windows") set(compile_options ${compile_options} -fpie -ffreestanding -fno-builtin) @@ -10,9 +18,15 @@ function(_get_common_compile_options output_var) list(APPEND compile_options "-fno-unwind-tables") list(APPEND compile_options "-fno-asynchronous-unwind-tables") list(APPEND compile_options "-fno-rtti") + if(ADD_FMA_FLAG) + list(APPEND compile_options "-mfma") + endif() elseif(MSVC) list(APPEND compile_options "/EHs-c-") list(APPEND compile_options "/GR-") + if(ADD_FMA_FLAG) + list(APPEND compile_options "/arch:AVX2") + endif() endif() set(${output_var} ${compile_options} PARENT_SCOPE) endfunction() @@ -54,7 +68,11 @@ function(create_object_library fq_target_name) ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR} ) - _get_common_compile_options(compile_options ${ADD_OBJECT_COMPILE_OPTIONS}) + _get_common_compile_options( + compile_options + "${ADD_OBJECT_FLAGS}" + ${ADD_OBJECT_COMPILE_OPTIONS} + ) target_compile_options(${fq_target_name} PRIVATE ${compile_options}) get_fq_deps_list(fq_deps_list ${ADD_OBJECT_DEPENDS}) @@ -276,7 +294,11 @@ function(create_entrypoint_object fq_target_name) set(ADD_ENTRYPOINT_OBJ_CXX_STANDARD ${CMAKE_CXX_STANDARD}) endif() - _get_common_compile_options(common_compile_options ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS}) + _get_common_compile_options( + common_compile_options + "${ADD_ENTRYPOINT_OBJ_FLAGS}" + ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS} + ) set(internal_target_name ${fq_target_name}.__internal__) set(include_dirs ${LIBC_BUILD_DIR}/include ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR}) get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS}) |