Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,22 @@ else()
endif()
use_component(${CLSPV_LIBCLC_SOURCE_DIR})

set(LLVM_ENABLE_PROJECTS "${LLVM_ENABLE_PROJECTS};libclc")
set(LLVM_ENABLE_RUNTIMES "libclc" CACHE STRING "Semicolon-separated list of runtimes to build, or \"all\".")
set(LIBCLC_TARGETS_TO_BUILD clspv--;clspv64--)
set(LLVM_EXTERNAL_LIBCLC_SOURCE_DIR ${CLSPV_LIBCLC_SOURCE_DIR})

# Tell LLVM to build the native target (needed to build libclc).
set(CLSPV_LLVM_TARGETS_TO_BUILD "Native")

# Disabling zlib as build is failing on libclc when enabled
set(LLVM_ENABLE_ZLIB "OFF" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
endif()

# Tell LLVM not to build any targets.
set(LLVM_TARGETS_TO_BUILD ""
set(LLVM_TARGETS_TO_BUILD "${CLSPV_LLVM_TARGETS_TO_BUILD}"
CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")

# Then pull in LLVM for building.
add_subdirectory(${CLSPV_LLVM_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm EXCLUDE_FROM_ALL)
add_subdirectory(${CLSPV_LLVM_SOURCE_DIR} ${CLSPV_LLVM_BINARY_DIR} EXCLUDE_FROM_ALL)

# Ensure clspv and LLVM use the same build options (e.g. -D_FILE_OFFSET_BITS=64).
list(APPEND CMAKE_MODULE_PATH ${CLSPV_LLVM_SOURCE_DIR}/cmake/modules/)
Expand Down
16 changes: 8 additions & 8 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ add_custom_target(clspv64_builtin_library
DEPENDS ${CLSPV64_LIBRARY_OUTPUT_FILE})

if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
set(CLSPV_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/tools/libclc/clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/tools/libclc/clspv64--.bc)
set(CLSPV_LIBRARY_INPUT_DEP prepare-clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_DEP prepare-clspv64--.bc)
set(CLSPV_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/lib/clang/${CLANG_EXECUTABLE_VERSION}/lib/libclc/clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/lib/clang/${CLANG_EXECUTABLE_VERSION}/lib/libclc/clspv64--.bc)
set(CLSPV_LIBRARY_DEP libclc)
set(CLSPV64_LIBRARY_DEP libclc)
else()
set(CLSPV_LIBRARY_INPUT_FILE ${CLSPV_EXTERNAL_LIBCLC_DIR}/clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_FILE ${CLSPV_EXTERNAL_LIBCLC_DIR}/clspv64--.bc)
set(CLSPV_LIBRARY_INPUT_DEP ${CLSPV_LIBRARY_INPUT_FILE})
set(CLSPV64_LIBRARY_INPUT_DEP ${CLSPV64_LIBRARY_INPUT_FILE})
set(CLSPV_LIBRARY_DEP ${CLSPV_LIBRARY_INPUT_FILE})
set(CLSPV64_LIBRARY_DEP ${CLSPV64_LIBRARY_INPUT_FILE})
endif()

add_custom_command(
Expand All @@ -135,7 +135,7 @@ add_custom_command(
--header-var=${CLSPV_LIBRARY_DATA_VAR_NAME}
--header-size=${CLSPV_LIBRARY_SIZE_VAR_NAME}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${BAKE_FILE_PYTHON_FILE} ${CLSPV_LIBRARY_INPUT_DEP} ${CLSPV_LIBRARY_INPUT_FILE}
DEPENDS ${BAKE_FILE_PYTHON_FILE} ${CLSPV_LIBRARY_DEP}
)

add_custom_command(
Expand All @@ -146,5 +146,5 @@ add_custom_command(
--header-var=${CLSPV64_LIBRARY_DATA_VAR_NAME}
--header-size=${CLSPV64_LIBRARY_SIZE_VAR_NAME}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${BAKE_FILE_PYTHON_FILE} ${CLSPV64_LIBRARY_INPUT_DEP} ${CLSPV64_LIBRARY_INPUT_FILE}
DEPENDS ${BAKE_FILE_PYTHON_FILE} ${CLSPV64_LIBRARY_DEP}
)
6 changes: 5 additions & 1 deletion deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"subrepo" : "llvm/llvm-project",
"branch" : "main",
"subdir" : "third_party/llvm",
"commit" : "e68a20e0b7623738d6af736d3aa02625cba6126a"
"commit" : "5bca8f2f97d23c3562544e959702826eb20696af",
"patches" : [
{"patch": "patches/0001-libclc-CMake-include-GetClangResourceDir-155836.patch"},
{"patch": "patches/0002-fix-clang_cmake_builddir.patch"}
]
},
{
"name" : "SPIRV-Headers",
Expand Down
2 changes: 1 addition & 1 deletion kokoro/scripts/linux/build-amber.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SRC=$PWD/github/clspv
AMBER_SRC=$PWD/github/amber

cd $SRC
python3 utils/fetch_sources.py
python3 utils/fetch_sources.py --ci

cd $BUILD_ROOT/github
git clone https://github.com/google/amber.git amber
Expand Down
2 changes: 1 addition & 1 deletion kokoro/scripts/linux/build-clvk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fi

# Get Clspv dependencies.
cd $SRC
python3 utils/fetch_sources.py
python3 utils/fetch_sources.py --ci

VULKAN_VERSION=v1.3.243

Expand Down
2 changes: 1 addition & 1 deletion kokoro/scripts/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BUILD_ROOT=$PWD
SRC=$PWD/github/clspv

cd $SRC
python3 utils/fetch_sources.py
python3 utils/fetch_sources.py --ci

mkdir build && cd $SRC/build

Expand Down
2 changes: 1 addition & 1 deletion kokoro/scripts/macos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export PATH="$PWD/cmake-$CMAKE_VER-macos-universal/CMake.app/Contents/bin:$PATH"

# Get dependencies.
cd $SRC
python utils/fetch_sources.py
python utils/fetch_sources.py --ci

mkdir build && cd $SRC/build

Expand Down
4 changes: 2 additions & 2 deletions kokoro/scripts/windows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set PATH=c:\cmake-3.31.2\bin;%PATH%
set PATH=c:\Python312;%PATH%

cd %SRC%
python utils/fetch_sources.py
python utils/fetch_sources.py --ci

:: #########################################
:: set up msvc build env
Expand All @@ -50,7 +50,7 @@ if "%KOKORO_GITHUB_COMMIT%." == "." (
set BUILD_SHA=%KOKORO_GITHUB_COMMIT%
)

cmake -G%GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DLLVM_TARGETS_TO_BUILD="" .. -Thost=x64
cmake -G%GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% .. -Thost=x64

if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%

Expand Down
17 changes: 9 additions & 8 deletions lib/FrontendPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {
} else if (auto *VT = dyn_cast<VectorType>(canonical)) {
return ContainsSizedType(VT->getElementType(), width);
} else if (auto *RT = dyn_cast<RecordType>(canonical)) {
for (auto field_decl : RT->getDecl()->fields()) {
for (auto field_decl : RT->getOriginalDecl()->fields()) {
if (ContainsSizedType(field_decl->getType(), width))
return true;
}
Expand All @@ -132,7 +132,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {
} else if (auto *AT = dyn_cast<ArrayType>(canonical)) {
return ContainsPointerType(AT->getElementType());
} else if (auto *RT = dyn_cast<RecordType>(canonical)) {
for (auto field_decl : RT->getDecl()->fields()) {
for (auto field_decl : RT->getOriginalDecl()->fields()) {
if (ContainsPointerType(field_decl->getType()))
return true;
}
Expand All @@ -148,7 +148,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {
} else if (isa<ArrayType>(canonical)) {
return true;
} else if (auto *RT = dyn_cast<RecordType>(canonical)) {
for (auto field_decl : RT->getDecl()->fields()) {
for (auto field_decl : RT->getOriginalDecl()->fields()) {
if (ContainsArrayType(field_decl->getType()))
return true;
}
Expand All @@ -169,7 +169,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {
} else if (auto *AT = dyn_cast<ArrayType>(canonical)) {
return IsRecursiveType(AT->getElementType(), seen);
} else if (auto *RT = dyn_cast<RecordType>(canonical)) {
for (auto field_decl : RT->getDecl()->fields()) {
for (auto field_decl : RT->getOriginalDecl()->fields()) {
if (IsRecursiveType(field_decl->getType(), seen))
return true;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {

// To avoid infinite recursion, first verify that the record is not
// recursive and then that its fields are supported.
for (auto *field_decl : RT->getDecl()->fields()) {
for (auto *field_decl : RT->getOriginalDecl()->fields()) {
if (!IsSupportedType(field_decl->getType(), SR, IsKernelParameter)) {
return false;
}
Expand Down Expand Up @@ -462,9 +462,10 @@ struct ExtraValidationConsumer final : public ASTConsumer {
return false;
}

const auto &record_layout = context.getASTRecordLayout(RT->getDecl());
const auto &record_layout =
context.getASTRecordLayout(RT->getOriginalDecl());
const FieldDecl *prev = nullptr;
for (auto field_decl : RT->getDecl()->fields()) {
for (auto field_decl : RT->getOriginalDecl()->fields()) {
const auto field_type = field_decl->getType();
const unsigned field_no = field_decl->getFieldIndex();
const uint64_t field_offset =
Expand Down Expand Up @@ -893,7 +894,7 @@ struct ExtraValidationConsumer final : public ASTConsumer {
clustered_args->completeDefinition();
if (!clustered_args->field_empty()) {
auto record_type =
FD->getASTContext().getRecordType(clustered_args);
FD->getASTContext().getCanonicalTagType(clustered_args);
if (!IsSupportedLayout(record_type, 0, SSBO, FD->getASTContext(),
FD->getSourceRange(),
FD->getSourceRange())) {
Expand Down
26 changes: 26 additions & 0 deletions patches/0001-libclc-CMake-include-GetClangResourceDir-155836.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 9d96c47f6b922ba02dee62337236f1b87074cfe0 Mon Sep 17 00:00:00 2001
From: Romaric Jodin <rjodin@google.com>
Date: Thu, 28 Aug 2025 18:56:33 +0200
Subject: [PATCH 1/3] libclc: CMake: include GetClangResourceDir (#155836)

`get_clang_resource_dir` is not guarantee to be there. Make sure of it
by including `GetClangResourceDir`.
---
libclc/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 756e097dcf12..5c4e12793329 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -99,6 +99,7 @@ else()

# 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.
+ include(GetClangResourceDir)
get_clang_resource_dir( LIBCLC_OUTPUT_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. )

# Note we do not adhere to LLVM_ENABLE_PER_TARGET_RUNTIME_DIR.
--
2.51.0.384.g4c02a37b29-goog

48 changes: 48 additions & 0 deletions patches/0002-fix-clang_cmake_builddir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From e4916b6bbd1b4e89d67b6a65e89839942b0be804 Mon Sep 17 00:00:00 2001
From: Romaric Jodin <rjodin@google.com>
Date: Thu, 28 Aug 2025 16:22:17 +0200
Subject: [PATCH 2/3] fix clang_cmake_builddir

When building llvm from a subdirectory (like clspv does)
`CMAKE_BINARY_DIR` is at the top of the build directory.

When building runtimes (libclc for example), the build fails looking
for clang (through `find_package` looking at `LLVM_BINARY_DIR` with
`NO_DEFAULT_PATH` & `NO_CMAKE_FIND_ROOT_PATH`) because clang is not in
`LLVM_BINARY_DIR`.

Fix that issue by setting `clang_cmake_builddir` the same way we set
`llvm_cmake_builddir` from `LLVM_BINARY_DIR`.

For default llvm build (using llvm as the main cmake project), it
should not change anything.
---
clang/cmake/modules/CMakeLists.txt | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/cmake/modules/CMakeLists.txt b/clang/cmake/modules/CMakeLists.txt
index d2d68121371b..b3b4a74f6d47 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -8,15 +8,14 @@ include(FindPrefixFromConfig)
# the usual CMake convention seems to be ${Project}Targets.cmake.
set(CLANG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/clang" CACHE STRING
"Path for CMake subdirectory for Clang (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/clang')")
-# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
-set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang")

# Keep this in sync with llvm/cmake/CMakeLists.txt!
set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
"Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
-string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
-set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
+string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_builddir "${LLVM_LIBRARY_DIR}")
+set( llvm_cmake_builddir "${llvm_builddir}/cmake/llvm")
+set(clang_cmake_builddir "${llvm_builddir}/cmake/clang")

get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
--
2.51.0.384.g4c02a37b29-goog

12 changes: 10 additions & 2 deletions utils/fetch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, json):
self.branch = json['branch']
self.subdir = os.path.join(TOP_DIR, json['subdir']) if ('subdir' in json) else TOP_DIR
self.commit = json['commit']
self.patches = json.get('patches', [])

def GetUrl(self, style='https'):
"""Returns the URL for the repository."""
Expand Down Expand Up @@ -131,12 +132,18 @@ def Fetch(self, shallow):
cmd.append(self.commit if shallow else self.branch)
command_output(cmd, self.subdir)

def Checkout(self, shallow):
def Patch(self, patch, ci):
command_output(['git', 'apply' if ci else 'am', os.path.join(TOP_DIR, patch)], self.subdir)

def Checkout(self, shallow, ci):
if not os.path.exists(os.path.join(self.subdir,'.git')):
self.InitRepo(shallow)
if not self.HasCommit():
self.Fetch(shallow)
command_output(['git', 'checkout', self.commit], self.subdir)
for patch in self.patches:
self.Patch(patch['patch'], ci)



def GetGoodCommits():
Expand All @@ -162,6 +169,7 @@ def main():
parser.add_argument('--deps', choices=all_deps, nargs='+', default=all_deps,
help='A list of dependencies to fetch sources for. '
'All is the default.')
parser.add_argument('--ci', action='store_true')

args = parser.parse_args()

Expand All @@ -175,7 +183,7 @@ def main():
if c.name not in args.deps:
continue
print('Get {n}\n'.format(n=c.name))
c.Checkout(args.shallow)
c.Checkout(args.shallow, args.ci)
sys.exit(0)


Expand Down