[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / compiler-rt / cmake / builtin-config-ix.cmake
blob1f63e158409ca49994b27fd9068db0e635b2786e
1 include(BuiltinTests)
2 include(CheckIncludeFiles)
3 include(CheckCSourceCompiles)
5 # Make all the tests only check the compiler
6 set(TEST_COMPILE_ONLY On)
8 # Check host compiler support for certain flags
9 builtin_check_c_compiler_flag(-fPIC                 COMPILER_RT_HAS_FPIC_FLAG)
10 builtin_check_c_compiler_flag(-fPIE                 COMPILER_RT_HAS_FPIE_FLAG)
11 builtin_check_c_compiler_flag(-fno-builtin          COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
12 builtin_check_c_compiler_flag(-std=c11              COMPILER_RT_HAS_STD_C11_FLAG)
13 builtin_check_c_compiler_flag(-fvisibility=hidden   COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG)
14 builtin_check_c_compiler_flag(-fomit-frame-pointer  COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG)
15 builtin_check_c_compiler_flag(-ffreestanding        COMPILER_RT_HAS_FFREESTANDING_FLAG)
16 builtin_check_c_compiler_flag(-fxray-instrument     COMPILER_RT_HAS_XRAY_COMPILER_FLAG)
17 builtin_check_c_compiler_flag(-fno-lto              COMPILER_RT_HAS_FNO_LTO_FLAG)
18 builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
19 builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
20 builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
21 builtin_check_c_compiler_flag(-Wno-pedantic         COMPILER_RT_HAS_WNO_PEDANTIC)
22 builtin_check_c_compiler_flag(-nogpulib             COMPILER_RT_HAS_NOGPULIB_FLAG)
23 builtin_check_c_compiler_flag(-flto                 COMPILER_RT_HAS_FLTO_FLAG)
24 builtin_check_c_compiler_flag(-fconvergent-functions COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG)
25 builtin_check_c_compiler_flag("-Xclang -mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG)
26 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
27 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
29 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
31 int foo(int x, int y) {
32  _Atomic int result = x * y;
33  return result;
37 builtin_check_c_compiler_source(COMPILER_RT_HAS_ASM_LSE
39 asm(\".arch armv8-a+lse\");
40 asm(\"cas w0, w1, [x2]\");
43 builtin_check_c_compiler_source(COMPILER_RT_HAS_AARCH64_SME
45 void foo(void)  __arm_streaming_compatible {
46   asm(\".arch armv9-a+sme\");
47   asm(\"smstart\");
51 check_include_files("sys/auxv.h"    COMPILER_RT_HAS_AUXV)
53 if(ANDROID)
54   set(OS_NAME "Android")
55 else()
56   set(OS_NAME "${CMAKE_SYSTEM_NAME}")
57 endif()
59 set(AMDGPU amdgcn)
60 set(ARM64 aarch64)
61 set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main)
62 set(AVR avr)
63 set(HEXAGON hexagon)
64 set(X86 i386)
65 set(X86_64 x86_64)
66 set(LOONGARCH64 loongarch64)
67 set(MIPS32 mips mipsel)
68 set(MIPS64 mips64 mips64el)
69 set(NVPTX nvptx64)
70 set(PPC32 powerpc powerpcspe)
71 set(PPC64 powerpc64 powerpc64le)
72 set(RISCV32 riscv32)
73 set(RISCV64 riscv64)
74 set(SPARC sparc)
75 set(SPARCV9 sparcv9)
76 set(WASM32 wasm32)
77 set(WASM64 wasm64)
78 set(VE ve)
80 if(APPLE)
81   set(ARM64 arm64 arm64e)
82   set(ARM32 armv7 armv7k armv7s)
83   set(X86_64 x86_64 x86_64h)
84 endif()
86 set(ALL_BUILTIN_SUPPORTED_ARCH
87   ${X86} ${X86_64} ${AMDGPU} ${ARM32} ${ARM64} ${AVR}
88   ${HEXAGON} ${MIPS32} ${MIPS64} ${NVPTX} ${PPC32} ${PPC64}
89   ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9}
90   ${WASM32} ${WASM64} ${VE} ${LOONGARCH64})
92 include(CompilerRTUtils)
93 include(CompilerRTDarwinUtils)
95 if(APPLE)
97   find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
98   find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
99   find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
100   find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
101   find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
102   find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
103   find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
104   find_darwin_sdk_dir(DARWIN_xrossim_SYSROOT xrsimulator)
105   find_darwin_sdk_dir(DARWIN_xros_SYSROOT xros)
107   # Get supported architecture from SDKSettings.
108   function(sdk_has_arch_support sdk_path os arch has_support)
109     execute_process(COMMAND
110         /usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
111       OUTPUT_VARIABLE SDK_SUPPORTED_ARCHS
112       RESULT_VARIABLE PLIST_ERROR
113       ERROR_QUIET)
114     if (PLIST_ERROR EQUAL 0 AND
115         SDK_SUPPORTED_ARCHS MATCHES " ${arch}\n")
116       message(STATUS "Found ${arch} support in ${sdk_path}/SDKSettings.plist")
117       set("${has_support}" On PARENT_SCOPE)
118     else()
119       message(STATUS "No ${arch} support in ${sdk_path}/SDKSettings.plist")
120       set("${has_support}" Off PARENT_SCOPE)
121     endif()
122   endfunction()
124   set(DARWIN_EMBEDDED_PLATFORMS)
125   set(DARWIN_osx_BUILTIN_MIN_VER 10.7)
126   set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
127       -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
128   set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
129   # Add support for arm64 macOS if available in SDK.
130   foreach(arch ${ARM64})
131     sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
132     if (MACOS_ARM_SUPPORT)
133      list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
134     endif()
135   endforeach(arch)
137   if(COMPILER_RT_ENABLE_IOS)
138     list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
139     set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
140     set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
141     set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
142       ${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
143     set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
144     set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
145     find_darwin_sdk_version(iossim_sdk_version "iphonesimulator")
146     if ("${iossim_sdk_version}" VERSION_GREATER 14.0 OR "${iossim_sdk_version}" VERSION_EQUAL 14.0)
147       list(APPEND DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
148     endif()
149   endif()
150   if(COMPILER_RT_ENABLE_WATCHOS)
151     list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
152     set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
153     set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
154     set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
155       ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
156     set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k arm64_32)
157     set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
158     find_darwin_sdk_version(watchossim_sdk_version "watchsimulator")
159     if ("${watchossim_sdk_version}" VERSION_GREATER 7.0 OR "${watchossim_sdk_version}" VERSION_EQUAL 7.0)
160       list(APPEND DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
161     endif()
162   endif()
163   if(COMPILER_RT_ENABLE_TVOS)
164     list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
165     set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
166     set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
167     set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
168       ${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
169     set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
170     set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
171     find_darwin_sdk_version(tvossim_sdk_version "appletvsimulator")
172     if ("${tvossim_sdk_version}" VERSION_GREATER 14.0 OR "${tvossim_sdk_version}" VERSION_EQUAL 14.0)
173       list(APPEND DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
174     endif()
175   endif()
176   if(COMPILER_RT_ENABLE_XROS)
177     list(APPEND DARWIN_EMBEDDED_PLATFORMS xros)
178     set(DARWIN_xros_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
179     set(DARWIN_xrossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
180   endif()
182   set(BUILTIN_SUPPORTED_OS osx)
184   # We're setting the flag manually for each target OS
185   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
187   # NOTE: We deliberately avoid using `DARWIN_<os>_ARCHS` here because that is
188   # used by `config-ix.cmake` in the context of building the rest of
189   # compiler-rt where the global `${TEST_COMPILE_ONLY}` (used by
190   # `darwin_test_archs()`) has a different value.
191   darwin_test_archs(osx
192     DARWIN_osx_BUILTIN_ARCHS
193     ${DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS}
194   )
195   message(STATUS "OSX supported builtin arches: ${DARWIN_osx_BUILTIN_ARCHS}")
196   foreach(arch ${DARWIN_osx_BUILTIN_ARCHS})
197     list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
198     set(CAN_TARGET_${arch} 1)
199   endforeach()
201   foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
202     if(DARWIN_${platform}sim_SYSROOT)
203       set(DARWIN_${platform}sim_BUILTIN_MIN_VER
204         ${DARWIN_${platform}_BUILTIN_MIN_VER})
205       set(DARWIN_${platform}sim_BUILTIN_MIN_VER_FLAG
206         ${DARWIN_${platform}_BUILTIN_MIN_VER_FLAG})
208       set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
210       darwin_test_archs(${platform}sim
211         DARWIN_${platform}sim_BUILTIN_ARCHS
212         ${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
213       )
214       message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
215       if(DARWIN_${platform}sim_BUILTIN_ARCHS)
216         list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
217       endif()
218       foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
219         list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
220         set(CAN_TARGET_${arch} 1)
221       endforeach()
222     endif()
224     if(DARWIN_${platform}_SYSROOT)
225       darwin_test_archs(${platform}
226         DARWIN_${platform}_BUILTIN_ARCHS
227         ${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
228       )
229       message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
230       if(DARWIN_${platform}_BUILTIN_ARCHS)
231         list(APPEND BUILTIN_SUPPORTED_OS ${platform})
232       endif()
233       foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
234         list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
235         set(CAN_TARGET_${arch} 1)
236       endforeach()
237     endif()
238   endforeach()
240   list_intersect(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH COMPILER_RT_SUPPORTED_ARCH)
242 else()
243   # If we're not building the builtins standalone, just rely on the  tests in
244   # config-ix.cmake to tell us what to build. Otherwise we need to do some leg
245   # work here...
246   if(COMPILER_RT_BUILTINS_STANDALONE_BUILD)
247     test_targets()
248   endif()
249   # Architectures supported by compiler-rt libraries.
250   filter_available_targets(BUILTIN_SUPPORTED_ARCH
251     ${ALL_BUILTIN_SUPPORTED_ARCH})
252 endif()
254 if(OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER AND NOT
255    COMPILER_RT_GPU_BUILD)
256   set(COMPILER_RT_HAS_CRT TRUE)
257 else()
258   set(COMPILER_RT_HAS_CRT FALSE)
259 endif()
261 message(STATUS "Builtin supported architectures: ${BUILTIN_SUPPORTED_ARCH}")