aboutsummaryrefslogtreecommitdiff
path: root/libclc/cmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'libclc/cmake/modules')
-rw-r--r--libclc/cmake/modules/AddLibclc.cmake103
1 files changed, 49 insertions, 54 deletions
diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake
index 1142963..7092457b 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -33,9 +33,7 @@ function(compile_to_bc)
else()
set( PP_OPTS -E;-P )
set( TMP_SUFFIX .tmp )
- string( REPLACE "-Xclang;-fdeclare-opencl-builtins;-Xclang;-finclude-default-header"
- "" EXTRA_OPTS "${ARG_EXTRA_OPTS}"
- )
+ string( REPLACE "-include;opencl-c-base.h" "" EXTRA_OPTS "${ARG_EXTRA_OPTS}")
endif()
set( TARGET_ARG )
@@ -226,33 +224,6 @@ function(get_libclc_device_info)
endif()
endfunction()
-# Install libclc artifacts.
-#
-# Arguments:
-# * FILES <string> ...
-# List of libclc artifact files to be installed.
-function(libclc_install)
- cmake_parse_arguments(ARG "" "" "FILES" ${ARGN})
-
- if( NOT ARG_FILES )
- message( FATAL_ERROR "Must provide FILES" )
- endif()
-
- if( NOT CMAKE_CFG_INTDIR STREQUAL "." )
- # Replace CMAKE_CFG_INTDIR with CMAKE_INSTALL_CONFIG_NAME for multiple-
- # configuration generators.
- string( REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}"
- files ${ARG_FILES} )
- else()
- set( files ${ARG_FILES} )
- endif()
-
- install(
- FILES ${files}
- DESTINATION ${LIBCLC_INSTALL_DIR}
- )
-endfunction()
-
# Compiles a list of library source files (provided by LIB_FILES) and compiles
# them to LLVM bytecode (or SPIR-V), links them together and optimizes them.
#
@@ -262,10 +233,14 @@ endfunction()
# Arguments:
# * ARCH <string>
# libclc architecture being built
+# * DEVICE <string>
+# libclc microarchitecture being built
# * ARCH_SUFFIX <string>
# libclc architecture/triple suffix
# * TRIPLE <string>
# Triple used to compile
+# * OUTPUT_FILENAME <string>
+# libclc output library name
# * PARENT_TARGET <string>
# Target into which to group the target builtins
#
@@ -288,7 +263,7 @@ endfunction()
function(add_libclc_builtin_set)
cmake_parse_arguments(ARG
"CLC_INTERNAL"
- "ARCH;TRIPLE;ARCH_SUFFIX;PARENT_TARGET"
+ "ARCH;DEVICE;TRIPLE;ARCH_SUFFIX;OUTPUT_FILENAME;PARENT_TARGET"
"LIB_FILES;COMPILE_FLAGS;OPT_FLAGS;ALIASES;INTERNAL_LINK_DEPENDENCIES"
${ARGN}
)
@@ -399,16 +374,27 @@ function(add_libclc_builtin_set)
return()
endif()
+ if (NOT DEFINED ARG_OUTPUT_FILENAME OR ARG_OUTPUT_FILENAME STREQUAL "")
+ message(FATAL_ERROR "OUTPUT_FILENAME parameter is required and must be non-empty.")
+ endif()
+ set( LIBCLC_OUTPUT_FILENAME ${ARG_OUTPUT_FILENAME} )
set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> )
+ # We store the library according to its triple and cpu if present.
+ if (NOT "${ARG_DEVICE}" STREQUAL "none")
+ set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${ARG_DEVICE})
+ else()
+ set (library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE})
+ endif()
+ file( MAKE_DIRECTORY ${library_dir} )
+
# 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_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
+ set( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.spv )
if ( LIBCLC_USE_SPIRV_BACKEND )
add_custom_command( OUTPUT ${libclc_builtins_lib}
- COMMAND ${clang_exe} --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib}
+ COMMAND ${clang_exe} -c --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib}
DEPENDS ${clang_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
)
else()
@@ -419,8 +405,7 @@ function(add_libclc_builtin_set)
endif()
else()
# Non-SPIR-V targets add an extra step to optimize the bytecode
- set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
- set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
+ set( libclc_builtins_lib ${library_dir}/${LIBCLC_OUTPUT_FILENAME}.bc )
add_custom_command( OUTPUT ${libclc_builtins_lib}
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${libclc_builtins_lib}
@@ -430,24 +415,28 @@ function(add_libclc_builtin_set)
endif()
# Add a 'library' target
- add_custom_target( library-${obj_suffix} ALL DEPENDS ${libclc_builtins_lib} )
- set_target_properties( "library-${obj_suffix}" PROPERTIES
+ add_custom_target( library-${ARG_ARCH_SUFFIX} ALL DEPENDS ${libclc_builtins_lib} )
+ set_target_properties( "library-${ARG_ARCH_SUFFIX}" PROPERTIES
TARGET_FILE ${libclc_builtins_lib}
FOLDER "libclc/Device IR/Library"
)
- # Also add a 'library' target for the triple. Since a triple may have
+ # Also add a 'libclc' 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.
- if( NOT TARGET library-${ARG_TRIPLE} )
- add_custom_target( library-${ARG_TRIPLE} ALL )
+ if( NOT TARGET libclc-${ARG_TRIPLE} )
+ add_custom_target( libclc-${ARG_TRIPLE} ALL )
endif()
- add_dependencies( library-${ARG_TRIPLE} library-${obj_suffix} )
+ add_dependencies( libclc-${ARG_TRIPLE} library-${ARG_ARCH_SUFFIX} )
# Add dependency to top-level pseudo target to ease making other
# targets dependent on libclc.
- add_dependencies( ${ARG_PARENT_TARGET} library-${ARG_TRIPLE} )
+ add_dependencies( ${ARG_PARENT_TARGET} libclc-${ARG_TRIPLE} )
- libclc_install(FILES ${libclc_builtins_lib})
+ # Install the created library.
+ install(
+ FILES ${libclc_builtins_lib}
+ DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}
+ )
# SPIR-V targets can exit early here
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
@@ -460,7 +449,7 @@ function(add_libclc_builtin_set)
# * nvptx64-- 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-funcs-${obj_suffix}
+ add_test( NAME external-funcs-${ARG_ARCH_SUFFIX}
COMMAND ./check_external_funcs.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
endif()
@@ -476,20 +465,26 @@ function(add_libclc_builtin_set)
set(LIBCLC_LINK_OR_COPY copy)
endif()
- set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
+ file( MAKE_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a} )
+ set( libclc_alias_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${ARG_TRIPLE}/${a}/${LIBCLC_OUTPUT_FILENAME}.bc )
add_custom_command(
- OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
- COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
- DEPENDS library-${obj_suffix}
+ OUTPUT ${libclc_alias_lib}
+ COMMAND ${CMAKE_COMMAND} -E ${LIBCLC_LINK_OR_COPY} ${LIBCLC_LINK_OR_COPY_SOURCE} ${libclc_alias_lib}
+ DEPENDS library-${ARG_ARCH_SUFFIX}
)
- add_custom_target( alias-${alias_suffix} ALL
- DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
+ add_custom_target( alias-${a}-${ARG_TRIPLE} ALL
+ DEPENDS ${libclc_alias_lib}
)
- add_dependencies( ${ARG_PARENT_TARGET} alias-${alias_suffix} )
- set_target_properties( alias-${alias_suffix}
+ add_dependencies( ${ARG_PARENT_TARGET} alias-${a}-${ARG_TRIPLE} )
+ set_target_properties( alias-${a}-${ARG_TRIPLE}
PROPERTIES FOLDER "libclc/Device IR/Aliases"
)
- libclc_install(FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix})
+
+ # Install the library
+ install(
+ FILES ${libclc_alias_lib}
+ DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}/${a}
+ )
endforeach( a )
endfunction(add_libclc_builtin_set)