[libclc] [libclc] Use custom CMake handling to overhaul libclc compilation (PR #185247)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 20:06:54 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
This PR uses https://github.com/llvm/llvm-project/pull/185243 to
overhaul compilation of libclc. This brings libclc to the same kind of
compilation flow that the other GPU libraries use (compiler-rt, libc,
libc++, openmp, flang-rt).
The main brunt of this change is simply changing the SOURCES files to
CMake variables and altering the compilation. Now that these are
standard CMake libraries we do not need to bother redefining custom
library handling and targets.
This builds as a static library, which we then consume with `llvm-link`
which converts it into a single `.bc` bitcode file similarly to before.
The final result is then optimized all together.
Hopefully this doesn't break anything.
---
Patch is 91.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/185247.diff
26 Files Affected:
- (modified) libclc/CMakeLists.txt (+278-272)
- (added) libclc/clc/lib/amdgcn/CMakeLists.txt (+14)
- (removed) libclc/clc/lib/amdgcn/SOURCES (-11)
- (added) libclc/clc/lib/amdgpu/CMakeLists.txt (+16)
- (removed) libclc/clc/lib/amdgpu/SOURCES (-13)
- (added) libclc/clc/lib/clspv/CMakeLists.txt (+5)
- (removed) libclc/clc/lib/clspv/SOURCES (-2)
- (added) libclc/clc/lib/generic/CMakeLists.txt (+185)
- (removed) libclc/clc/lib/generic/SOURCES (-182)
- (added) libclc/clc/lib/ptx-nvidiacl/CMakeLists.txt (+17)
- (removed) libclc/clc/lib/ptx-nvidiacl/SOURCES (-14)
- (added) libclc/clc/lib/spirv/CMakeLists.txt (+5)
- (removed) libclc/clc/lib/spirv/SOURCES (-2)
- (modified) libclc/cmake/modules/AddLibclc.cmake (+19-564)
- (added) libclc/opencl/lib/amdgcn-amdhsa/CMakeLists.txt (+6)
- (removed) libclc/opencl/lib/amdgcn-amdhsa/SOURCES (-3)
- (added) libclc/opencl/lib/amdgcn/CMakeLists.txt (+12)
- (removed) libclc/opencl/lib/amdgcn/SOURCES (-9)
- (added) libclc/opencl/lib/clspv/CMakeLists.txt (+85)
- (removed) libclc/opencl/lib/clspv/SOURCES (-77)
- (added) libclc/opencl/lib/generic/CMakeLists.txt (+206)
- (removed) libclc/opencl/lib/generic/SOURCES (-203)
- (added) libclc/opencl/lib/ptx-nvidiacl/CMakeLists.txt (+16)
- (removed) libclc/opencl/lib/ptx-nvidiacl/SOURCES (-13)
- (added) libclc/opencl/lib/spirv/CMakeLists.txt (+78)
- (removed) libclc/opencl/lib/spirv/SOURCES (-71)
``````````diff
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 1aa67b0745781..fccdfd300bc49 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -10,29 +10,12 @@ set(CMAKE_CXX_STANDARD 17)
# Add path for custom modules
list( INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" )
-set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
-set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
-set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
-
include( AddLibclc )
include( GNUInstallDirs )
-set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
- # OpenCL libraries
- opencl/lib/amdgcn-amdhsa/SOURCES;
- opencl/lib/amdgcn/SOURCES;
- opencl/lib/clspv/SOURCES;
- opencl/lib/generic/SOURCES;
- opencl/lib/ptx-nvidiacl/SOURCES;
- opencl/lib/spirv/SOURCES;
- # CLC internal libraries
- clc/lib/generic/SOURCES;
- clc/lib/amdgcn/SOURCES;
- clc/lib/amdgpu/SOURCES;
- clc/lib/clspv/SOURCES;
- clc/lib/ptx-nvidiacl/SOURCES;
- clc/lib/spirv/SOURCES;
-)
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
# A runtimes cross-build should only use the requested target.
set( LIBCLC_DEFAULT_TARGET "all" )
@@ -46,14 +29,37 @@ option(
LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF
)
-# Top level target used to build all Libclc libraries.
-add_custom_target( libclc ALL )
+# List of all supported targets.
+set( LIBCLC_TARGETS_ALL
+ amdgcn--
+ amdgcn-amd-amdhsa-llvm
+ amdgcn-mesa-mesa3d
+ clspv--
+ clspv64--
+ nvptx64--
+ nvptx64--nvidiacl
+ nvptx64-nvidia-cuda
+)
-add_custom_target( libclc-opencl-builtins COMMENT "Build libclc OpenCL builtins" )
-add_dependencies( libclc libclc-opencl-builtins )
+if( LIBCLC_USE_SPIRV_BACKEND OR llvm-spirv_exe )
+ list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
+endif()
+
+if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
+ set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
+else()
+ foreach(TARGET_TO_BUILD ${LIBCLC_TARGETS_TO_BUILD})
+ if (NOT ${TARGET_TO_BUILD} IN_LIST LIBCLC_TARGETS_ALL)
+ message( FATAL_ERROR
+ "Unknown target in LIBCLC_TARGETS_TO_BUILD: \"${TARGET_TO_BUILD}\"\n"
+ "Valid targets are: ${LIBCLC_TARGETS_ALL}\n")
+ endif()
+ endforeach()
+endif()
+
+list( SORT LIBCLC_TARGETS_TO_BUILD )
if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
- # Out-of-tree configuration
set( LIBCLC_STANDALONE_BUILD TRUE )
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
@@ -61,20 +67,16 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI
message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
- # Import required tools
- if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
- foreach( tool IN ITEMS clang llvm-as llvm-link opt )
- find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
- set( ${tool}_exe ${LLVM_TOOL_${tool}} )
- set( ${tool}_target )
- endforeach()
- endif()
+ foreach( tool IN ITEMS llvm-link opt )
+ find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+ set( ${tool}_exe ${LLVM_TOOL_${tool}} )
+ set( ${tool}_target )
+ endforeach()
# Setup the paths where libclc runtimes should be stored.
set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
set( LIBCLC_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/clc )
else()
- # In-tree configuration
set( LIBCLC_STANDALONE_BUILD FALSE )
if( NOT LLVM_PACKAGE_VERSION )
@@ -89,12 +91,8 @@ else()
message(FATAL_ERROR "Clang is not enabled, but is required to build libclc in-tree")
endif()
- if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
- get_host_tool_path( clang CLANG clang_exe clang_target )
- get_host_tool_path( llvm-as LLVM_AS llvm-as_exe llvm-as_target )
- get_host_tool_path( llvm-link LLVM_LINK llvm-link_exe llvm-link_target )
- get_host_tool_path( opt OPT opt_exe opt_target )
- endif()
+ get_host_tool_path( llvm-link LLVM_LINK llvm-link_exe llvm-link_target )
+ get_host_tool_path( opt OPT opt_exe opt_target )
# Setup the paths where libclc runtimes should be stored. By default, in an
# in-tree build we place the libraries in clang's resource driectory.
@@ -106,28 +104,6 @@ else()
cmake_path( APPEND LIBCLC_OUTPUT_LIBRARY_DIR ${LIBCLC_INSTALL_DIR} )
endif()
-if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
- message( WARNING "Using custom LLVM tools to build libclc: "
- "${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "
- " ensure the tools are up to date." )
- # Note - use a differently named variable than LLVM_TOOL_${tool} as above, as
- # the variable name is used to cache the result of find_program. If we used
- # the same name, a user wouldn't be able to switch a build between default
- # and custom tools.
- foreach( tool IN ITEMS clang llvm-as llvm-link opt )
- find_program( LLVM_CUSTOM_TOOL_${tool} ${tool}
- PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
- set( ${tool}_exe ${LLVM_CUSTOM_TOOL_${tool}} )
- set( ${tool}_target )
- endforeach()
-endif()
-
-foreach( tool IN ITEMS clang opt llvm-as llvm-link )
- if( NOT EXISTS "${${tool}_exe}" AND "${${tool}_target}" STREQUAL "" )
- message( FATAL_ERROR "libclc toolchain incomplete - missing tool ${tool}!" )
- endif()
-endforeach()
-
if( NOT LIBCLC_USE_SPIRV_BACKEND )
# llvm-spirv is an optional dependency, used to build spirv-* targets when
# the SPIR-V backend hasn't been requested. It may be provided in-tree or
@@ -141,80 +117,30 @@ if( NOT LIBCLC_USE_SPIRV_BACKEND )
endif()
endif()
-# List of all targets. Note that some are added dynamically below.
-set( LIBCLC_TARGETS_ALL
- amdgcn--
- amdgcn-amd-amdhsa-llvm
- clspv--
- clspv64--
- nvptx64--
- nvptx64--nvidiacl
- nvptx64-nvidia-cuda
-)
-
-# The mesa3d environment is only available since LLVM 4.0
-if( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 )
- list( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d )
-endif()
-
-# The spirv-mesa3d and spirv64-mesa3d targets are optional and can be built
-# with either the LLVM SPIR-V backend or the external llvm-spirv tool.
-if( LIBCLC_USE_SPIRV_BACKEND OR llvm-spirv_exe )
- list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
-endif()
-
-# Verify that the user hasn't requested mesa3d targets without an available
-# llvm-spirv tool.
-if( spirv-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD
- OR spirv64-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD )
- if( NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe )
- message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not "
- "installed and the SPIR-V backend has not been requested." )
+foreach( tool IN ITEMS opt llvm-link )
+ if( NOT EXISTS "${${tool}_exe}" AND "${${tool}_target}" STREQUAL "" )
+ message( FATAL_ERROR "libclc toolchain incomplete - missing tool ${tool}!" )
endif()
-endif()
+endforeach()
-if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
- set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
-else()
- foreach(TARGET_TO_BUILD ${LIBCLC_TARGETS_TO_BUILD})
- if (NOT ${TARGET_TO_BUILD} IN_LIST LIBCLC_TARGETS_ALL)
- message ( FATAL_ERROR "Unknown target in LIBCLC_TARGETS_TO_BUILD: \"${TARGET_TO_BUILD}\"\n"
- "Valid targets are: ${LIBCLC_TARGETS_ALL}\n")
- endif()
- endforeach()
-endif()
-list( SORT LIBCLC_TARGETS_TO_BUILD )
+add_subdirectory(clc/lib/generic)
+add_subdirectory(clc/lib/amdgcn)
+add_subdirectory(clc/lib/amdgpu)
+add_subdirectory(clc/lib/ptx-nvidiacl)
+add_subdirectory(clc/lib/spirv)
+add_subdirectory(clc/lib/clspv)
-# This needs to be set before any target that needs it
-# We need to use LLVM_INCLUDE_DIRS here, because if we are linking to an
-# llvm build directory, this includes $src/llvm/include which is where all the
-# headers are not $build/include/ which is what LLVM_INCLUDE_DIR is set to.
-include_directories( ${LLVM_INCLUDE_DIRS} )
-
-# Setup arch devices
-set( amdgcn--_devices none )
-set( amdgcn-mesa-mesa3d_devices none )
-set( amdgcn-amd-amdhsa-llvm_devices none )
-set( clspv--_devices none )
-set( clspv64--_devices none )
-set( nvptx64--_devices none )
-set( nvptx64--nvidiacl_devices none )
-set( nvptx64-nvidia-cuda_devices none )
-set( spirv-mesa3d-_devices none )
-set( spirv64-mesa3d-_devices none )
-
-# Setup aliases
-set( cedar_aliases palm sumo sumo2 redwood juniper )
-set( cypress_aliases hemlock )
-set( barts_aliases turks caicos )
-set( cayman_aliases aruba )
+add_subdirectory(opencl/lib/generic)
+add_subdirectory(opencl/lib/amdgcn)
+add_subdirectory(opencl/lib/amdgcn-amdhsa)
+add_subdirectory(opencl/lib/ptx-nvidiacl)
+add_subdirectory(opencl/lib/clspv)
+add_subdirectory(opencl/lib/spirv)
-# pkg-config file
-configure_file( libclc.pc.in libclc.pc @ONLY )
-install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" )
+# --- Per-file compile options ---
-set_source_files_properties(
+set_property(SOURCE
# CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_divide.cl
@@ -249,9 +175,19 @@ set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/opencl/lib/generic/math/native_sin.cl
${CMAKE_CURRENT_SOURCE_DIR}/opencl/lib/generic/math/native_sqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/opencl/lib/generic/math/native_tan.cl
- PROPERTIES COMPILE_OPTIONS -fapprox-func
+ APPEND PROPERTY COMPILE_OPTIONS -fapprox-func
)
+add_custom_target( libclc ALL )
+
+add_custom_target( libclc-opencl-builtins COMMENT "Build libclc OpenCL builtins" )
+add_dependencies( libclc libclc-opencl-builtins )
+
+# pkg-config file
+configure_file( libclc.pc.in libclc.pc @ONLY )
+install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" )
+
enable_testing()
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -261,12 +197,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list( GET TRIPLE 1 VENDOR )
list( GET TRIPLE 2 OS )
- set( opencl_dirs )
-
- if( ${ARCH} STREQUAL amdgcn )
- list( APPEND opencl_dirs amdgpu )
- endif()
-
# Some targets' directories alias others
if( ${ARCH} STREQUAL nvptx64 )
set( DARCH ptx )
@@ -283,155 +213,231 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( OS nvidiacl )
endif()
- # Append a variety of target- and triple-based directories to search,
- # increasing in specificity.
- list( APPEND opencl_dirs ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS} )
-
- # The 'generic' directory contains all of the generic implementations of the
- # builtins. It is included first so it has the lowest search priority,
- # allowing targets to override builtins based on file names found later in
- # the list of search directories.
- # CLC builds all builtins for all targets, so unconditionally prepend the
- # 'generic' directory.
- set( clc_dirs generic ${opencl_dirs} )
- # Some OpenCL targets don't build all builtins, in which case they don't want
- # the 'generic' directory. Otherwise, prepend the 'generic' directory.
- if ( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 AND
- NOT ARCH STREQUAL clspv AND NOT ARCH STREQUAL clspv64)
- list( PREPEND opencl_dirs generic )
+ # Determine the clang target triple.
+ set(clang_triple ${t})
+ if(ARCH STREQUAL spirv AND LIBCLC_USE_SPIRV_BACKEND)
+ set(clang_triple spirv32--)
+ elseif(ARCH STREQUAL spirv64 AND LIBCLC_USE_SPIRV_BACKEND)
+ set(clang_triple spirv64--)
+ elseif(ARCH STREQUAL spirv OR ARCH STREQUAL clspv)
+ set(clang_triple spir--)
+ elseif(ARCH STREQUAL spirv64 OR ARCH STREQUAL clspv64)
+ set(clang_triple spir64--)
+ endif()
+
+ # Determine the preprocessor define for this target
+ set(MACRO_ARCH ${ARCH})
+ if(ARCH STREQUAL spirv)
+ set(MACRO_ARCH SPIRV32)
+ elseif(ARCH STREQUAL spirv64)
+ set(MACRO_ARCH SPIRV64)
+ elseif(ARCH STREQUAL clspv)
+ set(MACRO_ARCH CLSPV32)
+ elseif(ARCH STREQUAL clspv64)
+ set(MACRO_ARCH CLSPV64)
endif()
+ string(TOUPPER "CLC_${MACRO_ARCH}" target_define)
- set( clc_lib_files )
+ # Address space values
+ set(private_addrspace_val 0)
+ set(generic_addrspace_val 0)
+ if(ARCH STREQUAL amdgcn)
+ set(private_addrspace_val 5)
+ endif()
+ if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
+ set(generic_addrspace_val 4)
+ endif()
- libclc_configure_lib_source(
- clc_lib_files
- LIB_ROOT_DIR clc
- DIRS ${clc_dirs}
- )
+ # Target-specific compile flags and defines
+ set(target_compile_flags)
+ set(target_extra_defines)
+ set(opt_flags -O3)
+
+ if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
+ list(APPEND target_compile_flags -O0 -finline-hint-functions)
+ list(APPEND target_extra_defines CLC_SPIRV)
+ set(opt_flags)
+ elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64)
+ list(APPEND target_compile_flags -Wno-unknown-assumption)
+ list(APPEND target_extra_defines CLC_CLSPV)
+ elseif(ARCH STREQUAL amdgcn)
+ list(APPEND target_compile_flags "SHELL:-Xclang -mcode-object-version=none")
+ endif()
+
+ # Collect CLC sources, target specific sources will override the generic ones
+ # if present in the list.
+ set(_clc_overrides)
+ if(ARCH STREQUAL amdgcn)
+ list(APPEND _clc_overrides ${CLC_AMDGPU_SOURCES} ${CLC_AMDGCN_SOURCES})
+ elseif(DARCH STREQUAL ptx AND OS STREQUAL nvidiacl)
+ list(APPEND _clc_overrides ${CLC_PTX_NVIDIACL_SOURCES})
+ elseif(DARCH STREQUAL spirv)
+ list(APPEND _clc_overrides ${CLC_SPIRV_SOURCES})
+ elseif(DARCH STREQUAL clspv)
+ list(APPEND _clc_overrides ${CLC_CLSPV_SOURCES})
+ endif()
+ libclc_merge_sources(clc_sources ${CLC_GENERIC_SOURCES} ${_clc_overrides})
+
+ # Collect OpenCL sources. SPIR-V and Clspv targets use self-contained
+ # subsets while others merge with target-specific overrides.
+ if(ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
+ set(opencl_sources ${OPENCL_SPIRV_SOURCES})
+ elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64)
+ set(opencl_sources ${OPENCL_CLSPV_SOURCES})
+ else()
+ set(_opencl_overrides)
+ if(ARCH STREQUAL amdgcn)
+ list(APPEND _opencl_overrides ${OPENCL_AMDGCN_SOURCES})
+ if(OS STREQUAL amdhsa)
+ list(APPEND _opencl_overrides ${OPENCL_AMDGCN_AMDHSA_SOURCES})
+ endif()
+ elseif(DARCH STREQUAL ptx AND OS STREQUAL nvidiacl)
+ list(APPEND _opencl_overrides ${OPENCL_PTX_NVIDIACL_SOURCES})
+ endif()
+ libclc_merge_sources(opencl_sources
+ ${OPENCL_GENERIC_SOURCES} ${_opencl_overrides})
+ endif()
- set( opencl_lib_files )
+ # Collect unique source directories for include paths. Each source file
+ # may include .inc files from its own directory.
+ set(_clc_inc_dirs)
+ foreach(f ${clc_sources})
+ get_filename_component(dir ${f} DIRECTORY)
+ list(APPEND _clc_inc_dirs ${dir})
+ endforeach()
+ list(REMOVE_DUPLICATES _clc_inc_dirs)
- libclc_configure_lib_source(
- opencl_lib_files
- LIB_ROOT_DIR opencl
- DIRS ${opencl_dirs}
+ set(_opencl_inc_dirs)
+ foreach(f ${opencl_sources})
+ get_filename_component(dir ${f} DIRECTORY)
+ list(APPEND _opencl_inc_dirs ${dir})
+ endforeach()
+ list(REMOVE_DUPLICATES _opencl_inc_dirs)
+
+ # Common compile options shared by CLC and OpenCL libraries
+ set(compile_flags
+ -flto
+ --target=${clang_triple}
+ -nostdlib
+ -nostdlibinc
+ -cl-no-stdinc
+ -cl-std=CL3.0
+ -include opencl-c-base.h
+ -Werror=undef
+ -Wall
+ -Wextra
+ -fdiscard-value-names
+ -ffp-contract=fast-honor-pragmas
+ -fdenormal-fp-math=dynamic
+ ${target_compile_flags}
)
- foreach( d ${${t}_devices} )
- get_libclc_device_info(
- TRIPLE ${t}
- DEVICE ${d}
- CPU cpu
- ARCH_SUFFIX arch_suffix
- CLANG_TRIPLE clang_triple
- )
- message( STATUS " device: ${d} ( ${${d}_aliases} )" )
+ # Build the CLC internal builtins library.
+ string(REPLACE "-" "_" lib_suffix ${t})
+ set(clc_lib clc_builtins_${lib_suffix})
+ add_library(${clc_lib} STATIC ${clc_sources})
+ target_compile_options(${clc_lib} PRIVATE ${compile_flags})
+ target_include_directories(${clc_lib} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/clc/include
+ ${_clc_inc_dirs}
+ )
+ target_compile_definitions(${clc_lib} PRIVATE
+ ${target_define}
+ ${target_extra_defines}
+ __CLC_PRIVATE_ADDRSPACE_VAL=${private_addrspace_val}
+ __CLC_GENERIC_ADDRSPACE_VAL=${generic_addrspace_val}
+ )
+ set_target_properties(${clc_lib} PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ FOLDER "libclc/Device IR/CLC"
+ )
- set( MACRO_ARCH ${ARCH} )
- if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
- set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
- set( opt_flags )
- set( spvflags --spirv-max-version=1.1 )
- set( MACRO_ARCH SPIRV32 )
- if( ARCH STREQUAL spirv64 )
- set( MACRO_ARCH SPIRV64 )
- endif()
- elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
- set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
- set( opt_flags -O3 )
- set( MACRO_ARCH CLSPV32 )
- if( ARCH STREQUAL clspv64 )
- set( MACRO_ARCH CLSPV64 )
- endif()
- elseif( ARCH STREQUAL amdgcn )
- set( build_flags "-Xclang" "-mcode-object-version=none" )
- set( opt_flags -O3 )
- else()
- set( build_flags )
- set( opt_flags -O3 )
- endif()
+ # Build the OpenCL builtins library.
+ set(opencl_lib opencl_builtins_${lib_suffix})
+ add_library(${opencl_lib} STATIC ${opencl_sources})
+ target_compile_options(${opencl_lib} PRIVATE
+ ${compile_flags}
+ "SHELL:-Xclang -fdeclare-opencl-builtins"
+ )
+ target_include_directories(${opencl_lib} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/clc/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/opencl/include
+ ${_opencl_inc_dirs}
+ )
+ target_compile_definitions(${opencl_lib} PRIVATE
+ ${target_define}
+ ${target_extra_defines}
+ __CLC_PRIVATE_ADDRSPACE_VAL=${private_addrspace_val}
+ __CLC_GENERIC_ADDRSPACE_VAL=${generic_addrspace_val}
+ )
+ set_target_properties(${opencl_lib} PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ FOLDER "libclc/Device IR/OpenCL"
+ )
- set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
- file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
-
- # Build for OpenCL 3.0 independently of the target or device.
- list( APPEND build_flags -cl-std=CL3.0 )
-
- string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
-
- list( APPEND build_flags
- -D${CLC_TARGET_DEFINE}
- # All libclc builtin libraries see CLC headers
- -I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
- -include opencl-c-base.h
- # Error on undefined macros
- -Werror=undef
- -Wall
- -Wextra
- -fdiscard-value-names
- -ffp-contract=fast-honor-pragmas
- -fdenormal-fp-math=dynamic
- )
+ # Link the final library.
+ set(library_dir ${LIBCLC_OUTPUT_LIBRARY_DIR}/${clang_triple})
+ file(MAKE_DIRECTORY ${library_dir})
- if( NOT "${cpu}" STREQUAL "" )
- list( APPEND build_flags -mcpu=${cpu} )
- endif()
+ set(linked_bc ${CMAKE_CURRENT_BINARY_DIR}/${t}.linked.bc)
- # Generic address space support.
- # Note: when declaring builtins, we must consider that even if a target
- # formally/nominally supports the generic address space, in practice that
- # target may map it to the same target address space as another address
- # space (often the private one). In such cases we must be careful not to
- # multiply-define a builtin in a single target address space, as it would
- # result in a mangling clash.
- # For this reason we must consider the target support of the generic
- # address space separately from the *implementation* decision about whether
- # to declare certain builtins in that address space.
- # Note: we assume that if there is no distinct generic address space, it
- # maps to the private address space.
- set ( private_addrspace_val 0 )
- set ( generic_addrspace_val 0 )
- if( ARCH STREQUAL amdgcn )
- set ( private_addrspace_val 5 )
- endif()
- if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
- set ( generic_addrspace_val 4 )
+ add_custom_command(OUTPUT ${linked_bc}
+ COMMAND ${llvm-link_exe}
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/185247
More information about the cfe-commits
mailing list