diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 9077f0c31f028..548f4752e6b69 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -92,9 +92,6 @@ else() endif() endif() -# Setup the paths where libclc runtimes should be stored. -set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) - if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) message( WARNING "Using custom LLVM tools to build libclc: " "${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, " @@ -342,6 +339,10 @@ else(LIBCLC_STANDALONE_BUILD) endif(LIBCLC_STANDALONE_BUILD) file( TO_CMAKE_PATH ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/clc LIBCLC_LIBRARY_OUTPUT_INTDIR ) +# Setup the paths where libclc runtimes should be stored. +# FIXME: Align with upstream +set( LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_LIBRARY_OUTPUT_INTDIR} ) + foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) message( STATUS "libclc target '${t}' is enabled" ) string( REPLACE "-" ";" TRIPLE ${t}-- ) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 92a897a482ac9..1f6dd587c24d4 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -101,7 +101,7 @@ endfunction() function(link_bc) cmake_parse_arguments(ARG "INTERNALIZE" - "TARGET;RSP_DIR" + "TARGET" "INPUTS;DEPENDENCIES" ${ARGN} ) @@ -110,7 +110,7 @@ function(link_bc) if( WIN32 OR CYGWIN ) # Create a response file in case the number of inputs exceeds command-line # character limits on certain platforms. - file( TO_CMAKE_PATH ${ARG_RSP_DIR}/${ARG_TARGET}.rsp RSP_FILE ) + file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE ) # Turn it into a space-separate list of input files list( JOIN ARG_INPUTS " " RSP_INPUT ) file( GENERATE OUTPUT ${RSP_FILE} CONTENT ${RSP_INPUT} ) @@ -205,78 +205,6 @@ function(get_libclc_device_info) endif() endfunction() -function(add_libclc_alias alias target) - cmake_parse_arguments(ARG "" "" PARENT_TARGET "" ${ARGN}) - - if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL Windows) - set(LIBCLC_LINK_OR_COPY create_symlink) - else() - set(LIBCLC_LINK_OR_COPY copy) - endif() - - add_custom_command( - OUTPUT ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix} - COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR} - COMMAND ${CMAKE_COMMAND} -E - ${LIBCLC_LINK_OR_COPY} ${target}.bc - ${alias_suffix} - WORKING_DIRECTORY - ${LIBCLC_LIBRARY_OUTPUT_INTDIR} - DEPENDS "prepare-${target}" - ) - add_custom_target( alias-${alias_suffix} ALL - DEPENDS "${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix}" ) - add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix}) - - install( FILES ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${alias_suffix} - DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) - -endfunction(add_libclc_alias alias target) - -# Runs opt and prepare-builtins on a bitcode file specified by lib_tgt -# -# ARGUMENTS: -# * LIB_TGT string -# Target name that becomes dependent on the out file named LIB_TGT.bc -# * IN_FILE string -# Target name of the input bytecode file -# * OUT_DIR string -# Name of the directory where the output should be placed -# * DEPENDENCIES ... -# List of extra dependencies to inject -function(process_bc out_file) - cmake_parse_arguments(ARG - "" - "LIB_TGT;IN_FILE;OUT_DIR" - "OPT_FLAGS;DEPENDENCIES" - ${ARGN}) - add_custom_command( OUTPUT ${ARG_LIB_TGT}.bc - COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${ARG_LIB_TGT}.bc - ${ARG_IN_FILE} - DEPENDS ${opt_target} ${ARG_IN_FILE} ${ARG_DEPENDENCIES} - ) - add_custom_target( ${ARG_LIB_TGT} - ALL DEPENDS ${ARG_LIB_TGT}.bc - ) - set_target_properties( ${ARG_LIB_TGT} - PROPERTIES TARGET_FILE ${ARG_LIB_TGT}.bc - ) - - set( builtins_opt_lib $ ) - - # Add prepare target - add_custom_command( OUTPUT ${ARG_OUT_DIR}/${out_file} - COMMAND ${prepare_builtins_exe} -o ${ARG_OUT_DIR}/${out_file} - ${builtins_opt_lib} - DEPENDS ${builtins_opt_lib} ${ARG_LIB_TGT} ${prepare_builtins_target} ) - add_custom_target( prepare-${out_file} ALL - DEPENDS ${ARG_OUT_DIR}/${out_file} - ) - set_target_properties( prepare-${out_file} - PROPERTIES TARGET_FILE ${ARG_OUT_DIR}/${out_file} - ) -endfunction() - # Compiles a list of library source files (provided by LIB_FILES/GEN_FILES) and # compiles them to LLVM bytecode (or SPIR-V), links them together and optimizes # them. @@ -411,7 +339,6 @@ function(add_libclc_builtin_set) link_bc( TARGET ${builtins_link_lib_tgt} INPUTS ${bytecode_files} - RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} DEPENDENCIES ${builtins_comp_lib_tgt} ) else() @@ -422,7 +349,6 @@ function(add_libclc_builtin_set) link_bc( TARGET ${builtins_link_lib_tmp_tgt} INPUTS ${bytecode_files} - RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} DEPENDENCIES ${builtins_comp_lib_tgt} ) set( internal_link_depend_files ) @@ -434,7 +360,6 @@ function(add_libclc_builtin_set) TARGET ${builtins_link_lib_tgt} INPUTS $ ${internal_link_depend_files} - RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} DEPENDENCIES ${builtins_link_lib_tmp_tgt} ${ARG_INTERNAL_LINK_DEPENDENCIES} ) endif() @@ -447,9 +372,15 @@ function(add_libclc_builtin_set) set( builtins_link_lib $ ) + add_custom_command( OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR} + DEPENDS ${builtins_link_lib} prepare_builtins ) + + # For SPIR-V targets we diverage at this point and generate SPIR-V using the + # llvm-spirv tool. if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) - set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} ) + set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) add_custom_command( OUTPUT ${libclc_builtins_lib} COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib} DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} @@ -474,7 +405,7 @@ function(add_libclc_builtin_set) set( builtins_opt_lib $ ) set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) - set( libclc_builtins_lib ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/${obj_suffix} ) + set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) add_custom_command( OUTPUT ${libclc_builtins_lib} COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib} DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} @@ -489,11 +420,6 @@ function(add_libclc_builtin_set) # targets dependent on libclc. add_dependencies(${ARG_PARENT_TARGET} prepare-${obj_suffix}) - # SPIR-V targets can exit early here - if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) - return() - endif() - # Also add a 'prepare' target for the triple. Since a triple may have # multiple devices, ensure we only try to create the triple target once. The # triple's target will build all of the bytecode for its constituent devices. @@ -512,49 +438,11 @@ function(add_libclc_builtin_set) return() endif() - # Add a test for whether or not the libraries contain unresolved calls which - # would usually indicate a build problem. Note that we don't perform this - # test for all libclc targets: - # * nvptx-- targets don't include workitem builtins - # * clspv targets don't include all OpenCL builtins - if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) - add_test( NAME external-calls-${obj_suffix} - COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR} - WORKING_DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR} ) - set_tests_properties( external-calls-${obj_suffix} - PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" ) - endif() - - if(CMAKE_HOST_UNIX OR LLVM_USE_SYMLINKS) - set(LIBCLC_LINK_OR_COPY create_symlink) - else() - set(LIBCLC_LINK_OR_COPY copy) - endif() - - foreach( a IN LISTS ARG_ALIASES ) - set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) - add_custom_command( - OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - DEPENDS prepare-${obj_suffix} - ) - add_custom_target( alias-${alias_suffix} ALL - DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - ) - set_target_properties( alias-${alias_suffix} - PROPERTIES FOLDER "libclc/Device IR/Aliases" - ) - install( - FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" - ) - endforeach( a ) - # Generate remangled variants if requested if( ARG_REMANGLE ) - set( dummy_in ${LIBCLC_LIBRARY_OUTPUT_INTDIR}/libclc_dummy_in.cc ) + set( dummy_in ${LIBCLC_OUTPUT_LIBRARY_DIR}/libclc_dummy_in.cc ) add_custom_command( OUTPUT ${dummy_in} - COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR} COMMAND ${CMAKE_COMMAND} -E touch ${dummy_in} ) set(long_widths l32 l64) @@ -571,9 +459,9 @@ function(add_libclc_builtin_set) foreach(signedness ${char_signedness}) # Remangle set( builtins_remangle_path - "${LIBCLC_LIBRARY_OUTPUT_INTDIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" ) + "${LIBCLC_OUTPUT_LIBRARY_DIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" ) add_custom_command( OUTPUT "${builtins_remangle_path}" - COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_OUTPUT_LIBRARY_DIR} COMMAND ${libclc-remangler_exe} -o "${builtins_remangle_path}" --triple=${ARG_TRIPLE} @@ -618,6 +506,36 @@ function(add_libclc_builtin_set) endforeach() endif() + # Add a test for whether or not the libraries contain unresolved calls which + # would usually indicate a build problem. Note that we don't perform this + # test for all libclc targets: + # * nvptx-- targets don't include workitem builtins + # * clspv targets don't include all OpenCL builtins + if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) + add_test( NAME external-calls-${obj_suffix} + COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + endif() + + foreach( a ${ARG_ALIASES} ) + set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) + add_custom_command( + OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + DEPENDS prepare-${obj_suffix} + ) + add_custom_target( alias-${alias_suffix} ALL + DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + ) + set_target_properties( alias-${alias_suffix} + PROPERTIES FOLDER "libclc/Device IR/Aliases" + ) + add_dependencies(${ARG_PARENT_TARGET} alias-${alias_suffix}) + install( + FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" + ) + endforeach( a ) endfunction(add_libclc_builtin_set) # Produces a list of libclc source files by walking over SOURCES files in a diff --git a/libclc/libspirv/lib/generic/math/acos.cl b/libclc/libspirv/lib/generic/math/acos.cl index feccbd4ca08f6..5cbdd31a1a5ee 100644 --- a/libclc/libspirv/lib/generic/math/acos.cl +++ b/libclc/libspirv/lib/generic/math/acos.cl @@ -10,6 +10,6 @@ #include #define FUNCTION __spirv_ocl_acos -#define __CLC_FUNCTION(x) __clc_acos +#define __IMPL_FUNCTION(x) __clc_acos #define __CLC_BODY #include diff --git a/libclc/libspirv/lib/generic/math/asin.cl b/libclc/libspirv/lib/generic/math/asin.cl index e88939ed33b77..d70f0ffb37053 100644 --- a/libclc/libspirv/lib/generic/math/asin.cl +++ b/libclc/libspirv/lib/generic/math/asin.cl @@ -10,6 +10,6 @@ #include #define FUNCTION __spirv_ocl_asin -#define __CLC_FUNCTION(x) __clc_asin +#define __IMPL_FUNCTION(x) __clc_asin #define __CLC_BODY #include diff --git a/libclc/libspirv/lib/generic/math/modf.cl b/libclc/libspirv/lib/generic/math/modf.cl index 303defe821798..f94469e243171 100644 --- a/libclc/libspirv/lib/generic/math/modf.cl +++ b/libclc/libspirv/lib/generic/math/modf.cl @@ -10,6 +10,6 @@ #include #define FUNCTION __spirv_ocl_modf -#define __CLC_FUNCTION(x) __clc_modf +#define __IMPL_FUNCTION(x) __clc_modf #define __CLC_BODY #include