@@ -278,49 +278,22 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
278
278
set ( DARCH ${ARCH} )
279
279
endif ()
280
280
281
- # Enumerate SOURCES* files
282
- set ( source_list )
283
- foreach ( l ${dirs} ${DARCH} ${DARCH} -${OS} ${DARCH} -${VENDOR}-${OS} )
284
- foreach ( s "SOURCES" "SOURCES_${LLVM_MAJOR} .${LLVM_MINOR} " )
285
- file ( TO_CMAKE_PATH ${l} /lib/${s} file_loc )
286
- file ( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /${file_loc} loc )
287
- # Prepend the location to give higher priority to
288
- # specialized implementation
289
- if ( EXISTS ${loc} )
290
- set ( source_list ${file_loc} ${source_list} )
291
- endif ()
292
- endforeach ()
293
- endforeach ()
294
-
295
- # Add the generated convert.cl here to prevent adding the one listed in
296
- # SOURCES
297
- set ( objects ) # A "set" of already-added input files
298
- set ( rel_files ) # Source directory input files, relative to the root dir
299
- set ( gen_files ) # Generated binary input files, relative to the binary dir
300
- if ( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
301
- if ( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL "clspv" AND
302
- NOT ${ARCH} STREQUAL "clspv64" )
303
- list ( APPEND gen_files convert.cl )
304
- list ( APPEND objects convert.cl )
305
- list ( APPEND rel_files generic/lib/subnormal_use_default.ll )
306
- elseif (${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64" )
307
- list ( APPEND gen_files clspv-convert.cl )
308
- list ( APPEND objects clspv-convert.cl )
281
+ set ( opencl_lib_files )
282
+ set ( opencl_gen_files )
283
+
284
+ if ( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
285
+ if ( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
286
+ list ( APPEND opencl_gen_files clspv-convert.cl )
287
+ elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
288
+ list ( APPEND opencl_gen_files convert.cl )
289
+ list ( APPEND opencl_lib_files generic/lib/subnormal_use_default.ll )
309
290
endif ()
310
291
endif ()
311
292
312
- foreach ( l ${source_list} )
313
- file ( READ ${l} file_list )
314
- string ( REPLACE "\n " ";" file_list ${file_list} )
315
- get_filename_component ( dir ${l} DIRECTORY )
316
- foreach ( f ${file_list} )
317
- # Only add each file once, so that targets can 'specialize' builtins
318
- if ( NOT ${f} IN_LIST objects )
319
- list ( APPEND objects ${f} )
320
- list ( APPEND rel_files ${dir} /${f} )
321
- endif ()
322
- endforeach ()
323
- endforeach ()
293
+ libclc_configure_lib_source (
294
+ opencl_lib_files
295
+ DIRS ${dirs} ${DARCH} ${DARCH} -${OS} ${DARCH} -${VENDOR}-${OS}
296
+ )
324
297
325
298
foreach ( d ${${t}_devices} )
326
299
get_libclc_device_info (
@@ -331,11 +304,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
331
304
CLANG_TRIPLE clang_triple
332
305
)
333
306
334
- set ( mcpu )
335
- if ( NOT "${cpu} " STREQUAL "" )
336
- set ( mcpu "-mcpu=${cpu} " )
337
- endif ()
338
-
339
307
message ( STATUS " device: ${d} ( ${${d} _aliases} )" )
340
308
341
309
if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
@@ -363,109 +331,19 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
363
331
-Wno-bitwise-conditional-parentheses
364
332
)
365
333
366
- set ( bytecode_files "" )
367
- foreach ( file IN LISTS gen_files rel_files )
368
- # We need to take each file and produce an absolute input file, as well
369
- # as a unique architecture-specific output file. We deal with a mix of
370
- # different input files, which makes this trickier.
371
- if ( ${file} IN_LIST gen_files )
372
- # Generated files are given just as file names, which we must make
373
- # absolute to the binary directory.
374
- set ( input_file ${CMAKE_CURRENT_BINARY_DIR} /${file} )
375
- set ( output_file "${LIBCLC_ARCH_OBJFILE_DIR} /${file} .bc" )
376
- else ()
377
- # Other files are originally relative to each SOURCE file, which are
378
- # then make relative to the libclc root directory. We must normalize
379
- # the path (e.g., ironing out any ".."), then make it relative to the
380
- # root directory again, and use that relative path component for the
381
- # binary path.
382
- get_filename_component ( abs_path ${file} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
383
- file ( RELATIVE_PATH root_rel_path ${CMAKE_CURRENT_SOURCE_DIR} ${abs_path} )
384
- set ( input_file ${CMAKE_CURRENT_SOURCE_DIR} /${file} )
385
- set ( output_file "${LIBCLC_ARCH_OBJFILE_DIR} /${root_rel_path} .bc" )
386
- endif ()
387
-
388
- get_filename_component ( file_dir ${file} DIRECTORY )
389
-
390
- compile_to_bc (
391
- TRIPLE ${clang_triple}
392
- INPUT ${input_file}
393
- OUTPUT ${output_file}
394
- EXTRA_OPTS "${mcpu} " -fno-builtin -nostdlib
395
- "${build_flags} " -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
396
- DEPENDENCIES generate_convert.cl clspv-generate_convert.cl
397
- )
398
- list ( APPEND bytecode_files ${output_file} )
399
- endforeach ()
400
-
401
- set ( builtins_comp_lib_tgt builtins.comp.${arch_suffix} )
402
- add_custom_target ( ${builtins_comp_lib_tgt}
403
- DEPENDS ${bytecode_files}
404
- )
405
- set_target_properties ( ${builtins_comp_lib_tgt} PROPERTIES FOLDER "libclc/Device IR/Comp" )
334
+ if ( NOT "${cpu} " STREQUAL "" )
335
+ list ( APPEND build_flags -mcpu=${cpu} )
336
+ endif ()
406
337
407
- set ( builtins_link_lib_tgt builtins.link.${arch_suffix} )
408
- link_bc (
409
- TARGET ${builtins_link_lib_tgt}
410
- INPUTS ${bytecode_files}
411
- DEPENDENCIES ${builtins_comp_lib_tgt}
338
+ add_libclc_builtin_set (
339
+ ARCH ${ARCH}
340
+ ARCH_SUFFIX ${arch_suffix}
341
+ TRIPLE ${clang_triple}
342
+ COMPILE_FLAGS ${build_flags}
343
+ OPT_FLAGS ${opt_flags}
344
+ LIB_FILES ${opencl_lib_files}
345
+ GEN_FILES ${opencl_gen_files}
346
+ ALIASES ${${d}_aliases}
412
347
)
413
-
414
- set ( builtins_link_lib $< TARGET_PROPERTY:${builtins_link_lib_tgt} ,TARGET_FILE> )
415
-
416
- if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
417
- set ( spv_suffix ${arch_suffix} .spv )
418
- add_custom_command ( OUTPUT ${spv_suffix}
419
- COMMAND ${llvm-spirv_exe} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
420
- DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
421
- )
422
- add_custom_target ( "prepare-${spv_suffix} " ALL DEPENDS "${spv_suffix} " )
423
- set_target_properties ( "prepare-${spv_suffix} " PROPERTIES FOLDER "libclc/Device IR/Prepare" )
424
- install ( FILES ${CMAKE_CURRENT_BINARY_DIR} /${spv_suffix}
425
- DESTINATION "${CMAKE_INSTALL_DATADIR} /clc" )
426
- else ()
427
- set ( builtins_opt_lib_tgt builtins.opt.${arch_suffix} )
428
-
429
- # Add opt target
430
- add_custom_command ( OUTPUT ${builtins_opt_lib_tgt} .bc
431
- COMMAND ${opt_exe} ${opt_flags} -o ${builtins_opt_lib_tgt} .bc
432
- ${builtins_link_lib}
433
- DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
434
- )
435
- add_custom_target ( ${builtins_opt_lib_tgt}
436
- ALL DEPENDS ${builtins_opt_lib_tgt} .bc
437
- )
438
- set_target_properties ( ${builtins_opt_lib_tgt} PROPERTIES
439
- TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR} /${builtins_opt_lib_tgt}.bc
440
- FOLDER "libclc/Device IR/Opt"
441
- )
442
-
443
- set ( builtins_opt_lib $< TARGET_PROPERTY:${builtins_opt_lib_tgt} ,TARGET_FILE> )
444
-
445
- # Add prepare target
446
- set ( obj_suffix ${arch_suffix} .bc )
447
- add_custom_command ( OUTPUT ${obj_suffix}
448
- COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib}
449
- DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} )
450
- add_custom_target ( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
451
- set_target_properties ( "prepare-${obj_suffix} " PROPERTIES FOLDER "libclc/Device IR/Prepare" )
452
-
453
- # nvptx-- targets don't include workitem builtins
454
- if ( NOT clang_triple MATCHES ".*ptx.*--$" )
455
- add_test ( NAME external-calls-${obj_suffix}
456
- COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR} /${obj_suffix} ${LLVM_TOOLS_BINARY_DIR}
457
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
458
- endif ()
459
-
460
- install ( FILES ${CMAKE_CURRENT_BINARY_DIR} /${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR} /clc" )
461
- foreach ( a ${${d}_aliases} )
462
- set ( alias_suffix "${a} -${clang_triple} .bc" )
463
- add_custom_target ( ${alias_suffix} ALL
464
- COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} ${alias_suffix}
465
- DEPENDS prepare-${obj_suffix} )
466
- set_target_properties ( "${alias_suffix} " PROPERTIES FOLDER "libclc/Device IR/Aliases" )
467
- install ( FILES ${CMAKE_CURRENT_BINARY_DIR} /${alias_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR} /clc" )
468
- endforeach ( a )
469
- endif ()
470
348
endforeach ( d )
471
349
endforeach ( t )
0 commit comments