brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 81aa700 Raw
103 lines · plain
1#2#//===----------------------------------------------------------------------===//3#//4#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5#// See https://llvm.org/LICENSE.txt for license information.6#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7#//8#//===----------------------------------------------------------------------===//9#10 11# Determine the architecture from predefined compiler macros12# The architecture name can only contain alphanumeric characters and underscores (i.e., C identifier)13 14# void get_architecture(string* return_arch)15# - Returns the architecture in return_arch16function(libomp_get_architecture return_arch)17  set(detect_arch_src_txt "18    #if defined(__KNC__)19      #error ARCHITECTURE=mic20    #elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)21      #error ARCHITECTURE=x86_6422    #elif defined(__i386) || defined(__i386__) || defined(__IA32__) || defined(_M_I86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_)23      #error ARCHITECTURE=i38624    #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) ||  defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7M__)  || defined(__ARM_ARCH_7S__)25      #error ARCHITECTURE=arm26    #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__)  || defined(__ARM_ARCH_6Z__)  || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6ZK__)27      #error ARCHITECTURE=arm28    #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5E__)  || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)29      #error ARCHITECTURE=arm30    #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)31      #error ARCHITECTURE=arm32    #elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__)33      #error ARCHITECTURE=arm34    #elif defined(__ARM_ARCH_2__)35      #error ARCHITECTURE=arm36    #elif defined(__arm__) || defined(_M_ARM) || defined(_ARM)37      #error ARCHITECTURE=arm38    #elif defined(__ARM64_ARCH_8_32__)39      #error ARCHITECTURE=aarch64_3240    #elif defined(__aarch64__) || defined(_M_ARM64)41      #error ARCHITECTURE=aarch6442    #elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)43      #error ARCHITECTURE=ppc64le44    #elif defined(__powerpc64__)45      #error ARCHITECTURE=ppc6446    #elif defined(__powerpc__) && !defined(__powerpc64__)47      #error ARCHITECTURE=ppc48    #elif defined(__mips__) && defined(__mips64)49      #error ARCHITECTURE=mips6450    #elif defined(__mips__) && !defined(__mips64)51      #error ARCHITECTURE=mips52    #elif defined(__riscv) && __riscv_xlen == 6453      #error ARCHITECTURE=riscv6454    #elif defined(__loongarch__) && __loongarch_grlen == 6455      #error ARCHITECTURE=loongarch6456    #elif defined(__ve__)57      #error ARCHITECTURE=ve58    #elif defined(__s390x__)59      #error ARCHITECTURE=s390x60    #elif defined(__wasm32__)61      #error ARCHITECTURE=wasm3262    #elif defined(__sparcv9)63      #error ARCHITECTURE=sparcv964    #elif defined(__sparc)65      #error ARCHITECTURE=sparc66    #else67      #error ARCHITECTURE=UnknownArchitecture68    #endif69  ")70  # Write out ${detect_arch_src_txt} to a file within the cmake/ subdirectory71  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" ${detect_arch_src_txt})72 73  # Try to compile using the C Compiler.  It will always error out with an #error directive, so store error output to ${local_architecture}74  try_run(run_dummy compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" COMPILE_OUTPUT_VARIABLE local_architecture)75 76  # Match the important architecture line and store only that matching string in ${local_architecture}77  string(REGEX MATCH "ARCHITECTURE=([a-zA-Z0-9_]+)" local_architecture "${local_architecture}")78 79  # Get rid of the ARCHITECTURE= part of the string80  string(REPLACE "ARCHITECTURE=" "" local_architecture "${local_architecture}")81 82  # set the return value to the architecture detected (e.g., 32e, 32, arm, ppc64, etc.)83  set(${return_arch} "${local_architecture}" PARENT_SCOPE)84 85  # Remove ${detect_arch_src_txt} from cmake/ subdirectory86  file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c")87endfunction()88 89function(libomp_is_aarch64_a64fx return_is_aarch64_a64fx)90  set(is_aarch64_a64fx FALSE)91  if (EXISTS "/proc/cpuinfo")92    file(READ "/proc/cpuinfo" cpu_info_content)93    string(REGEX MATCH "CPU implementer[ \t]*: 0x46\n" cpu_implementer ${cpu_info_content})94    string(REGEX MATCH "CPU architecture[ \t]*: 8\n" cpu_architecture ${cpu_info_content})95 96    if (cpu_architecture AND cpu_implementer)97      set(is_aarch64_a64fx TRUE)98    endif()99  endif()100 101  set(${return_is_aarch64_a64fx} "${is_aarch64_a64fx}" PARENT_SCOPE)102endfunction(libomp_is_aarch64_a64fx)103