Skip to content

Commit d4e759f

Browse files
committed
Revert "Revert all"
This reverts commit 2fd4e94f242c982e9f6d167a388252a9b00a9ec7.
1 parent 6e5aa7a commit d4e759f

File tree

10 files changed

+108
-7
lines changed

10 files changed

+108
-7
lines changed

.github/workflows/root-ci-config/buildconfig/global.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
adaptivecpp=ON
12
alien=OFF
23
all=OFF
34
arrow=OFF

cmake/modules/RootBuildOptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ endfunction()
7777
# The default value can be changed as many times as we wish before calling ROOT_APPLY_OPTIONS()
7878
#--------------------------------------------------------------------------------------------------
7979

80+
ROOT_BUILD_OPTION(adaptivecpp ON "Build AdaptiveCPP, for SYCL support")
8081
ROOT_BUILD_OPTION(arrow OFF "Enable support for Apache Arrow")
8182
ROOT_BUILD_OPTION(asimage ON "Enable support for image processing via libAfterImage")
8283
ROOT_BUILD_OPTION(asserts OFF "Enable asserts (defaults to ON for CMAKE_BUILD_TYPE=Debug and/or dev=ON)")

interpreter/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
2727
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
2828
set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
2929
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
30-
set(CLANG_BUILD_TOOLS OFF CACHE BOOL "")
30+
set(CLANG_BUILD_TOOLS ON CACHE BOOL "")
3131
# It looks like that turning off CLANG_BUILD_TOOLS is not enough.
3232
set(CLANG_TOOL_ARCMT_TEST_BUILD OFF CACHE BOOL "")
3333
set(CLANG_TOOL_CLANG_CHECK_BUILD OFF CACHE BOOL "")
@@ -53,7 +53,10 @@ set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON CACHE BOOL "")
5353
# found before (because the user turned on cuda or tmva-gpu), this will not have
5454
# an effect, which is fine.
5555
# (Note that the option is very counter-intuitive: We turn *on* disabling it...)
56-
set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON)
56+
# Special case when we want to build cling with adaptiveCpp
57+
if(NOT adaptivecpp)
58+
set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON)
59+
endif()
5760

5861
# will be set again in case NOT builtin_llvm
5962
set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm")
@@ -390,6 +393,9 @@ if (builtin_clang)
390393
${CLANG_BINARY_DIR}/include
391394
CACHE STRING "Clang include directories.")
392395
set(CLANG_CMAKE_DIR "${CMAKE_BINARY_DIR}/lib/cmake/clang/")
396+
set(CLANG_EXECUTABLE_PATH
397+
"${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}"
398+
CACHE STRING "Path to just‐built clang (if builtin_clang).")
393399
else()
394400
find_package(Clang REQUIRED CONFIG)
395401
message(STATUS "Found Clang ${CLANG_PACKAGE_VERSION} in ${CLANG_CMAKE_DIR}")

interpreter/cling/CMakeLists.txt

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ else(WIN32)
88
cmake_minimum_required(VERSION 3.5)
99
endif(WIN32)
1010

11-
if(adaptivecpp)
12-
add_compile_definitions(ADAPTIVECPP_ENABLED)
13-
endif()
14-
1511
# If we are not building as a part of LLVM, build Cling as an
1612
# standalone project, using LLVM as an external library:
1713
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
@@ -140,6 +136,20 @@ set(CLING_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
140136
set(LLVM_TOOLS_BINARY_DIR "${LLVM_BINARY_DIR}/bin")
141137
if(DEFINED CLING_ROOT_BUILD)
142138
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${LLVM_TOOLS_BINARY_DIR}")
139+
140+
if(adaptivecpp)
141+
# Hack for now to make it work with adaptiveCpp without making more changes
142+
# Ensure runtime ACPP directory exists to prevent SYCL from running
143+
set(ACPP_RUNTIME_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../lib/hipSYCL/")
144+
file(MAKE_DIRECTORY "${ACPP_RUNTIME_DIRECTORY}")
145+
146+
# Create a symbolic link to the bitcode directory
147+
execute_process(
148+
COMMAND ${CMAKE_COMMAND} -E create_symlink
149+
"${CMAKE_BINARY_DIR}/lib/hipSYCL/bitcode"
150+
"${ACPP_RUNTIME_DIRECTORY}/bitcode"
151+
)
152+
endif()
143153
endif()
144154

145155
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
@@ -248,7 +258,7 @@ if(MSVC)
248258
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++14")
249259
endif()
250260
endif()
251-
else()
261+
elseif(NOT adaptivecpp)
252262
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
253263
endif()
254264

@@ -482,6 +492,35 @@ if (TARGET clang-headers)
482492
list(APPEND LLVM_COMMON_DEPENDS clang-headers)
483493
endif()
484494

495+
if(adaptivecpp)
496+
set(ADAPTIVE_CPP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/AdaptiveCpp)
497+
set(WITH_CUDA_BACKEND false)
498+
set(Boost_FIBER_LIBRARY_DEBUG false)
499+
set(LLVM_VERSION_MAJOR 18)
500+
list(INSERT CMAKE_MODULE_PATH 0 "${ADAPTIVE_CPP_SOURCE_DIR}/cmake/")
501+
add_compile_definitions(ADAPTIVECPP_ENABLED)
502+
503+
set(ACPP_EXPORTS
504+
acpp-clang-cbs
505+
acpp-clang
506+
acpp-common
507+
llvm-to-backend
508+
# llvm-to-ptx
509+
llvm-to-host
510+
# rt-backend-cuda
511+
rt-backend-omp
512+
acpp-rt
513+
)
514+
515+
set_property(GLOBAL APPEND PROPERTY CLING_EXPORTS ${ACPP_EXPORTS})
516+
add_subdirectory(${ADAPTIVE_CPP_SOURCE_DIR})
517+
518+
if (TARGET intrinsics_gen)
519+
add_dependencies(acpp-clang-cbs intrinsics_gen)
520+
add_dependencies(llvm-to-backend intrinsics_gen)
521+
endif()
522+
endif()
523+
485524
add_subdirectory(include/cling/Interpreter)
486525
add_subdirectory(lib)
487526

interpreter/cling/lib/Interpreter/BackendPasses.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#include "llvm/Transforms/Scalar.h"
3030
#include "llvm/Transforms/Utils.h"
3131

32+
#ifdef ADAPTIVECPP_ENABLED
33+
#include "hipSYCL/compiler/SMCPCompatPass.hpp"
34+
#include "hipSYCL/compiler/GlobalsPruningPass.hpp"
35+
#include "hipSYCL/compiler/sscp/TargetSeparationPass.hpp"
36+
#endif
37+
3238
//#include "clang/Basic/LangOptions.h"
3339
//#include "clang/Basic/TargetOptions.h"
3440
#include "clang/Basic/CharInfo.h"
@@ -511,6 +517,18 @@ void BackendPasses::CreatePasses(int OptLevel, llvm::ModulePassManager& MPM,
511517
std::optional<PGOOptions> PGOOpt;
512518
PassBuilder PB(&m_TM, PTO, PGOOpt, &PIC);
513519

520+
#ifdef ADAPTIVECPP_ENABLED
521+
PB.registerOptimizerLastEPCallback([](llvm::ModulePassManager &MPM, OptimizationLevel) {
522+
MPM.addPass(hipsycl::compiler::SMCPCompatPass{});
523+
MPM.addPass(hipsycl::compiler::GlobalsPruningPass{});
524+
});
525+
526+
PB.registerPipelineStartEPCallback(
527+
[&](llvm::ModulePassManager &MPM, OptimizationLevel Level) {
528+
MPM.addPass(hipsycl::compiler::TargetSeparationPass{""});
529+
});
530+
#endif
531+
514532
// Attempt to load pass plugins and register their callbacks with PB.
515533
for (auto& PluginFN : m_CGOpts.PassPlugins) {
516534
auto PassPlugin = PassPlugin::Load(PluginFN);

interpreter/cling/lib/Interpreter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#------------------------------------------------------------------------------
88

99
set(LIBS
10+
acpp-clang
11+
acpp-rt
1012
clingUtils
1113
clangCodeGen
1214
clangDriver

interpreter/cling/lib/Interpreter/Interpreter.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,31 @@ namespace cling {
212212
m_RuntimeOptions{},
213213
m_OptLevel(parentInterp ? parentInterp->m_OptLevel : -1) {
214214

215+
#ifdef ADAPTIVECPP_ENABLED
216+
// Compiler arguments for ADAPTIVECPP
217+
static constexpr std::array<const char*, 8> extraArgs = {
218+
"-D__OPENSYCL__",
219+
"-D__HIPSYCL__",
220+
"-D__ADAPTIVECPP__",
221+
"-D__ACPP__",
222+
"-D__ACPP_ENABLE_LLVM_SSCP_TARGET__",
223+
"-ffp-contract=fast",
224+
"-Xclang",
225+
"-disable-O0-optnone"
226+
};
227+
228+
std::vector<const char*> argvChar;
229+
argvChar.reserve(argc + 8);
230+
231+
// Copy existing arguments
232+
argvChar.assign(argv, argv + argc);
233+
234+
argvChar.insert(argvChar.end(), extraArgs.begin(), extraArgs.end());
235+
argvChar.push_back(nullptr); // signal end of array
236+
237+
m_Opts = InvocationOptions(argvChar.size() - 1, argvChar.data());
238+
#endif
239+
215240
if (handleSimpleOptions(m_Opts))
216241
return;
217242

interpreter/cling/lib/Utils/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ set(LLVM_LINK_COMPONENTS
2727
)
2828

2929
set(LIBS
30+
acpp-clang
31+
acpp-rt
3032
clangCodeGen
3133
clangDriver
3234
clangFrontend

interpreter/cling/tools/driver/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ set(LLVM_NO_DEAD_STRIP 1)
1212
set(LLVM_LINK_COMPONENTS Support)
1313
if(BUILD_SHARED_LIBS)
1414
set(LIBS
15+
acpp-clang
16+
acpp-rt
1517

1618
clangFrontendTool
1719

@@ -25,6 +27,9 @@ if(BUILD_SHARED_LIBS)
2527
)
2628
else()
2729
set(LIBS
30+
acpp-clang
31+
acpp-rt
32+
2833
clangASTMatchers
2934
clangFrontendTool
3035

interpreter/cling/tools/libcling/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ set(SOURCES
1111
)
1212

1313
set(LIBS
14+
acpp-clang
15+
acpp-rt
1416
clangAnalysis
1517
clangDriver
1618
clangFrontend

0 commit comments

Comments
 (0)