66 Commits

Author SHA1 Message Date
Wenju He
7be9972cb2
[libclc] Fix llvm-spirv dependency when llvm-spirv is built in-tree (#188896)
When SPIRV-LLVM-Translator is built in-tree (i.e., placed in
llvm/projects folder), llvm-spirv target exists.

Drop legacy llvm-spirv_target dependency (was for non-runtime build) and
add llvm-spirv to runtimes dependencies.
2026-03-28 07:06:23 +08:00
Wenju He
4abb927bac
[libclc][CMake] Use clang/llvm-ar on Windows (#186726)
When LLVM_TARGETS_TO_BUILD contains host target, runtime build sets
CMAKE_C_COMPILER to clang-cl on Windows.
Changes to fix build on Windows:
- libclc struggles to pass specific flags to clang-cl MSVC-like interface.
- compile flag handling will be consistent across all host systems.
- libclc build is cross-compilation for offloading targets.
2026-03-17 09:45:52 +08:00
Wenju He
1c04e7fada
[libclc] fix compiler check with --target=spirv64 and -disable-llvm-passes (#185376)
Fix "unknown target triple" errors when LLVM_TARGETS_TO_BUILD is empty.

Adding -disable-llvm-passes reduces this to a very basic sanity check
of Clang frontend. This allows the test to pass even if SPIR-V backend
is not enabled, as the frontend can still generate IR for the target.
2026-03-17 07:59:14 +08:00
Wenju He
e945f7afbe
[libclc][CMake] Rename opencl to clc in add_libclc_library, update comment (#186544)
Align with cmake function name.
2026-03-14 10:04:19 +08:00
Wenju He
8175bd92ea
[libclc][CMake] Check SOURCES and LIBRARIES arguments are not empty (#186542) 2026-03-14 08:52:32 +08:00
Wenju He
d352aac32c
[libclc][CMake] Add check-libclc umbrella test target (#186053)
This allows running the full test suite using `ninja check-libclc`.
2026-03-12 19:55:18 +08:00
Wenju He
aa5767ee19
[libclc][CMake] Add back OUTPUT_FILENAME and PARENT_TARGET (#185633)
They were droped in e20ae16ce672.
OUTPUT_FILENAME is helpful for customizing library name. PARENT_TARGET
could be helpful for customizing dependency control.
2026-03-11 07:45:38 +08:00
Wenju He
90e5a1ef74
[libclc][CMake] Append target_name to external-funcs test target name (#185639)
Avoid name conflicts when multiple libararies use the same target
triple.
2026-03-10 20:53:41 +08:00
Joseph Huber
e20ae16ce6
[libclc] Use custom CMake handling to overhaul libclc compilation (#185247)
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.
2026-03-09 13:53:39 +08:00
Joseph Huber
088f740035
[libclc] Add custom CMake language handling for OpenCL files (#185243)
Summary:
The current handling of `libclc` is to use custom clang jobs to compile
source files. This is the way we used to compile GPU libraries, but we
have largely moved away from this. The eventual goal is to simple be
able to use `clang` like a normal project. One barrier to this is the
lack of language support for OpenCL in CMake.

This PR uses CMake's custom language support to define a minimal OpenCL
language, largely just a wrapper around `clang -x cl`. This does
nothing, just enables the support. Future PRs will need to untangle the
mess of dependencies.

The 'link+opt' steps that we now do should be able to simply be done as
a custom `llvm-link` and `opt` job on the library, which isn't ideal but
it still better than the current state.
2026-03-07 22:34:17 -06:00
Matt Arsenault
732f66eccc
libclc: Reimplement amdhsa workitem functions (#184571)
These were quite out of date and broken. These were originally
implemented for clover, which at one point was aiming for HSA v2 ABI
near compatibility. Since clover has been removed, that path is dead.
This was also broken for the modern HSA ABIs. Update to assume the
v5 ABI.
2026-03-04 10:47:42 +01:00
Wenju He
5b1a0230d9
[libclc][CMake] Add COMPONENT ${ARG_PARENT_TARGET} to install (#182716)
Toolchain can specify the component to selectively install libclc to a
deploy folder. E.g. our downstream SYCL toolchain deploy:
https://github.com/intel/llvm/blob/e7b423fd517d/sycl/CMakeLists.txt#L531

Also check ARG_PARENT_TARGET is defined and non-empty.

Co-authored-by: Jinsong Ji <jinsong.ji@intel.com>
2026-02-23 08:20:42 +08:00
Matt Arsenault
ee2ebaf0d4
libclc: Fix broken symlinks (#181247) 2026-02-12 22:45:09 +01:00
Wenju He
39f3d72b72
[libclc] Only use software fma for r600 target (#179428)
Implement generic __clc_fma with __builtin_elementwise_fma for all
targets except for r600.

Add --spirv-ext=+SPV_KHR_fma flag to SPIR-V generation. SPIR-V target
supports @llvm.fma since SPV_KHR_fma was implemented in llvm-spirv
(https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/3467) and
SPIR-V backend (8f8dfbf8c9f0).
This PR assumes SPIR-V consumer with modern hardware supports fma.
2026-02-04 08:17:57 +08:00
Wenju He
5b4f424454
[libclc][NFC] Fix build warning typedef-redefinition (#177888)
Fix downstream build warning:
redefinition of typedef 'ushort8' is a C11 feature [-Wtypedef-redefinition]

clctypes.h re-defines typedef from opencl-c-base.h. Both files are
included in libclc/opencl folder.
This PR deletes clctypes.h and includes opencl-c-base.h for both CLC and
OpenCL libraries.
Previously opencl-c-base.h was only included in OpenCL library.
2026-01-29 08:06:24 +08:00
Wenju He
e421ef2532
[libclc] Make output filename configurable; rename top-level targets (#178119)
This PR relates to c5cb48c39701.

Pass `OUTPUT_FILENAME` to `add_libclc_builtin_set` to allow downstream
output naming (e.g. libspirv in
https://github.com/intel/llvm/tree/sycl/libclc).

Rename top-level target to `libclc-${ARG_TRIPLE}` to avoid collision
with `library-${ARG_ARCH_SUFFIX}` in our downstream when libclc TRIPLE
matches libspirv ARCH_SUFFIX.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-28 12:41:16 +08:00
Joseph Huber
295d5484c0
Reapply "[libclc] Rework libclc naming convention to use the triple (#177465)" (#178033)
This reverts commit 2c9efd0177910753008767a8c50e62f676721443.
2026-01-26 15:18:09 -06:00
Aiden Grossman
2c9efd0177 Revert "[libclc] Rework libclc naming convention to use the triple (#177465)"
This reverts commit c5cb48c39701086393d1177929a328868849fc72.

This was causing CMake configuration failures for the postsubmit
buildbot checking the premerge configuration:
```
2026-01-26T13:46:47.849060051Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command):
2026-01-26T13:46:47.849086795Z   Attempt to add a custom rule to output
2026-01-26T13:46:47.849088339Z
2026-01-26T13:46:47.849090228Z     /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule
2026-01-26T13:46:47.849101045Z
2026-01-26T13:46:47.849103110Z   which already has a custom rule.
2026-01-26T13:46:47.849104522Z Call Stack (most recent call first):
2026-01-26T13:46:47.849106013Z   /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set)
2026-01-26T13:46:47.849107043Z
2026-01-26T13:46:47.849108005Z
2026-01-26T13:46:47.851329201Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command):
2026-01-26T13:46:47.851341592Z   Attempt to add a custom rule to output
2026-01-26T13:46:47.851343793Z
2026-01-26T13:46:47.851346484Z     /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule
2026-01-26T13:46:47.851348290Z
2026-01-26T13:46:47.851350814Z   which already has a custom rule.
2026-01-26T13:46:47.851352774Z Call Stack (most recent call first):
2026-01-26T13:46:47.851354795Z   /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set)
2026-01-26T13:46:47.851356284Z
2026-01-26T13:46:47.851357807Z
2026-01-26T13:46:47.853361832Z CMake Error at /home/gha/llvm-project/libclc/cmake/modules/AddLibclc.cmake:407 (add_custom_command):
2026-01-26T13:46:47.853368044Z   Attempt to add a custom rule to output
2026-01-26T13:46:47.853369290Z
2026-01-26T13:46:47.853370974Z     /home/gha/llvm-project/build/lib/clang/23/lib/r600--/libclc.bc.rule
2026-01-26T13:46:47.853372068Z
2026-01-26T13:46:47.853373338Z   which already has a custom rule.
2026-01-26T13:46:47.853374637Z Call Stack (most recent call first):
2026-01-26T13:46:47.853376034Z   /home/gha/llvm-project/libclc/CMakeLists.txt:460 (add_libclc_builtin_set)
2026-01-26T13:46:47.853377158Z
2026-01-26T13:46:47.853378154Z
2026-01-26T13:47:02.534691197Z -- Generating done (11.9s)
```

https://lab.llvm.org/staging/#/builders/192
2026-01-26 16:17:57 +00:00
Joseph Huber
c5cb48c397
[libclc] Rework libclc naming convention to use the triple (#177465)
Summary:
Right now all these libraries are installed in the `libclc/` directory
in the compiler's resource directory. We should instead follow the
per-target approach and install it according to the triple. The
sub-architectures will be put in a subdirectory as well.

I will do refactorings on this later to remove all the redundant targets
and pull this into common handling.

Also we should accept `--libclc-lib` without an argument to just find it
by default. I don't know what the plan here is since AMDGCN is the only
triple that uses this flag.
2026-01-26 07:43:26 -06:00
Konrad Kleine
d09fac4536
[libclc] compile w/o linking builtins with SPIRV backend (#176732)
As we're only building a single file, there is no need to link. This
avoids a dependency on spriv-link when we're using the native SPIRV
backend.
2026-01-20 08:14:49 +01:00
Wenju He
a3ca7caa74
[libclc][NFC] Remove unused builtins_opt_lib_tgt (#175479)
It was left behind after f07988ff3ec8.
2026-01-12 11:56:56 +08:00
Wenju He
ee8a4bc9d7
[libclc] Remove llvm-link --override flag and make implementation self-contained (#175134)
Revert --override flag added in 28d9255aa7c0 and avoid defining the same
symbol across multiple files of a target, simplifying the build and
easing the transition to CMake add_library for libclc.

amdgcn ldexp now uses __builtin_elementwise_ldexp.

No functional changes to clc_sqrt or clc_rsqrt.
2026-01-12 10:00:10 +08:00
Joseph Huber
f07988ff3e
[libclc] Remove bitcode prepare utility from OpenCL library build (#174447)
Summary:
This utility is unnecessary with the current usage. Right now it sets
linkage to linkonce_odr and deduplicates metadata nodes. The former is
not required as `-mlink-builtin-bitcode` will internalize all functions
anyway. The deduplication is no longer necessary as `llvm-link` handles
that. Removing this simplifies complexity and make it easier to
cross-build this utility as it no longer depends on host LLVM utilities
to be built in the proejct itself.
2026-01-05 21:58:17 -06:00
Joseph Huber
bbbccf063a
[libclc] Update default triple support for AMD and deprecate 32-bit PTX (#174415)
Summary:
The standard `nvptx` target is not supported and has been completely
removed following the CUDA 12 release. It should be safe to drop support
for it in the default build. Additionally we add the `amd` vendor to the
amdgcn triple as this is the more canonical form and builds the same IR.
2026-01-05 21:57:51 -06:00
Wenju He
776f5933c9
[libclc][NFC] Move convert builtins from Python generator to .cl sources (#172634)
Remove the Python dependency for generating convert builtins, aligning
with how other builtins are defined.
In addition, our downstream target relies on this PR to override convert
implementations.
llvm-diff shows no changes to all bitcodes:
amdgcn--amdhsa.bc, barts-r600--.bc, cayman-r600--.bc, cedar-r600--.bc,
clspv64--.bc, clspv--.bc, cypress-r600--.bc, nvptx64--.bc,
nvptx64--nvidiacl.bc, nvptx--.bc, nvptx--nvidiacl.bc, tahiti-amdgcn--.bc
and tahiti-amdgcn-mesa-mesa3d.bc.
2025-12-19 08:19:58 +08:00
Wenju He
79620d8ac0
[libclc] Add OpenCL atomic_*_explicit builtins (#168318)
Implement atomic_*_explicit (e.g. atomic_store_explicit) with
memory_order plus optional memory_scope.

OpenCL memory_order maps 1:1 to Clang (e.g. OpenCL memory_order_relaxed
== Clang __ATOMIC_RELAXED), so we pass it unchanged to clc_atomic_*
function which forwards to Clang _scoped_atomic* builtins.

Other changes:
* Add __opencl_get_clang_memory_scope helper in opencl/utils.h (OpenCL
scope -> Clang scope).
* Correct atomic_compare_exchange return type to bool.
* Fix atomic_compare_exchange to return true when value stored in the
pointer equals expected value.
* Remove volatile from CLC functions so that volatile isn't present in
LLVM IR.
* Add '-fdeclare-opencl-builtins -finclude-default-header' flag to
include
declaration of memory_scope. Some constants in libclc are already
provided
  by Clang’s OpenCL header; disable those in OpenCL library build and
  enable them only for CLC library build.
2025-12-05 10:12:25 +08:00
Wenju He
d6b68545aa
[NFC][libclc] Improve empty builtins error: include ARCH_SUFFIX in message (#164527)
To clarify which builtin set has no bytecode files.
2025-10-22 12:47:44 +08:00
Wenju He
b9e2f7ac04
[libclc] Change libclc install dir to ${clang_resource_dir}/lib/libclc in in-tree build (#163896)
Commit df7473673214b placed libclc libraries into clang resource dir
<resource-dir>/lib/libclc at build stage.
This PR does it at install stage as well.
Note that in standalone (not in-tree) build, libclc is still installed
to old ${CMAKE_INSTALL_DATADIR}/clc dir.
2025-10-20 09:47:00 +08:00
Wenju He
64574d3564
[libclc] Remove -fno-builtin from compile options (#162075)
The flag was added in 8ef48d07efa3 to suppress build warning and is no
longer needed.

It adds "no-builtins" attribute, which prevents libclc functions from
being inlined into caller that don't have the attribute.

The flag is meant to prevent folding standard library calls into
optimized implementations. For libclc device targets, however, such
target‑driven folding is desirable.

llvm-diff shows no change to amdgcn--amdhsa.bc and nvptx--nvidiacl.bc.

Co-authored-by: Mészáros Gergely <gergely.meszaros@intel.com>
2025-10-07 08:14:54 +08:00
Wenju He
7d1adab5a6
[libclc] Fix ctest failures after 7f3661128b1e: adjust external check and make shuffle helpers static (#160036)
* Replace call-site check with external declaration scan (grep declare)
to avoid false positives for not-inlined __clc_* functions.
* _clc_get_el* helpers are defined as inline in clc_shuffle2.cl, so they
have available_externally attribute. When they fail to inline they are
deleted by EliminateAvailableExternallyPass and become unresolved in
cedar-r600--.bc. Mark them static to resolve the issue.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-22 15:55:49 +08:00
Wenju He
28d9255aa7
[libclc] Override generic symbol using llvm-link --override flag instead of using weak linkage (#156778)
Before this PR, weak linkage is applied to a few CLC generic functions
to allow target specific implementation to override generic one.
However, adding weak linkage has a side effect of preventing
inter-procedural optimization, such as PostOrderFunctionAttrsPass,
because weak function doesn't have exact definition (as determined by
hasExactDefinition in the pass).

This PR resolves the issue by adding --override flag for every
non-generic bitcode file in llvm-link run. This approach eliminates the
need for weak linkage while still allowing target-specific
implementation to override generic one.
llvm-diff shows imporoved attribute deduction for some functions in
amdgcn--amdhsa.bc, e.g.
  %23 = tail call half @llvm.sqrt.f16(half %22)
=>
  %23 = tail call noundef half @llvm.sqrt.f16(half %22)
2025-09-05 19:58:07 +08:00
Wenju He
e6d095e89c
[libclc] Only create a target per each compile command for cmake MSVC generator (#154479)
libclc sequential build issue addressed in commit 0c21d6b4c8ad is
specific to cmake MSVC generator. Therefore, this PR avoids creating a
large number of targets when a non-MSVC generator is used, such as the
Ninja generator, which is used in pre-merge CI on Windows in
llvm-project repo. We plan to migrate from MSVC generator to Ninja
generator in our downstream CI to fix flaky cmake bug `Cannot restore
timestamp`, which might be related to the large number of targets.
2025-08-22 07:45:42 +08:00
Wenju He
68c609b6c8
[libclc] Fix libclc install on Windows when MSVC generator is used (#152703)
Fix a regression of df7473673214.

cmake MSVC generator is multiple configurations. Build type is not known
at configure time and CMAKE_CFG_INTDIR is evaluated to $(Configuration)
at configure time. libclc install fails since $(Configuration) in
bitcode file path is unresolved in libclc/cmake_install.cmake at install time.

We need a solution that resolves libclc bitcode file path at install
time. This PR fixes the issue using CMAKE_INSTALL_CONFIG_NAME which can
be evaluated at install time. This is the same solution as in
https://reviews.llvm.org/D76827
2025-08-11 18:05:42 +08:00
Wenju He
3d1c1a5277
[libclc] Set TARGET_FILE property for prepare-${obj_suffix} target (#152245)
The target's output bitcode `libclc_builtins_lib` is located in a
sub-directory in clang resource directory since df7473673214. Setting
TARGET_FILE property can allow targets in non-libclc project to obtain
the path to `libclc_builtins_lib`.
2025-08-07 08:28:43 +08:00
Fraser Cormack
b0313adefa
[libclc] Add an option to build SPIR-V targets with the LLVM backend (#151347)
This removes the dependency on an external tool to build the SPIR-V
files. It may be of interest to projects such as Mesa.

Note that the option is off by default as using the SPIR-V backend, at
least on my machine, uses a *lot* of memory and the process is often
killed in a parallelized build. It does complete, however.

Fixes #135327.
2025-08-01 09:48:40 +01:00
Fraser Cormack
76bebb5be9
[libclc] Fix building top-level 'libclc' target (#150972)
With libclc being a 'runtime', the top-level build assumes that there is
a corresopnding 'libclc' target. We previously weren't providing this,
leading to a build failure if the user tried to build it.

This commit remedies this by adding support for building the 'libclc'
target. It does so by adding dependencies from the OpenCL builtins to
this target. It uses a configurable in-between target -
libclc-opencl-builtins - to ease the possibility of adding non-OpenCL
builtin libraries in the future.
2025-07-29 10:53:31 +01:00
Michał Górny
abe93d9d7e
[libclc] Fix installed symlinks to be relative again (#149728)
Fix the symlink creation logic to use relative paths instead of
absolute, in order to ensure that the installed symlinks actually refer
to the installed .bc files rather than the ones from the build
directory. This was broken in #146833. The change is a bit roundabout
but it attempts to preserve the spirit of #146833, that is the ability
to use multiple output directories (provided they all resides in
`${LIBCLC_OUTPUT_LIBRARY_DIR}` and preserve the same structure in the
installed tree).

Signed-off-by: Michał Górny <mgorny@gentoo.org>
2025-07-21 20:59:31 +02:00
Fraser Cormack
9b5959dd9a
[libclc] Change symlinks to copies on Windows (#147759)
This mirrors how other LLVM libraries handle symlinks
2025-07-09 17:20:56 +01:00
Fraser Cormack
222e795347 [libclc] Fix target dependency
The prepare target was depending on the output of a custom command, but
wasn't the full path to that file. This tripped up CMake if the file was
removed as it didn't know how to rebuild that file.
2025-07-04 11:08:00 +01:00
Fraser Cormack
81e6552a3d
[libclc] Make library output directories explicit (#146833)
These changes were split off from #146503.

This commit makes the output directories of libclc artefacts explicit.
It creates a variable for the final output directory -
LIBCLC_OUTPUT_LIBRARY_DIR - which has not changed. This allows future
changes to alter the output directory more simply, such as by pointing
it to somewhere inside clang's resource directory.

This commit also changes the output directory of each target's
intermediate builtins.*.bc files. They are now placed into each
respective libclc target's object directory, rather than the top-level
libclc binary directory. This should help keep the binary directory a
bit tidier.
2025-07-04 10:35:15 +01:00
Fraser Cormack
85d09de5fa
[libclc] Add prepare-<triple> targets (#146700)
This target provides a unified build target for all devices under the
single triple. This way a user doesn't have to know device names to
build a specific target's bytecode libraries.

Device names may be considered as internal implementation details as
they are not exposed to users of CMake; users only specify triples to
build. Now, instead of `prepare-{barts,cayman,cedar,cypress}-r600--.bc`,
for example, a user may now build simply `prepare-r600--` and have all
four of those libraries built.

This commit also refactors the CMake somewhat. We were previously
diverging between the SPIR-V and other targets, and duplicating a bit of
logic like the creation of the 'prepare' targets, the targets'
properties, and the installation directory. It's cleaner and hopefully
more robust to share this code between all targets. This commit also
takes this opportunity to improve some comments around this code.
2025-07-03 08:30:33 +01:00
Fraser Cormack
32cf55aef3
[libclc] Reorganize OpenCL builtins (#140557)
This commits moves all OpenCL builtins under a top-level 'opencl'
directory, akin to how the CLC builtins are organized. This new
structure aims to better convey the separation of the two layers and
that 'CLC' is not a subset of OpenCL or a libclc target.

In doing so this commit moves the location of the 'lib' directory to
match CLC: libclc/generic/lib/ becomes libclc/opencl/lib/generic/. This
allows us to remove some special casing in CMake and ensure a common
directory structure.

It also tries to better communicate that the OpenCL headers are
libclc-specific OpenCL headers and should not be confused with or used
as standard OpenCL headers. It does so by ensuring includes are of the
form <clc/opencl/*>. It might be that we don't specifically need the
libclc OpenCL headers and we simply could use clang's built-in
declarations, but we can revisit that later.

Aside from the code move, there is some code formatting and updating a
couple of OpenCL builtin includes to use the readily available gentype
helpers. This allows us to remove some '.inc' files.
2025-05-20 09:51:30 +01:00
Wenju He
d779b8f92b
[libclc] Append file_specific_compile_options after ARG_COMPILE_FLAGS (#139871)
This enables file_specific_compile_options to take precedence over
ARG_COMPILE_FLAGS. For example, if we add -fno-slp-vectorize to
COMPILE_OPTIONS of a file, the behavior changes as follows:
* Before this PR: -fno-slp-vectorize is overwritten by -O3, resulting in
SLP vectorizer remaining enabled.
* After this PR: -fno-slp-vectorize overwrites -O3, effectively
disabling SLP vectorizer.
2025-05-16 10:21:45 +01:00
Wenju He
77fe6aaeaa
[libclc] only check filename part of the source for avoiding duplication (#135710)
llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders. For
example, in target SOURCES we have math-common/cos.cl, while in generic
SOURCES it is math/cos.cl. Based on current check rule that compares
both folder name and base filename, target math-common/cos.cl won't
override math/cos.cl when collecting source files from SOURCES files in
cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
2025-04-24 05:35:16 +01:00
Fraser Cormack
4cb1803ff9 [libclc][NFC] Fix typo in comment 2025-04-14 14:38:58 +01:00
Wenju He
0c21d6b4c8
[libclc] Fix commands in compile_to_bc are executed sequentially (#130755)
In libclc, we observe that compiling OpenCL source files to bitcode is
executed sequentially on Windows, which increases debug build time by
about an hour.
add_custom_command may introduce additional implicit dependencies, see
https://gitlab.kitware.com/cmake/cmake/-/issues/17097
This PR adds a target for each command, enabling parallel builds of
OpenCL source files.
CMake 3.27 has fixed above issue with DEPENDS_EXPLICIT_ONLY. When LLVM
upgrades cmake vertion to 3.7, we can switch to DEPENDS_EXPLICIT_ONLY.
2025-04-14 14:11:04 +01:00
Fraser Cormack
0a74cbfac4
[libclc] Pass -fapprox-func when compiling 'native' builtins (#133119)
The libclc build system isn't well set up to pass arbitrary options to
arbitrary source files in a non-intrusive way. There isn't currently any
other motivating example to warrant rewriting the build system just to
satisfy this requirement. So this commit uses a filename-based approach
to inserting this option into the list of compile flags.
2025-03-28 08:22:19 +00:00
Wenju He
735d7c1539
[libclc] link_bc target should depends on target builtins.link.clc-arch_suffix (#132338)
Currently link_bc command depends on the bitcode file that is associated
with custom target builtins.link.clc-arch_suffix.
On windows we randomly see following error:
`
  Generating builtins.link.clc-${ARCH}--.bc
  Generating builtins.link.libspirv-${ARCH}.bc
error : The requested operation cannot be performed on a file with a
user-mapped section open.
`
I suspect that builtins.link.clc-${ARCH}--.bc file is being generated
while it is being used in link_bc.
This PR adds target-level dependency to ensure
builtins.link.clc-${ARCH}--.bc is generated first.
2025-03-24 10:09:19 +00:00
Wenju He
cb1e91c18d
[libclc] add --only-needed to llvm-link when INTERNALIZE flag is set (#130871)
When -internalize flag is passed to llvm-link, we only need to link in
needed symbols. This PR reduces size of linked bitcode, e.g. by removing
following symbols:

    _Z12__clc_sw_fmaDv16_fS_S_
    _Z12__clc_sw_fmaDv2_fS_S_
    _Z12__clc_sw_fmaDv3_fS_S_
    _Z12__clc_sw_fmaDv4_fS_S_
    _Z12__clc_sw_fmaDv8_fS_S_
    _Z12__clc_sw_fmafff
2025-03-20 13:25:55 +00:00
Fraser Cormack
73d067977b
[libclc] Clean up directory search procedure (#127783)
During a recent change, the build system accidentally dropped the
(theoretical) support for the CLC builtins library to build
target-specific builtins from the 'amdgpu' directory, due to a change in
variable names. This functionality wasn't being used but was spotted
during another code review.

This commit takes the opportunity to clean up and better document the
code that manages the list of directories to search for builtin
implementations.

While fixing this, some references to now-removed SOURCES files were
discovered which have been cleaned up.
2025-02-19 12:21:18 +00:00