@@ -356,55 +356,72 @@ function(add_libclc_builtin_set)
356
356
357
357
set ( builtins_link_lib $< TARGET_PROPERTY:${builtins_link_lib_tgt} ,TARGET_FILE> )
358
358
359
+ # For SPIR-V targets we diverage at this point and generate SPIR-V using the
360
+ # llvm-spirv tool.
359
361
if ( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
360
- set ( spv_suffix ${ARG_ARCH_SUFFIX} .spv )
361
- add_custom_command ( OUTPUT ${spv_suffix }
362
- COMMAND ${llvm-spirv_exe} ${spvflags} -o ${spv_suffix } ${builtins_link_lib}
362
+ set ( obj_suffix ${ARG_ARCH_SUFFIX} .spv )
363
+ add_custom_command ( OUTPUT ${obj_suffix }
364
+ COMMAND ${llvm-spirv_exe} ${spvflags} -o ${obj_suffix } ${builtins_link_lib}
363
365
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
364
366
)
365
- add_custom_target ( "prepare-${spv_suffix} " ALL DEPENDS "${spv_suffix} " )
366
- set_target_properties ( "prepare-${spv_suffix} " PROPERTIES FOLDER "libclc/Device IR/Prepare" )
367
- install ( FILES ${CMAKE_CURRENT_BINARY_DIR} /${spv_suffix}
368
- DESTINATION "${CMAKE_INSTALL_DATADIR} /clc" )
369
-
370
- return ()
371
- endif ()
367
+ else ()
368
+ # Non-SPIR-V targets add an extra step to optimize the bytecode
369
+ set ( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} )
372
370
373
- set ( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} )
371
+ add_custom_command ( OUTPUT ${builtins_opt_lib_tgt} .bc
372
+ COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt} .bc
373
+ ${builtins_link_lib}
374
+ DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
375
+ )
376
+ add_custom_target ( ${builtins_opt_lib_tgt}
377
+ ALL DEPENDS ${builtins_opt_lib_tgt} .bc
378
+ )
379
+ set_target_properties ( ${builtins_opt_lib_tgt} PROPERTIES
380
+ TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR} /${builtins_opt_lib_tgt}.bc
381
+ FOLDER "libclc/Device IR/Opt"
382
+ )
374
383
375
- # Add opt target
376
- add_custom_command ( OUTPUT ${builtins_opt_lib_tgt} .bc
377
- COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt} .bc
378
- ${builtins_link_lib}
379
- DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
380
- )
381
- add_custom_target ( ${builtins_opt_lib_tgt}
382
- ALL DEPENDS ${builtins_opt_lib_tgt} .bc
383
- )
384
- set_target_properties ( ${builtins_opt_lib_tgt} PROPERTIES
385
- TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR} /${builtins_opt_lib_tgt}.bc
386
- FOLDER "libclc/Device IR/Opt"
387
- )
384
+ set ( builtins_opt_lib $< TARGET_PROPERTY:${builtins_opt_lib_tgt} ,TARGET_FILE> )
388
385
389
- set ( builtins_opt_lib $< TARGET_PROPERTY:${builtins_opt_lib_tgt} ,TARGET_FILE> )
386
+ set ( obj_suffix ${ARG_ARCH_SUFFIX} .bc )
387
+ add_custom_command ( OUTPUT ${obj_suffix}
388
+ COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib}
389
+ DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} )
390
+ endif ()
390
391
391
- # Add prepare target
392
- set ( obj_suffix ${ARG_ARCH_SUFFIX} .bc )
393
- add_custom_command ( OUTPUT ${obj_suffix}
394
- COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib}
395
- DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} )
392
+ # Add a 'prepare' target
396
393
add_custom_target ( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
397
394
set_target_properties ( "prepare-${obj_suffix} " PROPERTIES FOLDER "libclc/Device IR/Prepare" )
398
395
399
- # nvptx-- targets don't include workitem builtins, and clspv targets don't
400
- # include all OpenCL builtins
396
+ # Also add a 'prepare' target for the triple. Since a triple may have
397
+ # multiple devices, ensure we only try to create the triple target once. The
398
+ # triple's target will build all of the bytecode for its constituent devices.
399
+ if ( NOT TARGET prepare-${ARG_TRIPLE} )
400
+ add_custom_target ( prepare-${ARG_TRIPLE} ALL )
401
+ endif ()
402
+ add_dependencies ( prepare-${ARG_TRIPLE} prepare-${obj_suffix} )
403
+
404
+ install (
405
+ FILES ${CMAKE_CURRENT_BINARY_DIR} /${obj_suffix}
406
+ DESTINATION "${CMAKE_INSTALL_DATADIR} /clc"
407
+ )
408
+
409
+ # SPIR-V targets can exit early here
410
+ if ( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
411
+ return ()
412
+ endif ()
413
+
414
+ # Add a test for whether or not the libraries contain unresolved calls which
415
+ # would usually indicate a build problem. Note that we don't perform this
416
+ # test for all libclc targets:
417
+ # * nvptx-- targets don't include workitem builtins
418
+ # * clspv targets don't include all OpenCL builtins
401
419
if ( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
402
420
add_test ( NAME external-calls-${obj_suffix}
403
421
COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR} /${obj_suffix} ${LLVM_TOOLS_BINARY_DIR}
404
422
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
405
423
endif ()
406
424
407
- install ( FILES ${CMAKE_CURRENT_BINARY_DIR} /${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR} /clc" )
408
425
foreach ( a ${ARG_ALIASES} )
409
426
set ( alias_suffix "${a} -${ARG_TRIPLE} .bc" )
410
427
add_custom_command (
0 commit comments