Louis Dionne | afa1afd | 2020-04-22 15:15:05 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.13.4) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 2 | |
| 3 | project( libclc VERSION 0.2.0 LANGUAGES CXX ) |
Jan Vesely | e25db17 | 2019-01-07 20:20:37 | [diff] [blame] | 4 | include( GNUInstallDirs ) |
Jan Vesely | 814fb65 | 2020-02-15 03:29:04 | [diff] [blame] | 5 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS |
| 6 | amdgcn-amdhsa/lib/SOURCES; |
| 7 | amdgcn/lib/SOURCES; |
| 8 | amdgcn-mesa3d/lib/SOURCES; |
| 9 | amdgpu/lib/SOURCES; |
Alan Baker | 21427b8 | 2020-12-07 20:54:14 | [diff] [blame] | 10 | clspv/lib/SOURCES; |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 11 | clspv64/lib/SOURCES; |
Jan Vesely | 814fb65 | 2020-02-15 03:29:04 | [diff] [blame] | 12 | generic/lib/SOURCES; |
| 13 | ptx/lib/SOURCES; |
| 14 | ptx-nvidiacl/lib/SOURCES; |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 15 | r600/lib/SOURCES; |
| 16 | spirv/lib/SOURCES; |
| 17 | spirv64/lib/SOURCES |
Jan Vesely | 814fb65 | 2020-02-15 03:29:04 | [diff] [blame] | 18 | ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 19 | |
| 20 | # List of all targets |
| 21 | set( LIBCLC_TARGETS_ALL |
| 22 | amdgcn-- |
| 23 | amdgcn--amdhsa |
Alan Baker | 21427b8 | 2020-12-07 20:54:14 | [diff] [blame] | 24 | clspv-- |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 25 | clspv64-- |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 26 | r600-- |
| 27 | nvptx-- |
| 28 | nvptx64-- |
| 29 | nvptx--nvidiacl |
| 30 | nvptx64--nvidiacl |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 31 | spirv-mesa3d- |
| 32 | spirv64-mesa3d- |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | set( LIBCLC_MIN_LLVM "3.9.0" ) |
| 36 | |
| 37 | set( LIBCLC_TARGETS_TO_BUILD "all" |
| 38 | CACHE STRING "Semicolon-separated list of targets to build, or 'all'." ) |
| 39 | |
| 40 | option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." |
| 41 | OFF ) |
| 42 | |
| 43 | if( NOT LLVM_CONFIG ) |
| 44 | find_program( LLVM_CONFIG llvm-config ) |
| 45 | endif() |
| 46 | execute_process( COMMAND ${LLVM_CONFIG} "--version" |
| 47 | OUTPUT_VARIABLE LLVM_VERSION |
| 48 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
| 49 | message( "LLVM version: ${LLVM_VERSION}" ) |
| 50 | |
| 51 | if( ${LLVM_VERSION} VERSION_LESS ${LIBCLC_MIN_LLVM} ) |
| 52 | message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) |
| 53 | endif() |
| 54 | |
| 55 | # mesa3d environment is only available since LLVM 4.0 |
| 56 | if( ${LLVM_VERSION} VERSION_GREATER "3.9.0" ) |
| 57 | set( LIBCLC_TARGETS_ALL ${LIBCLC_TARGETS_ALL} amdgcn-mesa-mesa3d ) |
| 58 | endif() |
| 59 | |
| 60 | if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" ) |
| 61 | set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} ) |
| 62 | endif() |
| 63 | |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 64 | execute_process( COMMAND ${LLVM_CONFIG} "--system-libs" |
| 65 | OUTPUT_VARIABLE LLVM_SYSTEM_LIBS |
| 66 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
Daniel Stone | e6bb1d6 | 2020-04-14 04:38:22 | [diff] [blame] | 67 | separate_arguments( LLVM_SYSTEM_LIBS ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 68 | execute_process( COMMAND ${LLVM_CONFIG} "--libs" "core" "bitreader" "bitwriter" |
| 69 | OUTPUT_VARIABLE LLVM_LIBS |
| 70 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
Daniel Stone | e6bb1d6 | 2020-04-14 04:38:22 | [diff] [blame] | 71 | separate_arguments( LLVM_LIBS ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 72 | execute_process( COMMAND ${LLVM_CONFIG} "--libdir" |
| 73 | OUTPUT_VARIABLE LLVM_LIBDIR |
| 74 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
| 75 | execute_process( COMMAND ${LLVM_CONFIG} "--ldflags" |
| 76 | OUTPUT_VARIABLE LLVM_LD_FLAGS |
| 77 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
| 78 | execute_process( COMMAND ${LLVM_CONFIG} "--cxxflags" |
| 79 | OUTPUT_VARIABLE LLVM_CXX_FLAGS |
| 80 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
| 81 | separate_arguments( LLVM_CXX_FLAGS ) |
| 82 | execute_process( COMMAND ${LLVM_CONFIG} "--bindir" |
| 83 | OUTPUT_VARIABLE LLVM_BINDIR |
| 84 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
| 85 | |
| 86 | # These were not properly reported in early LLVM and we don't need them |
Daniel Stone | e6bb1d6 | 2020-04-14 04:38:22 | [diff] [blame] | 87 | list( APPEND LLVM_CXX_FLAGS -fno-rtti -fno-exceptions ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 88 | |
| 89 | # Print LLVM variables |
| 90 | message( "LLVM system libs: ${LLVM_SYSTEM_LIBS}" ) |
| 91 | message( "LLVM libs: ${LLVM_LIBS}" ) |
| 92 | message( "LLVM libdir: ${LLVM_LIBDIR}" ) |
| 93 | message( "LLVM bindir: ${LLVM_BINDIR}" ) |
| 94 | message( "LLVM ld flags: ${LLVM_LD_FLAGS}" ) |
| 95 | message( "LLVM cxx flags: ${LLVM_CXX_FLAGS}" ) |
| 96 | message( "" ) |
| 97 | |
| 98 | find_program( LLVM_CLANG clang PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) |
| 99 | find_program( LLVM_AS llvm-as PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) |
| 100 | find_program( LLVM_LINK llvm-link PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) |
| 101 | find_program( LLVM_OPT opt PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 102 | find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 103 | |
| 104 | # Print toolchain |
| 105 | message( "clang: ${LLVM_CLANG}" ) |
| 106 | message( "llvm-as: ${LLVM_AS}" ) |
| 107 | message( "llvm-link: ${LLVM_LINK}" ) |
| 108 | message( "opt: ${LLVM_OPT}" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 109 | message( "llvm-spirv: ${LLVM_SPIRV}" ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 110 | message( "" ) |
| 111 | if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK ) |
| 112 | message( FATAL_ERROR "toolchain incomplete!" ) |
| 113 | endif() |
| 114 | |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 115 | list( SORT LIBCLC_TARGETS_TO_BUILD ) |
| 116 | |
| 117 | if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD ) |
| 118 | if( NOT LLVM_SPIRV ) |
| 119 | message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not installed" ) |
| 120 | endif() |
| 121 | endif() |
| 122 | |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 123 | set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ) |
| 124 | set( CMAKE_CLC_COMPILER ${LLVM_CLANG} ) |
| 125 | set( CMAKE_CLC_ARCHIVE ${LLVM_LINK} ) |
| 126 | set( CMAKE_LLAsm_PREPROCESSOR ${LLVM_CLANG} ) |
| 127 | set( CMAKE_LLAsm_COMPILER ${LLVM_AS} ) |
| 128 | set( CMAKE_LLAsm_ARCHIVE ${LLVM_LINK} ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 129 | |
| 130 | # Construct LLVM version define |
| 131 | string( REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_VERSION} ) |
| 132 | list( GET LLVM_VERSION_LIST 0 LLVM_MAJOR ) |
| 133 | list( GET LLVM_VERSION_LIST 1 LLVM_MINOR ) |
| 134 | set( LLVM_VERSION_DEFINE "-DHAVE_LLVM=0x${LLVM_MAJOR}0${LLVM_MINOR}" ) |
| 135 | |
Jan Vesely | ea469b0 | 2021-07-15 00:41:50 | [diff] [blame] | 136 | |
| 137 | # LLVM 13 enables standard includes by default |
| 138 | if( ${LLVM_VERSION} VERSION_GREATER "12.99.99" ) |
| 139 | set( CMAKE_LLAsm_FLAGS ${CMAKE_LLAsm_FLAGS} -cl-no-stdinc ) |
| 140 | set( CMAKE_CLC_FLAGS ${CMAKE_CLC_FLAGS} -cl-no-stdinc ) |
| 141 | endif() |
| 142 | |
| 143 | enable_language( CLC LLAsm ) |
| 144 | |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 145 | # This needs to be set before any target that needs it |
| 146 | link_directories( ${LLVM_LIBDIR} ) |
| 147 | |
| 148 | # Setup prepare_builtins tools |
| 149 | add_executable( prepare_builtins utils/prepare-builtins.cpp ) |
| 150 | target_compile_options( prepare_builtins PRIVATE ${LLVM_CXX_FLAGS} ) |
| 151 | target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 152 | target_link_libraries( prepare_builtins PRIVATE ${LLVM_LIBS} ) |
Tom Stellard | 174c41d | 2020-04-29 22:34:48 | [diff] [blame] | 153 | target_link_libraries( prepare_builtins PRIVATE ${LLVM_SYSTEM_LIBS} ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 154 | |
| 155 | # Setup arch devices |
| 156 | set( r600--_devices cedar cypress barts cayman ) |
| 157 | set( amdgcn--_devices tahiti ) |
| 158 | set( amdgcn-mesa-mesa3d_devices ${amdgcn--_devices} ) |
| 159 | set( amdgcn--amdhsa_devices none ) |
Alan Baker | 21427b8 | 2020-12-07 20:54:14 | [diff] [blame] | 160 | set( clspv--_devices none ) |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 161 | set( clspv64--_devices none ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 162 | set( nvptx--_devices none ) |
| 163 | set( nvptx64--_devices none ) |
| 164 | set( nvptx--nvidiacl_devices none ) |
| 165 | set( nvptx64--nvidiacl_devices none ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 166 | set( spirv-mesa3d-_devices none ) |
| 167 | set( spirv64-mesa3d-_devices none ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 168 | |
| 169 | # Setup aliases |
| 170 | set( cedar_aliases palm sumo sumo2 redwood juniper ) |
| 171 | set( cypress_aliases hemlock ) |
| 172 | set( barts_aliases turks caicos ) |
| 173 | set( cayman_aliases aruba ) |
| 174 | set( tahiti_aliases pitcairn verde oland hainan bonaire kabini kaveri hawaii |
| 175 | mullins tonga iceland carrizo fiji stoney polaris10 polaris11 ) |
| 176 | |
| 177 | # Support for gfx9 was added in LLVM 5.0 (r295554) |
| 178 | if( ${LLVM_VERSION} VERSION_GREATER "4.99.99" ) |
| 179 | set( tahiti_aliases ${tahiti_aliases} gfx900 gfx902 ) |
| 180 | endif() |
| 181 | |
| 182 | # Support for Vega12 and Vega20 was added in LLVM 7 (r331215) |
| 183 | if( ${LLVM_VERSION} VERSION_GREATER "6.99.99" ) |
| 184 | set( tahiti_aliases ${tahiti_aliases} gfx904 gfx906 ) |
| 185 | endif() |
| 186 | |
| 187 | # pkg-config file |
| 188 | configure_file( libclc.pc.in libclc.pc @ONLY ) |
John Ericson | ddcc02d | 2021-12-11 01:54:42 | [diff] [blame] | 189 | install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" ) |
| 190 | install( DIRECTORY generic/include/clc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 191 | |
| 192 | if( ENABLE_RUNTIME_SUBNORMAL ) |
| 193 | add_library( subnormal_use_default STATIC |
| 194 | generic/lib/subnormal_use_default.ll ) |
| 195 | add_library( subnormal_disable STATIC |
| 196 | generic/lib/subnormal_disable.ll ) |
| 197 | install( TARGETS subnormal_use_default subnormal_disable ARCHIVE |
John Ericson | ddcc02d | 2021-12-11 01:54:42 | [diff] [blame] | 198 | DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 199 | endif() |
| 200 | |
Aaron Puchert | 1c1a810 | 2020-10-01 20:31:30 | [diff] [blame] | 201 | find_package( Python3 REQUIRED COMPONENTS Interpreter ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 202 | file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/generic/lib/gen_convert.py script_loc ) |
| 203 | add_custom_command( |
| 204 | OUTPUT convert.cl |
Aaron Puchert | 1c1a810 | 2020-10-01 20:31:30 | [diff] [blame] | 205 | COMMAND ${Python3_EXECUTABLE} ${script_loc} > convert.cl |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 206 | DEPENDS ${script_loc} ) |
| 207 | add_custom_target( "generate_convert.cl" DEPENDS convert.cl ) |
| 208 | |
| 209 | enable_testing() |
| 210 | |
| 211 | foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) |
| 212 | message( "BUILDING ${t}" ) |
| 213 | string( REPLACE "-" ";" TRIPLE ${t} ) |
| 214 | list( GET TRIPLE 0 ARCH ) |
| 215 | list( GET TRIPLE 1 VENDOR ) |
| 216 | list( GET TRIPLE 2 OS ) |
| 217 | |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 218 | set( dirs ) |
| 219 | |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 220 | if ( NOT ${ARCH} STREQUAL spirv AND NOT ${ARCH} STREQUAL spirv64 AND |
| 221 | NOT ${ARCH} STREQUAL clspv AND NOT ${ARCH} STREQUAL clspv64) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 222 | LIST( APPEND dirs generic ) |
| 223 | endif() |
| 224 | |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 225 | if( ${ARCH} STREQUAL r600 OR ${ARCH} STREQUAL amdgcn ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 226 | list( APPEND dirs amdgpu ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 227 | endif() |
| 228 | |
| 229 | #nvptx is special |
| 230 | if( ${ARCH} STREQUAL nvptx OR ${ARCH} STREQUAL nvptx64 ) |
| 231 | set( DARCH ptx ) |
| 232 | else() |
| 233 | set( DARCH ${ARCH} ) |
| 234 | endif() |
| 235 | |
| 236 | # Enumerate SOURCES* files |
| 237 | set( source_list ) |
| 238 | foreach( l ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS} ) |
| 239 | foreach( s "SOURCES" "SOURCES_${LLVM_MAJOR}.${LLVM_MINOR}" ) |
| 240 | file( TO_CMAKE_PATH ${l}/lib/${s} file_loc ) |
| 241 | file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/${file_loc} loc ) |
| 242 | # Prepend the location to give higher priority to |
| 243 | # specialized implementation |
| 244 | if( EXISTS ${loc} ) |
| 245 | set( source_list ${file_loc} ${source_list} ) |
| 246 | endif() |
| 247 | endforeach() |
| 248 | endforeach() |
| 249 | |
| 250 | # Add the generated convert.cl here to prevent adding |
| 251 | # the one listed in SOURCES |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 252 | if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" AND |
| 253 | NOT ${ARCH} STREQUAL "clspv" AND NOT ${ARCH} STREQUAL "clspv64" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 254 | set( rel_files convert.cl ) |
| 255 | set( objects convert.cl ) |
| 256 | if( NOT ENABLE_RUNTIME_SUBNORMAL ) |
| 257 | list( APPEND rel_files generic/lib/subnormal_use_default.ll ) |
| 258 | endif() |
| 259 | else() |
| 260 | set( rel_files ) |
| 261 | set( objects ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 262 | endif() |
| 263 | |
| 264 | foreach( l ${source_list} ) |
| 265 | file( READ ${l} file_list ) |
| 266 | string( REPLACE "\n" ";" file_list ${file_list} ) |
| 267 | get_filename_component( dir ${l} DIRECTORY ) |
| 268 | foreach( f ${file_list} ) |
| 269 | list( FIND objects ${f} found ) |
| 270 | if( found EQUAL -1 ) |
| 271 | list( APPEND objects ${f} ) |
| 272 | list( APPEND rel_files ${dir}/${f} ) |
| 273 | # FIXME: This should really go away |
| 274 | file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/${dir}/${f} src_loc ) |
| 275 | get_filename_component( fdir ${src_loc} DIRECTORY ) |
| 276 | |
| 277 | set_source_files_properties( ${dir}/${f} |
| 278 | PROPERTIES COMPILE_FLAGS "-I ${fdir}" ) |
| 279 | endif() |
| 280 | endforeach() |
| 281 | endforeach() |
| 282 | |
| 283 | foreach( d ${${t}_devices} ) |
| 284 | # Some targets don't have a specific GPU to target |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 285 | if( ${d} STREQUAL "none" OR ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 286 | set( mcpu ) |
| 287 | set( arch_suffix "${t}" ) |
| 288 | else() |
| 289 | set( mcpu "-mcpu=${d}" ) |
| 290 | set( arch_suffix "${d}-${t}" ) |
| 291 | endif() |
| 292 | message( " DEVICE: ${d} ( ${${d}_aliases} )" ) |
| 293 | |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 294 | if ( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" ) |
| 295 | if( ${ARCH} STREQUAL "spirv" ) |
| 296 | set( t "spir--" ) |
| 297 | else() |
| 298 | set( t "spir64--" ) |
| 299 | endif() |
| 300 | set( build_flags -O0 -finline-hint-functions ) |
| 301 | set( opt_flags ) |
| 302 | set( spvflags --spirv-max-version=1.1 ) |
Alan Baker | 21427b8 | 2020-12-07 20:54:14 | [diff] [blame] | 303 | elseif( ${ARCH} STREQUAL "clspv" ) |
| 304 | set( t "spir--" ) |
| 305 | set( build_flags ) |
| 306 | set( opt_flags -O3 ) |
Kévin Petit | ec0a880 | 2022-01-05 16:32:08 | [diff] [blame] | 307 | elseif( ${ARCH} STREQUAL "clspv64" ) |
| 308 | set( t "spir64--" ) |
| 309 | set( build_flags ) |
| 310 | set( opt_flags -O3 ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 311 | else() |
| 312 | set( build_flags ) |
| 313 | set( opt_flags -O3 ) |
| 314 | endif() |
| 315 | |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 316 | add_library( builtins.link.${arch_suffix} STATIC ${rel_files} ) |
| 317 | # Make sure we depend on the pseudo target to prevent |
| 318 | # multiple invocations |
| 319 | add_dependencies( builtins.link.${arch_suffix} |
| 320 | generate_convert.cl ) |
| 321 | # CMake will turn this include into absolute path |
| 322 | target_include_directories( builtins.link.${arch_suffix} PRIVATE |
| 323 | "generic/include" ) |
| 324 | target_compile_definitions( builtins.link.${arch_suffix} PRIVATE |
| 325 | "__CLC_INTERNAL" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 326 | string( TOUPPER "-DCLC_${ARCH}" CLC_TARGET_DEFINE ) |
| 327 | target_compile_definitions( builtins.link.${arch_suffix} PRIVATE |
| 328 | ${CLC_TARGET_DEFINE} ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 329 | target_compile_options( builtins.link.${arch_suffix} PRIVATE -target |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 330 | ${t} ${mcpu} -fno-builtin -nostdlib ${build_flags} ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 331 | set_target_properties( builtins.link.${arch_suffix} PROPERTIES |
| 332 | LINKER_LANGUAGE CLC ) |
| 333 | |
| 334 | set( obj_suffix ${arch_suffix}.bc ) |
| 335 | |
| 336 | # Add opt target |
| 337 | add_custom_command( OUTPUT "builtins.opt.${obj_suffix}" |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 338 | COMMAND ${LLVM_OPT} ${opt_flags} -o |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 339 | "builtins.opt.${obj_suffix}" |
| 340 | "builtins.link.${obj_suffix}" |
| 341 | DEPENDS "builtins.link.${arch_suffix}" ) |
| 342 | add_custom_target( "opt.${obj_suffix}" ALL |
| 343 | DEPENDS "builtins.opt.${obj_suffix}" ) |
| 344 | |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 345 | if( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" ) |
| 346 | set( spv_suffix ${arch_suffix}.spv ) |
| 347 | add_custom_command( OUTPUT "${spv_suffix}" |
| 348 | COMMAND ${LLVM_SPIRV} ${spvflags} |
| 349 | -o "${spv_suffix}" |
| 350 | "builtins.link.${obj_suffix}" |
| 351 | DEPENDS "builtins.link.${arch_suffix}" ) |
| 352 | add_custom_target( "prepare-${spv_suffix}" ALL |
| 353 | DEPENDS "${spv_suffix}" ) |
| 354 | install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix} |
John Ericson | ddcc02d | 2021-12-11 01:54:42 | [diff] [blame] | 355 | DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 356 | else() |
| 357 | |
| 358 | # Add prepare target |
| 359 | add_custom_command( OUTPUT "${obj_suffix}" |
| 360 | COMMAND prepare_builtins -o |
| 361 | "${obj_suffix}" |
| 362 | "builtins.opt.${obj_suffix}" |
| 363 | DEPENDS "opt.${obj_suffix}" |
| 364 | "builtins.opt.${obj_suffix}" |
| 365 | prepare_builtins ) |
| 366 | add_custom_target( "prepare-${obj_suffix}" ALL |
| 367 | DEPENDS "${obj_suffix}" ) |
| 368 | |
| 369 | # nvptx-- targets don't include workitem builtins |
| 370 | if( NOT ${t} MATCHES ".*ptx.*--$" ) |
| 371 | add_test( NAME external-calls-${obj_suffix} |
| 372 | COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} |
| 373 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) |
| 374 | set_tests_properties( external-calls-${obj_suffix} |
| 375 | PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" ) |
| 376 | endif() |
| 377 | |
John Ericson | ddcc02d | 2021-12-11 01:54:42 | [diff] [blame] | 378 | install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 379 | foreach( a ${${d}_aliases} ) |
| 380 | set( alias_suffix "${a}-${t}.bc" ) |
| 381 | add_custom_target( ${alias_suffix} ALL |
| 382 | COMMAND ${CMAKE_COMMAND} -E |
| 383 | create_symlink ${obj_suffix} |
| 384 | ${alias_suffix} |
| 385 | DEPENDS "prepare-${obj_suffix}" ) |
John Ericson | ddcc02d | 2021-12-11 01:54:42 | [diff] [blame] | 386 | install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) |
Dave Airlie | c37145c | 2020-08-17 20:45:04 | [diff] [blame] | 387 | endforeach( a ) |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 388 | endif() |
Jan Vesely | 2ce1d09 | 2018-11-27 16:07:19 | [diff] [blame] | 389 | endforeach( d ) |
| 390 | endforeach( t ) |