From: Guillaume Chatelet Date: Wed, 5 May 2021 15:52:42 +0000 (+0000) Subject: [libc] Normalize LIBC_TARGET_MACHINE X-Git-Tag: llvmorg-14-init~7547 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c2ece523d7ff74f3eeabce1b9685f3eaae8cff4;p=platform%2Fupstream%2Fllvm.git [libc] Normalize LIBC_TARGET_MACHINE Current implementation defines LIBC_TARGET_MACHINE with the use of CMAKE_SYSTEM_PROCESSOR. Unfortunately CMAKE_SYSTEM_PROCESSOR is OS dependent and can produce different results. An evidence of this is the various matchers used to detect whether the architecture is x86. This patch normalizes LIBC_TARGET_MACHINE and renames it LIBC_TARGET_ARCHITECTURE. I've added many architectures but we may want to limit ourselves to x86 and ARM. Differential Revision: https://reviews.llvm.org/D101524 --- diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index ff1a0c6..15a0b35 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -19,7 +19,8 @@ set(LIBC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Define libc destinat set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS) -set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR}) +# Defines LIBC_TARGET_ARCHITECTURE and associated macros. +include(LLVMLibCArchitectures) # Check --print-resource-dir to find the compiler resource dir if this flag # is supported by the compiler. @@ -73,8 +74,8 @@ include(CMakeParseArguments) include(LLVMLibCRules) include(LLVMLibCCheckCpuFeatures) -include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt") -include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt") +include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt") +include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt") set(TARGET_ENTRYPOINT_NAME_LIST "") foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS) diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake new file mode 100644 index 0000000..8d49054 --- /dev/null +++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------ +# Architecture definitions +# ------------------------------------------------------------------------------ + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + set(LIBC_TARGET_ARCHITECTURE_IS_MIPS TRUE) + set(LIBC_TARGET_ARCHITECTURE "mips") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + set(LIBC_TARGET_ARCHITECTURE_IS_ARM TRUE) + set(LIBC_TARGET_ARCHITECTURE "arm") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + set(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 TRUE) + set(LIBC_TARGET_ARCHITECTURE "aarch64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)") + set(LIBC_TARGET_ARCHITECTURE_IS_X86 TRUE) + set(LIBC_TARGET_ARCHITECTURE "x86_64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + set(LIBC_TARGET_ARCHITECTURE_IS_POWER TRUE) + set(LIBC_TARGET_ARCHITECTURE "power") +else() + message(FATAL_ERROR "Unsupported processor ${CMAKE_SYSTEM_PROCESSOR}") +endif() diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake index 1b92b48..a44186e 100644 --- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake +++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake @@ -2,7 +2,7 @@ # Cpu features definition and flags # ------------------------------------------------------------------------------ -if(${LIBC_TARGET_MACHINE} MATCHES "x86|x86_64") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(ALL_CPU_FEATURES SSE SSE2 AVX AVX2 AVX512F) list(SORT ALL_CPU_FEATURES) endif() diff --git a/libc/config/linux/CMakeLists.txt b/libc/config/linux/CMakeLists.txt index 50e9837..e3a0018 100644 --- a/libc/config/linux/CMakeLists.txt +++ b/libc/config/linux/CMakeLists.txt @@ -3,9 +3,9 @@ add_gen_header( DEF_FILE syscall.h.def GEN_HDR syscall.h PARAMS - inline_syscalls=${LIBC_TARGET_MACHINE}/syscall.h.inc + inline_syscalls=${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc DATA_FILES - ${LIBC_TARGET_MACHINE}/syscall.h.inc + ${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc DEPENDS libc.src.__support.common ) diff --git a/libc/loader/linux/CMakeLists.txt b/libc/loader/linux/CMakeLists.txt index 5cb184a..4b8b0d9 100644 --- a/libc/loader/linux/CMakeLists.txt +++ b/libc/loader/linux/CMakeLists.txt @@ -56,16 +56,16 @@ function(add_loader_object name) ) endfunction() -if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE})) - message(STATUS "Skipping loader for target machine ${LIBC_TARGET_MACHINE}") +if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})) + message(STATUS "Skipping loader for target architecture ${LIBC_TARGET_ARCHITECTURE}") return() endif() -add_subdirectory(${LIBC_TARGET_MACHINE}) +add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) add_loader_object( crt1 ALIAS DEPENDS - .${LIBC_TARGET_MACHINE}.crt1 + .${LIBC_TARGET_ARCHITECTURE}.crt1 ) diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 1774139..50fc4a4 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -1,19 +1,19 @@ add_subdirectory(generic) -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}) - add_subdirectory(${LIBC_TARGET_MACHINE}) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) endif() function(add_math_entrypoint_object name) # We prefer machine specific implementation if available. Hence we check # that first and retrun early if we are able to add an alias target for the # machine specific implementation. - get_fq_target_name("${LIBC_TARGET_MACHINE}.${name}" fq_machine_specific_target_name) + get_fq_target_name("${LIBC_TARGET_ARCHITECTURE}.${name}" fq_machine_specific_target_name) if(TARGET ${fq_machine_specific_target_name}) add_entrypoint_object( ${name} ALIAS DEPENDS - .${LIBC_TARGET_MACHINE}.${name} + .${LIBC_TARGET_ARCHITECTURE}.${name} ) return() endif() diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index c31525a..351e942 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -211,16 +211,13 @@ endfunction() # ------------------------------------------------------------------------------ # include the relevant architecture specific implementations -if(${LIBC_TARGET_MACHINE} STREQUAL "x86_64") - set(LIBC_STRING_TARGET_ARCH "x86") - set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/x86/memcpy.cpp) -elseif(${LIBC_TARGET_MACHINE} STREQUAL "aarch64") - set(LIBC_STRING_TARGET_ARCH "aarch64") - set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/aarch64/memcpy.cpp) +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) + set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/${LIBC_TARGET_ARCHITECTURE}/memcpy.cpp) +elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64}) + set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/${LIBC_TARGET_ARCHITECTURE}/memcpy.cpp) #Disable tail merging as it leads to lower performance set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm --tail-merge-threshold=0") else() - set(LIBC_STRING_TARGET_ARCH ${LIBC_TARGET_MACHINE}) set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp) endif() @@ -237,7 +234,7 @@ function(add_memcpy memcpy_name) ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_memcpy(memcpy MARCH native) else() add_memcpy(memcpy) @@ -260,7 +257,7 @@ function(add_memset memset_name) ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_memset(memset MARCH native) else() add_memset(memset) @@ -284,7 +281,7 @@ function(add_bzero bzero_name) ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_bzero(bzero MARCH native) else() add_bzero(bzero) @@ -294,6 +291,6 @@ endif() # Add all other relevant implementations for the native target. # ------------------------------------------------------------------------------ -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_STRING_TARGET_ARCH}) - include(${LIBC_STRING_TARGET_ARCH}/CMakeLists.txt) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + include(${LIBC_TARGET_ARCHITECTURE}/CMakeLists.txt) endif() diff --git a/libc/src/string/aarch64/CMakeLists.txt b/libc/src/string/aarch64/CMakeLists.txt index 8430891..c673f5b 100644 --- a/libc/src/string/aarch64/CMakeLists.txt +++ b/libc/src/string/aarch64/CMakeLists.txt @@ -1 +1 @@ -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}") diff --git a/libc/src/string/x86/CMakeLists.txt b/libc/src/string/x86/CMakeLists.txt deleted file mode 100644 index c52057e..0000000 --- a/libc/src/string/x86/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") - -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") - -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") diff --git a/libc/src/string/x86_64/CMakeLists.txt b/libc/src/string/x86_64/CMakeLists.txt new file mode 100644 index 0000000..9d0dffa --- /dev/null +++ b/libc/src/string/x86_64/CMakeLists.txt @@ -0,0 +1,14 @@ +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") + +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") + +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") diff --git a/libc/src/string/x86/memcpy.cpp b/libc/src/string/x86_64/memcpy.cpp similarity index 100% rename from libc/src/string/x86/memcpy.cpp rename to libc/src/string/x86_64/memcpy.cpp diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt index 08a04c6..767bf34 100644 --- a/libc/src/threads/linux/CMakeLists.txt +++ b/libc/src/threads/linux/CMakeLists.txt @@ -3,9 +3,9 @@ add_gen_header( DEF_FILE thread_start_args.h.def GEN_HDR thread_start_args.h PARAMS - thread_start_args=${LIBC_TARGET_MACHINE}/thread_start_args.h.in + thread_start_args=${LIBC_TARGET_ARCHITECTURE}/thread_start_args.h.in DATA_FILES - ${LIBC_TARGET_MACHINE}/thread_start_args.h.in + ${LIBC_TARGET_ARCHITECTURE}/thread_start_args.h.in ) add_entrypoint_object( diff --git a/libc/test/config/linux/CMakeLists.txt b/libc/test/config/linux/CMakeLists.txt index fea3d0b..b449a33 100644 --- a/libc/test/config/linux/CMakeLists.txt +++ b/libc/test/config/linux/CMakeLists.txt @@ -1,5 +1,5 @@ add_libc_testsuite(libc_linux_tests) -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}) - add_subdirectory(${LIBC_TARGET_MACHINE}) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) endif() diff --git a/libc/test/loader/linux/CMakeLists.txt b/libc/test/loader/linux/CMakeLists.txt index 15d67a1..4284ea4 100644 --- a/libc/test/loader/linux/CMakeLists.txt +++ b/libc/test/loader/linux/CMakeLists.txt @@ -1,5 +1,5 @@ -if(NOT (EXISTS ${LIBC_SOURCE_DIR}/loader/linux/${LIBC_TARGET_MACHINE})) - message("Skipping loader tests for target machine ${LIBC_TARGET_MACHINE}.") +if(NOT (EXISTS ${LIBC_SOURCE_DIR}/loader/linux/${LIBC_TARGET_ARCHITECTURE})) + message("Skipping loader tests for target architecture ${LIBC_TARGET_ARCHITECTURE}.") return() endif() diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index be7518f..22ff6d6 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -976,7 +976,7 @@ add_fp_unittest( # from insufficient precision in MPFR calculations leading to # https://hal.archives-ouvertes.fr/hal-01091186/document. We will # renable after fixing the precision issue. -if(${LIBC_TARGET_MACHINE} MATCHES "x86_64") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_fp_unittest( sqrtl_test NEED_MPFR diff --git a/libc/test/utils/FPUtil/CMakeLists.txt b/libc/test/utils/FPUtil/CMakeLists.txt index 65cb677..c5315d3 100644 --- a/libc/test/utils/FPUtil/CMakeLists.txt +++ b/libc/test/utils/FPUtil/CMakeLists.txt @@ -1,4 +1,4 @@ -if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_MACHINE} MATCHES "i386|x86_64")) +if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_ARCHITECTURE_IS_X86})) add_libc_unittest( x86_long_double_test SRCS diff --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt index 43ee643..8156464a 100644 --- a/libc/utils/FPUtil/CMakeLists.txt +++ b/libc/utils/FPUtil/CMakeLists.txt @@ -1,11 +1,11 @@ -if(${LIBC_TARGET_MACHINE} MATCHES "^x86.*") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(LONG_DOUBLE_HDR LongDoubleBitsX86.h) else() set(LONG_DOUBLE_HDR) endif() -if(EXISTS ${LIBC_TARGET_MACHINE}) - set(FENV_IMPL ${LIBC_TARGET_MACHINE}/FEnv.h) +if(EXISTS ${LIBC_TARGET_ARCHITECTURE}) + set(FENV_IMPL ${LIBC_TARGET_ARCHITECTURE}/FEnv.h) else() set(FENV_IMPL DummyFEnv.h) endif()