Skip to content

Commit 6410941

Browse files
committed
[SYCL][LIBCLC] Allow custom tools location when building libclc
1 parent ba44e2e commit 6410941

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

libclc/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,54 @@ execute_process( COMMAND ${LLVM_CONFIG} "--bindir"
116116
# These were not properly reported in early LLVM and we don't need them
117117
list( APPEND LLVM_CXX_FLAGS -fno-rtti -fno-exceptions )
118118

119+
# Use custom toolchain to build libclc, this can be useful when dealing with
120+
# debug builds, that do not need libclc bitcode to be built using debug tools.
121+
if ( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
122+
message( WARNING "Using custom LLVM tools to build libclc: "
123+
"${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "
124+
" make sure that the tools are up to date." )
125+
126+
# find_program needs the variable to be cleared in order to perform a search.
127+
# Make sure that the cached entries are cleared as well.
128+
unset( LLVM_CLANG CACHE )
129+
unset( LLVM_AS CACHE )
130+
unset( LLVM_LINK CACHE )
131+
unset( LLVM_OPT CACHE )
132+
unset( LLVM_SPIRV CACHE )
133+
unset( LIBCLC_REMANGLER CACHE )
134+
unset( LLVM_CLANG )
135+
unset( LLVM_AS )
136+
unset( LLVM_LINK )
137+
unset( LLVM_OPT )
138+
unset( LLVM_SPIRV )
139+
unset( LIBCLC_REMANGLER )
140+
find_program( LLVM_CLANG clang PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
141+
NO_DEFAULT_PATH )
142+
find_program( LLVM_AS llvm-as PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
143+
NO_DEFAULT_PATH )
144+
find_program( LLVM_LINK llvm-link PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
145+
NO_DEFAULT_PATH )
146+
find_program( LLVM_OPT opt PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}
147+
NO_DEFAULT_PATH )
148+
find_program( LLVM_SPIRV llvm-spirv
149+
PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
150+
find_program( LIBCLC_REMANGLER libclc-remangler
151+
PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
152+
if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK
153+
OR NOT LIBCLC_REMANGLER )
154+
message( WARNING
155+
"Custom toolchain incomplete, will try the default location." )
156+
endif()
157+
endif()
158+
119159
# Print LLVM variables
120160
message( "LLVM libdir: ${LLVM_LIBRARY_DIR}" )
121161
message( "LLVM bindir: ${LLVM_TOOLS_BINARY_DIR}" )
122162
message( "LLVM cxx flags: ${LLVM_CXX_FLAGS}" )
123163
message( "" )
124164

165+
# It's OK to call find program again, if the variables have been set in the
166+
# custom location clause, find_program returns immediately.
125167
find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
126168
find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
127169
find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )

sycl/doc/GetStartedGuide.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ control which revision of Unified Runtime should be used when building DPC++:
377377
* `SYCL_PI_UR_SOURCE_DIR` is a variable used to specify the path to the Unified
378378
Runtime repository when `SYCL_PI_UR_USE_FETCH_CONTENT` is set of `OFF`.
379379

380+
### Build DPC++ libclc with a custom toolchain
381+
382+
libclc is an implementation of the OpenCL required libraries, as described in
383+
the [OpenCL C specification](https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html),
384+
additionally providing definitions of SPIR-V builtins. It is built to
385+
target-specific bitcode, that is linked against SYCL binaries. By default, the
386+
built system uses the SYCL toolchain currently being built to create libclc
387+
bitcode. This can be suboptimal in case of debug builds, in which case debug
388+
tools are used to build non-debug libclc bitcode (the notion of debug builds
389+
doesn't really apply to libclc), resulting in very long compilation time. In
390+
order to specify a directory containing custom toolchain users can set:
391+
`LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR` variable. Care is required, as the
392+
changes to the local SYCL tree might not be reflected in the custom location
393+
during the build time.
394+
380395
### Deployment
381396

382397
TODO: add instructions how to deploy built DPC++ toolchain.

0 commit comments

Comments
 (0)