@@ -101,7 +101,7 @@ endfunction()
101
101
function (link_bc )
102
102
cmake_parse_arguments (ARG
103
103
"INTERNALIZE"
104
- "TARGET"
104
+ "TARGET;RSP_DIR "
105
105
"INPUTS;DEPENDENCIES"
106
106
${ARGN}
107
107
)
@@ -110,7 +110,7 @@ function(link_bc)
110
110
if ( WIN32 OR CYGWIN )
111
111
# Create a response file in case the number of inputs exceeds command-line
112
112
# character limits on certain platforms.
113
- file ( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR } /${ARG_TARGET}.rsp RSP_FILE )
113
+ file ( TO_CMAKE_PATH ${ARG_RSP_DIR } /${ARG_TARGET}.rsp RSP_FILE )
114
114
# Turn it into a space-separate list of input files
115
115
list ( JOIN ARG_INPUTS " " RSP_INPUT )
116
116
file ( GENERATE OUTPUT ${RSP_FILE} CONTENT ${RSP_INPUT} )
@@ -126,14 +126,14 @@ function(link_bc)
126
126
endif ()
127
127
128
128
add_custom_command (
129
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR } /${ARG_TARGET}.bc
130
- COMMAND ${llvm-link_exe} ${link_flags} -o ${CMAKE_CURRENT_BINARY_DIR } /${ARG_TARGET}.bc ${LINK_INPUT_ARG}
129
+ OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR } /${ARG_TARGET}.bc
130
+ COMMAND ${llvm-link_exe} ${link_flags} -o ${LIBCLC_ARCH_OBJFILE_DIR } /${ARG_TARGET}.bc ${LINK_INPUT_ARG}
131
131
DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
132
132
)
133
133
134
- add_custom_target ( ${ARG_TARGET} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR } /${ARG_TARGET}.bc )
134
+ add_custom_target ( ${ARG_TARGET} ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR } /${ARG_TARGET}.bc )
135
135
set_target_properties ( ${ARG_TARGET} PROPERTIES
136
- TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR } /${ARG_TARGET}.bc
136
+ TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR } /${ARG_TARGET}.bc
137
137
FOLDER "libclc/Device IR/Linking"
138
138
)
139
139
endfunction ()
@@ -250,21 +250,17 @@ function(process_bc out_file)
250
250
"LIB_TGT;IN_FILE;OUT_DIR"
251
251
"OPT_FLAGS;DEPENDENCIES"
252
252
${ARGN} )
253
-
254
- # Check if the target already exists
255
- if (NOT TARGET ${ARG_LIB_TGT} )
256
- add_custom_command (OUTPUT ${ARG_LIB_TGT} .bc
257
- COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT} .bc
258
- ${ARG_IN_FILE}
259
- DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES}
260
- )
261
- add_custom_target (${ARG_LIB_TGT}
262
- ALL DEPENDS ${ARG_LIB_TGT} .bc
253
+ add_custom_command ( OUTPUT ${ARG_LIB_TGT} .bc
254
+ COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT} .bc
255
+ ${ARG_IN_FILE}
256
+ DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES}
257
+ )
258
+ add_custom_target ( ${ARG_LIB_TGT}
259
+ ALL DEPENDS ${ARG_LIB_TGT} .bc
263
260
)
264
- set_target_properties (${ARG_LIB_TGT}
265
- PROPERTIES TARGET_FILE ${ARG_LIB_TGT} .bc
261
+ set_target_properties ( ${ARG_LIB_TGT}
262
+ PROPERTIES TARGET_FILE ${ARG_LIB_TGT} .bc
266
263
)
267
- endif ()
268
264
269
265
set ( builtins_opt_lib $< TARGET_PROPERTY:${ARG_LIB_TGT} ,TARGET_FILE> )
270
266
@@ -415,6 +411,7 @@ function(add_libclc_builtin_set)
415
411
link_bc (
416
412
TARGET ${builtins_link_lib_tgt}
417
413
INPUTS ${bytecode_files}
414
+ RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
418
415
DEPENDENCIES ${builtins_comp_lib_tgt}
419
416
)
420
417
else ()
@@ -425,6 +422,7 @@ function(add_libclc_builtin_set)
425
422
link_bc (
426
423
TARGET ${builtins_link_lib_tmp_tgt}
427
424
INPUTS ${bytecode_files}
425
+ RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
428
426
DEPENDENCIES ${builtins_comp_lib_tgt}
429
427
)
430
428
set ( internal_link_depend_files )
@@ -436,6 +434,7 @@ function(add_libclc_builtin_set)
436
434
TARGET ${builtins_link_lib_tgt}
437
435
INPUTS $< TARGET_PROPERTY:${builtins_link_lib_tmp_tgt} ,TARGET_FILE>
438
436
${internal_link_depend_files}
437
+ RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
439
438
DEPENDENCIES ${builtins_link_lib_tmp_tgt} ${ARG_INTERNAL_LINK_DEPENDENCIES}
440
439
)
441
440
endif ()
@@ -448,15 +447,9 @@ function(add_libclc_builtin_set)
448
447
449
448
set ( builtins_link_lib $< TARGET_PROPERTY:${builtins_link_lib_tgt} ,TARGET_FILE> )
450
449
451
- add_custom_command ( OUTPUT ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
452
- COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
453
- DEPENDS ${builtins_link_lib} prepare_builtins )
454
-
455
- # For SPIR-V targets we diverage at this point and generate SPIR-V using the
456
- # llvm-spirv tool.
457
450
if ( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
458
451
set ( obj_suffix ${ARG_ARCH_SUFFIX} .spv )
459
- set ( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR } /${obj_suffix} )
452
+ set ( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR } /${obj_suffix} )
460
453
add_custom_command ( OUTPUT ${libclc_builtins_lib}
461
454
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
462
455
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
@@ -481,7 +474,7 @@ function(add_libclc_builtin_set)
481
474
set ( builtins_opt_lib $< TARGET_PROPERTY:${builtins_opt_lib_tgt} ,TARGET_FILE> )
482
475
483
476
set ( obj_suffix ${ARG_ARCH_SUFFIX} .bc )
484
- set ( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR } /${obj_suffix} )
477
+ set ( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR } /${obj_suffix} )
485
478
add_custom_command ( OUTPUT ${libclc_builtins_lib}
486
479
COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib}
487
480
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target}
@@ -495,7 +488,11 @@ function(add_libclc_builtin_set)
495
488
# Add dependency to top-level pseudo target to ease making other
496
489
# targets dependent on libclc.
497
490
add_dependencies (${ARG_PARENT_TARGET} prepare-${obj_suffix} )
498
- set ( builtins_lib ${obj_suffix} )
491
+
492
+ # SPIR-V targets can exit early here
493
+ if ( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
494
+ return ()
495
+ endif ()
499
496
500
497
# Also add a 'prepare' target for the triple. Since a triple may have
501
498
# multiple devices, ensure we only try to create the triple target once. The
@@ -515,6 +512,38 @@ function(add_libclc_builtin_set)
515
512
return ()
516
513
endif ()
517
514
515
+ # Add a test for whether or not the libraries contain unresolved calls which
516
+ # would usually indicate a build problem. Note that we don't perform this
517
+ # test for all libclc targets:
518
+ # * nvptx-- targets don't include workitem builtins
519
+ # * clspv targets don't include all OpenCL builtins
520
+ if ( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
521
+ add_test ( NAME external-calls-${obj_suffix}
522
+ COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
523
+ WORKING_DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR} )
524
+ set_tests_properties ( external-calls-${obj_suffix}
525
+ PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG} " )
526
+ endif ()
527
+
528
+ foreach ( a ${ARG_ALIASES} )
529
+ set ( alias_suffix "${a} -${ARG_TRIPLE} .bc" )
530
+ add_custom_command (
531
+ OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
532
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
533
+ DEPENDS prepare-${obj_suffix}
534
+ )
535
+ add_custom_target ( alias-${alias_suffix} ALL
536
+ DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
537
+ )
538
+ set_target_properties ( alias-${alias_suffix}
539
+ PROPERTIES FOLDER "libclc/Device IR/Aliases"
540
+ )
541
+ install (
542
+ FILES ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
543
+ DESTINATION "${CMAKE_INSTALL_DATADIR} /clc"
544
+ )
545
+ endforeach ( a )
546
+
518
547
# Generate remangled variants if requested
519
548
if ( ARG_REMANGLE )
520
549
set ( dummy_in ${LIBCLC_LIBRARY_OUTPUT_INTDIR} /libclc_dummy_in.cc )
@@ -544,9 +573,9 @@ function(add_libclc_builtin_set)
544
573
--triple=${ARG_TRIPLE}
545
574
--long-width=${long_width}
546
575
--char-signedness=${signedness}
547
- --input-ir=${builtins_lib }
576
+ --input-ir=${libclc_builtins_lib }
548
577
${dummy_in}
549
- DEPENDS ${builtins_lib } ${libclc-remangler_target} ${dummy_in} )
578
+ DEPENDS ${libclc_builtins_lib } ${libclc-remangler_target} ${dummy_in} )
550
579
add_custom_target ( "remangled-${long_width} -${signedness} _char.${obj_suffix_mangled} " ALL
551
580
DEPENDS "${builtins_remangle_path} " "${dummy_in} " )
552
581
set_target_properties ("remangled-${long_width} -${signedness} _char.${obj_suffix_mangled} "
@@ -569,7 +598,7 @@ function(add_libclc_builtin_set)
569
598
# dependency against check-libclc.
570
599
set (libclc-remangler-tests )
571
600
set (libclc-remangler-test-no 0 )
572
- foreach (target -ir ${builtins_opt_lib} ${builtins_link_lib} ${builtins_lib } )
601
+ foreach (target -ir ${builtins_opt_lib} ${builtins_link_lib} ${libclc_builtins_lib } )
573
602
math (EXPR libclc-remangler-test-no "${libclc-remangler-test-no}+1" )
574
603
set (current-test "libclc-remangler-test-${obj_suffix} -${libclc-remangler-test-no}" )
575
604
add_custom_target (${current-test}
@@ -578,41 +607,11 @@ function(add_libclc_builtin_set)
578
607
--char-signedness=signed
579
608
--input-ir=${target-ir}
580
609
${dummy_in} -t -o -
581
- DEPENDS ${builtins_lib } "${dummy_in} " ${libclc-remangler_target} )
610
+ DEPENDS ${libclc_builtins_lib } "${dummy_in} " ${libclc-remangler_target} )
582
611
list (APPEND libclc-remangler-tests ${current-test} )
583
612
endforeach ()
584
613
endif ()
585
614
586
- # Add a test for whether or not the libraries contain unresolved calls which
587
- # would usually indicate a build problem. Note that we don't perform this
588
- # test for all libclc targets:
589
- # * nvptx-- targets don't include workitem builtins
590
- # * clspv targets don't include all OpenCL builtins
591
- if ( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
592
- add_test ( NAME external-calls-${obj_suffix}
593
- COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
594
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
595
- endif ()
596
-
597
- foreach ( a ${ARG_ALIASES} )
598
- set ( alias_suffix "${a} -${ARG_TRIPLE} .bc" )
599
- add_custom_command (
600
- OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
601
- COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
602
- DEPENDS prepare-${obj_suffix}
603
- )
604
- add_custom_target ( alias-${alias_suffix} ALL
605
- DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
606
- )
607
- set_target_properties ( alias-${alias_suffix}
608
- PROPERTIES FOLDER "libclc/Device IR/Aliases"
609
- )
610
- install (
611
- FILES ${LIBCLC_OUTPUT_LIBRARY_DIR} /${alias_suffix}
612
- DESTINATION "${CMAKE_INSTALL_DATADIR} /clc"
613
- )
614
- endforeach ( a )
615
-
616
615
endfunction (add_libclc_builtin_set )
617
616
618
617
# Produces a list of libclc source files by walking over SOURCES files in a
0 commit comments