Skip to content

Commit f3962f6

Browse files
authored
[libclc] build libclc as LLVM runtime (#21221)
Cherry-pick upstream commit a3a15f3 which moves libclc from LLVM_ALL_PROJECTS to LLVM_DEFAULT_RUNTIMES. Update configure, build and deploy to enable libclc runtime build. jira: CMPLRLLVM-73202
1 parent 0cb4d00 commit f3962f6

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

buildbot/configure.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def do_configure(args, passthrough_args):
8181

8282
libclc_enabled = args.cuda or args.hip or args.native_cpu
8383
if libclc_enabled:
84-
llvm_enable_projects += ";libclc"
84+
llvm_enable_runtimes += ";libclc"
8585

8686
# DeviceRTL uses -fuse-ld=lld, so enable lld.
8787
if args.offload:
@@ -149,12 +149,12 @@ def do_configure(args, passthrough_args):
149149

150150
# For clang-format, clang-tidy and code coverage
151151
llvm_enable_projects += ";clang-tools-extra"
152-
llvm_enable_runtimes += "compiler-rt"
152+
llvm_enable_runtimes += ";compiler-rt"
153153
if sys.platform != "darwin":
154154
# libclc is required for CI validation
155155
libclc_enabled = True
156-
if "libclc" not in llvm_enable_projects:
157-
llvm_enable_projects += ";libclc"
156+
if "libclc" not in llvm_enable_runtimes:
157+
llvm_enable_runtimes += ";libclc"
158158
# libclc passes `--nvvm-reflect-enable=false`, build NVPTX to enable it
159159
if "NVPTX" not in llvm_targets_to_build:
160160
llvm_targets_to_build += ";NVPTX"
@@ -216,7 +216,7 @@ def do_configure(args, passthrough_args):
216216
if llvm_enable_runtimes:
217217
cmake_cmd.extend(
218218
[
219-
"-DLLVM_ENABLE_RUNTIMES={}".format(llvm_enable_runtimes),
219+
"-DLLVM_ENABLE_RUNTIMES={}".format(llvm_enable_runtimes.lstrip(";")),
220220
]
221221
)
222222

libclc/utils/libclc-remangler/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ set(LLVM_LINK_COMPONENTS
1010
TargetParser
1111
)
1212

13+
list( PREPEND CMAKE_MODULE_PATH ${LIBCLC_SOURCE_DIR}/../clang/cmake/modules )
14+
include( AddClang )
1315
add_clang_tool(libclc-remangler LibclcRemangler.cpp)
1416

1517
setup_host_tool( libclc-remangler LIBCLC_REMANGLER
1618
libclc-remangler_exe libclc-remangler_target )
1719

1820
target_include_directories(libclc-remangler PRIVATE
1921
${CMAKE_SOURCE_DIR}/../clang/include
20-
${CMAKE_BINARY_DIR}/tools/clang/include)
22+
${LLVM_BINARY_DIR}/tools/clang/include)
2123

2224
clang_target_link_libraries(libclc-remangler
2325
PRIVATE

llvm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ endif()
104104
# This allows an easy way of setting up a build directory for llvm and another
105105
# one for llvm+clang+... using the same sources.
106106
# These projects will be included when "all" is included in LLVM_ENABLE_PROJECTS.
107-
set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;cross-project-tests;libclc;lld;lldb;mlir;polly")
107+
set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;cross-project-tests;lld;lldb;mlir;polly")
108108
set(LLVM_ALL_PROJECTS "${LLVM_ALL_PROJECTS};${LLVM_EXTERNAL_PROJECTS}")
109109

110110
# The libc and compiler-rt projects are not part of LLVM_ALL_PROJECTS, because
@@ -140,7 +140,7 @@ endforeach()
140140
#
141141
# As we migrate runtimes to using the bootstrapping build, the set of default runtimes
142142
# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
143-
set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt;openmp")
143+
set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind;libclc;compiler-rt;openmp")
144144
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;libcxx;compiler-rt;openmp;llvm-libgcc;offload;flang-rt;libclc;libsycl;orc-rt")
145145
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
146146
"Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")

sycl-jit/jit-compiler/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set(SYCL_JIT_RESOURCE_INSTALL_COMPONENTS
2020
clang-resource-headers
2121
libsycldevice)
2222

23-
if ("libclc" IN_LIST LLVM_ENABLE_PROJECTS)
23+
if ("libclc" IN_LIST LLVM_ENABLE_RUNTIMES)
2424
# If some targets required `libclc` then we should embed it for the
2525
# `sycl-jit`.
2626
list(APPEND SYCL_JIT_RESOURCE_INSTALL_COMPONENTS libspirv-builtins)
@@ -29,13 +29,20 @@ endif()
2929
set(SYCL_JIT_RESOURCE_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/rtc-resources-install)
3030

3131
set(SYCL_JIT_PREPARE_RESOURCE_COMMANDS)
32+
set(RUNTIMES_BINARY_DIR ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins)
3233
foreach(component IN LISTS SYCL_JIT_RESOURCE_INSTALL_COMPONENTS)
34+
set(BINARY_DIR ${CMAKE_BINARY_DIR})
35+
if("${component}" STREQUAL "libspirv-builtins")
36+
set(BINARY_DIR ${RUNTIMES_BINARY_DIR})
37+
list(APPEND SYCL_JIT_RESOURCE_DEPS libclc)
38+
else()
39+
list(APPEND SYCL_JIT_RESOURCE_DEPS ${component})
40+
endif()
3341
list(APPEND SYCL_JIT_PREPARE_RESOURCE_COMMANDS
34-
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix ${SYCL_JIT_RESOURCE_INSTALL_DIR} --component "${component}"
42+
COMMAND ${CMAKE_COMMAND} --install ${BINARY_DIR} --prefix ${SYCL_JIT_RESOURCE_INSTALL_DIR} --component "${component}"
3543
)
3644
endforeach()
3745

38-
set(SYCL_JIT_RESOURCE_DEPS ${SYCL_JIT_RESOURCE_INSTALL_COMPONENTS})
3946
# OpenCL-Headers doesn't have a corresponding build target:
4047
list(FILTER SYCL_JIT_RESOURCE_DEPS EXCLUDE REGEX "^OpenCL-Headers$")
4148

sycl/CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,14 @@ if("lld" IN_LIST LLVM_ENABLE_PROJECTS)
527527
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS lld)
528528
endif()
529529

530-
if("libclc" IN_LIST LLVM_ENABLE_PROJECTS)
531-
add_dependencies(sycl-toolchain libspirv-builtins)
530+
if("libclc" IN_LIST LLVM_ENABLE_RUNTIMES)
531+
add_dependencies(sycl-toolchain libclc)
532532
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins)
533533
endif()
534534

535535
if("cuda" IN_LIST SYCL_ENABLE_BACKENDS)
536536
# Ensure that libclc is enabled.
537-
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
537+
list(FIND LLVM_ENABLE_RUNTIMES libclc LIBCLC_FOUND)
538538
if( LIBCLC_FOUND EQUAL -1 )
539539
message(FATAL_ERROR
540540
"CUDA support requires adding \"libclc\" to the CMake argument \"LLVM_ENABLE_PROJECTS\"")
@@ -546,7 +546,7 @@ endif()
546546

547547
if("hip" IN_LIST SYCL_ENABLE_BACKENDS)
548548
# Ensure that libclc is enabled.
549-
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
549+
list(FIND LLVM_ENABLE_RUNTIMES libclc LIBCLC_FOUND)
550550
if( LIBCLC_FOUND EQUAL -1 )
551551
message(FATAL_ERROR
552552
"HIP support requires adding \"libclc\" to the CMake argument \"LLVM_ENABLE_PROJECTS\"")
@@ -578,15 +578,22 @@ add_custom_command(OUTPUT __force_it
578578
set(__chain_dep __force_it)
579579

580580
set(manifest_list)
581+
set(RUNTIMES_INSTALL_SCRIPT "${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/cmake_install.cmake")
581582
foreach( comp ${SYCL_TOOLCHAIN_DEPLOY_COMPONENTS} )
583+
set(INSTALL_SCRIPT "${CMAKE_BINARY_DIR}/cmake_install.cmake")
584+
set(RUNTIME_TARGET)
585+
if("${comp}" STREQUAL "libspirv-builtins")
586+
set(RUNTIME_TARGET libclc)
587+
set(INSTALL_SCRIPT ${RUNTIMES_INSTALL_SCRIPT})
588+
endif()
582589
message( STATUS "Adding component ${comp} to deploy")
583590

584591
set (manifest_file ${CMAKE_CURRENT_BINARY_DIR}/install_manifest_${comp}.txt)
585592
add_custom_command(OUTPUT ${manifest_file}
586593
COMMAND "${CMAKE_COMMAND}"
587594
"-DCMAKE_INSTALL_COMPONENT=${comp}"
588-
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
589-
DEPENDS ${__chain_dep}
595+
-P "${INSTALL_SCRIPT}"
596+
DEPENDS ${__chain_dep} ${RUNTIME_TARGET}
590597
COMMENT "Deploying component ${comp}"
591598
USES_TERMINAL
592599
)

0 commit comments

Comments
 (0)