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