[libclc] libclc: increase fp16 support (PR #98149)

2024-07-10 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> @frasercrmck Could you review it please?

Sure, will do, thanks for this. We've done something similar downstream so I 
can hopefully verify against what we've done.

https://github.com/llvm/llvm-project/pull/98149
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)

2024-06-24 Thread Fraser Cormack via cfe-commits


@@ -394,6 +401,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 DEPENDS ${builtins_link_lib}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
+  set_target_properties( "prepare-${spv_suffix}" PROPERTIES FOLDER 
"libclc/Sourcegenning" )

frasercrmck wrote:

I wonder whether it is confusing to have the SPIR-V `prepare-xxx` target 
labelled `libclc/Sourcegenning` but the non-SPIR-V `prepare-xxx` target labeled 
`libclc/Device IR/Prepare`. Both being called `prepare` makes me think they 
should be grouped similarly.

Note that I don't currently have any way of testing out this patch as I haven't 
got VS Code or XCode available to me right now. It might be that the dichotomy 
as currently in this patch makes sense.

https://github.com/llvm/llvm-project/pull/89746
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)

2024-06-24 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/95018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)

2024-06-12 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> Yes, the article you link to is highly relevant. Without this PR we're 
> hitting the problem described in example #4.
> 
> We can promote the issue to a build failure by choosing a custom command 
> which can't run concurrently with itself:
> 
> ```cmake
> cmake_minimum_required(VERSION 3.2)
> 
> add_custom_command(
> OUTPUT gen
> # Try to grab a lock and fail immediately if we can't:
> COMMAND flock -x -n gen.lock sleep 1
> COMMAND cmake -E echo Hello > gen
> )
> 
> add_custom_target(
> my-all-1 ALL DEPENDS gen
> )
> 
> add_custom_target(
> my-all-2 ALL DEPENDS gen
> )
> ```
> 
> With the above `make` will succeed, but `make -j2` will fail. The issue is 
> not exposed with Ninja. This is the same behavior I see in libclc today, 
> except more jobs are needed. Adding an intermediate target and depending on 
> both the new target and the file does seem to fix all of our problems.
> 
> I've added the file dependencies back in 
> [b707fc7](https://github.com/llvm/llvm-project/commit/b707fc7dea2e5e57bc3e4f01e27b9ca7bbf0e398),
>  and I think it fixes the build issue while preserving the incremental build 
> behavior you described. Could you please give it a try?

Brilliant, thanks. I have played around and see that incremental builds appear 
to work as intended. I've tried deleting and `touch`ing various files and full 
rebuilds and partial rebuilds do what I'd expect.

Thanks also for pointing out I've already read about this exact issue (example 
#4) and missed it! It's a real shame there isn't a better framework for testing 
CMake and build generators themselves.

https://github.com/llvm/llvm-project/pull/95018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)

2024-06-12 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck approved this pull request.

LGTM, thank you!

https://github.com/llvm/llvm-project/pull/95018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)

2024-06-11 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

Hmm, isn't CMake fun? Thanks for looking into this.

Unfortunately the file-level dependencies are there for a reason. With this 
patch, if I `rm builtins.link.nvptx64--.bc` and build `builtins.opt.nvptx64--` 
(with `ninja`), it builds the `link` target but doesn't actually rebuild the 
`opt` target. On `main`, it does do this. We need to preserve that behaviour, 
or developers will see stale builds and that will lead to all sorts of problems.

I found [example #5 of this 
example](https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands)
 interesting when I was initially implementing this. CMake's dependencies are 
really strange.

Going by the documentation you link, could we have _both_ the file- and the 
target-level dependency? Note how the 
[example](https://cmake.org/cmake/help/v3.29/command/add_custom_command.html#example-generating-files-for-multiple-targets)
 has `DEPENDS table.csv generate_table_csv` in *both* parallel targets, so the 
file-level dependency `foo.csv` *is* being used twice - but also supplying the 
target-level dependency prevents it from being a race condition?

https://github.com/llvm/llvm-project/pull/95018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-25 Thread Fraser Cormack via cfe-commits


@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s

frasercrmck wrote:

That's true, but I'm still sceptical that we can make the tests simple enough 
for `update_cc_test_checks` to be viable. We'd have to embed libclc further 
into the clang driver for it to work, given that it currently doesn't know 
where to find libclc libraries for each target, and we can't express the path 
to libclc libraries in LIT in such a way that `update_cc_test_checks` would 
handle it. I'm not convinced clang _should_ necessarily know about libclc. I 
don't think we should be tying libclc to any specific compilation model like 
OpenCL C.

https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-24 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Fraser Cormack via cfe-commits


@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)

frasercrmck wrote:

Interesting, thank you for pointing that out.

I just tried something inspired by that (looking at 
https://github.com/ROCm/ROCm-Device-Libs/blob/amd-stg-open/cmake/OCL.cmake#L129)
 but when I deleted the configured `.rsp` file it wouldn't know how to rebuild 
it. It did reconfigure and rebuild when I deleted the `.rsp.in` file. It might 
be I've done something wrong, but though I like your suggestion I might stick 
with this one as I've verified it can handle being deleted.

https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/89756

We've recently seen the libclc llvm-link invocations become so long that they 
exceed the character limits on certain platforms.

Using a 'response file' should solve this by offloading the list of inputs into 
a separate file, and using special syntax to pass it to llvm-link. Note that 
neither the response file nor syntax aren't specific to Windows but we restrict 
it to that platform regardless. We have the option of expanding it to other 
platforms in the future.

>From 640b18bdf3ccd706a509b534d1b8a01b499eddd7 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 23 Apr 2024 13:50:54 +0100
Subject: [PATCH] [libclc] Use a response file when building on Windows

We've recently seen the libclc llvm-link invocations become so long that
they exceed the character limits on certain platforms.

Using a 'response file' should solve this by offloading the list of
inputs into a separate file, and using special syntax to pass it to
llvm-link. Note that neither the response file nor syntax aren't
specific to Windows but we restrict it to that platform regardless. We
have the option of expanding it to other platforms in the future.
---
 libclc/cmake/modules/AddLibclc.cmake | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index bbedc244a72899..7f4620fa6a21df 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)
+set( LINK_INPUT_ARG "@${RSP_FILE}" )
+  endif()
+
   add_custom_command(
 OUTPUT ${ARG_TARGET}.bc
-COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${ARG_INPUTS}
-DEPENDS libclc::llvm-link ${ARG_INPUTS}
+COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
+DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE}
   )
 
   add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)

2024-04-22 Thread Fraser Cormack via cfe-commits


@@ -39,6 +39,10 @@ function(compile_to_bc)
 set( TARGET_ARG "-target" ${ARG_TRIPLE} )
   endif()
 
+  # Ensure the directory we are told to output to exists
+  get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY )

frasercrmck wrote:

Yeah, there very well may be. I couldn't find anything obvious, but I'm sure 
I'll keep iterating on the build system over time so I'll keep an eye out.

https://github.com/llvm/llvm-project/pull/89147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)

2024-04-22 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/89147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)

2024-04-18 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/89147

>From 0f102a202e4a80fbc106303df5005a2b7922b0cf Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 17 Apr 2024 22:28:03 +0100
Subject: [PATCH] [libclc] Fix build with Unix Makefiles

Commit #87622 broke the build. Ninja was happy with creating the output
directories as necessary, but Unix Makefiles isn't. Ensure they are
always created.

Fixes #88626.
---
 libclc/cmake/modules/AddLibclc.cmake | 4 
 1 file changed, 4 insertions(+)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index 5e09cde8035c27..bbedc244a72899 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -39,6 +39,10 @@ function(compile_to_bc)
 set( TARGET_ARG "-target" ${ARG_TRIPLE} )
   endif()
 
+  # Ensure the directory we are told to output to exists
+  get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY )
+  file( MAKE_DIRECTORY ${ARG_OUTPUT_DIR} )
+
   add_custom_command(
 OUTPUT ${ARG_OUTPUT}${TMP_SUFFIX}
 COMMAND libclc::clang

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] dc74c69 - [libclc] Provide a more helpful error when tools are missing

2024-04-18 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-18T07:01:13+01:00
New Revision: dc74c69f016fa65949bf0cf691061e12bef93d29

URL: 
https://github.com/llvm/llvm-project/commit/dc74c69f016fa65949bf0cf691061e12bef93d29
DIFF: 
https://github.com/llvm/llvm-project/commit/dc74c69f016fa65949bf0cf691061e12bef93d29.diff

LOG: [libclc] Provide a more helpful error when tools are missing

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index b0c29ed77270cf..5ce17952430854 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -94,10 +94,11 @@ if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
   endforeach()
 endif()
 
-if( NOT TARGET libclc::clang OR NOT TARGET libclc::opt
-OR NOT TARGET libclc::llvm-as OR NOT TARGET libclc::llvm-link )
-  message( FATAL_ERROR "libclc toolchain incomplete!" )
-endif()
+foreach( tool IN ITEMS clang opt llvm-as llvm-link )
+  if( NOT TARGET libclc::${tool} )
+message( FATAL_ERROR "libclc toolchain incomplete - missing tool ${tool}!" 
)
+  endif()
+endforeach()
 
 # llvm-spirv is an optional dependency, used to build spirv-* targets.
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 0aeeff3 - [libclc] Allow building with pre-built tools

2024-04-18 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-18T07:01:13+01:00
New Revision: 0aeeff3059e79b86f55ed92a4488bdee8fa66e12

URL: 
https://github.com/llvm/llvm-project/commit/0aeeff3059e79b86f55ed92a4488bdee8fa66e12
DIFF: 
https://github.com/llvm/llvm-project/commit/0aeeff3059e79b86f55ed92a4488bdee8fa66e12.diff

LOG: [libclc] Allow building with pre-built tools

Building the libclc project in-tree with debug tools can be very slow.
This commit adds an option for a user to specify a dierctory from which
to import (e.g., release-built) tools. All tools required by the project
must be imported from the same location, for simplicity.

Original patch downstream authored by @jchlanda.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 4442ff6daa61b8..b0c29ed77270cf 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -50,11 +50,13 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DI
   endif()
 
   # Import required tools as targets
-  foreach( tool IN ITEMS clang llvm-as llvm-link opt )
-find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-add_executable( libclc::${tool} IMPORTED GLOBAL )
-set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
-  endforeach()
+  if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
+foreach( tool IN ITEMS clang llvm-as llvm-link opt )
+  find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  add_executable( libclc::${tool} IMPORTED GLOBAL )
+  set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
+endforeach()
+  endif()
 else()
   # In-tree configuration
   set( LIBCLC_STANDALONE_BUILD FALSE )
@@ -68,8 +70,27 @@ else()
 message(FATAL_ERROR "Clang is not enabled, but is required to build libclc 
in-tree")
   endif()
 
+  if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
+foreach( tool IN ITEMS clang llvm-as llvm-link opt )
+  add_executable(libclc::${tool} ALIAS ${tool})
+endforeach()
+  endif()
+endif()
+
+if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
+  message( WARNING "Using custom LLVM tools to build libclc: "
+"${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "
+" ensure the tools are up to date." )
+  # Note - use a 
diff erently named variable than LLVM_TOOL_${tool} as above, as
+  # the variable name is used to cache the result of find_program. If we used
+  # the same name, a user wouldn't be able to switch a build between default
+  # and custom tools.
   foreach( tool IN ITEMS clang llvm-as llvm-link opt )
-add_executable(libclc::${tool} ALIAS ${tool})
+find_program( LLVM_CUSTOM_TOOL_${tool} ${tool}
+  PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+add_executable( libclc::${tool} IMPORTED GLOBAL )
+set_target_properties( libclc::${tool} PROPERTIES
+  IMPORTED_LOCATION ${LLVM_CUSTOM_TOOL_${tool}} )
   endforeach()
 endif()
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 93d5119 - [libclc] Clarify option help message

2024-04-18 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-18T07:01:13+01:00
New Revision: 93d51194b1df8229268953ec94063fc4194a320b

URL: 
https://github.com/llvm/llvm-project/commit/93d51194b1df8229268953ec94063fc4194a320b
DIFF: 
https://github.com/llvm/llvm-project/commit/93d51194b1df8229268953ec94063fc4194a320b.diff

LOG: [libclc] Clarify option help message

This should make it more obvious it applies only to libclc.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c77da2d4f18e74..4442ff6daa61b8 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -32,7 +32,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
 set( LIBCLC_MIN_LLVM 3.9.0 )
 
 set( LIBCLC_TARGETS_TO_BUILD "all"
-CACHE STRING "Semicolon-separated list of targets to build, or 'all'." )
+CACHE STRING "Semicolon-separated list of libclc targets to build, or 
'all'." )
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 06f54e7 - [libclc] Convert llvm-spirv to imported executable

2024-04-18 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-18T07:01:13+01:00
New Revision: 06f54e7c2b4f26fbcad906a6b4aa2e46bf60b8af

URL: 
https://github.com/llvm/llvm-project/commit/06f54e7c2b4f26fbcad906a6b4aa2e46bf60b8af
DIFF: 
https://github.com/llvm/llvm-project/commit/06f54e7c2b4f26fbcad906a6b4aa2e46bf60b8af.diff

LOG: [libclc] Convert llvm-spirv to imported executable

This tool now behaves like the others, for consistency.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index f605c3bbbe9dce..c77da2d4f18e74 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -81,6 +81,11 @@ endif()
 # llvm-spirv is an optional dependency, used to build spirv-* targets.
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 
+if( LLVM_SPIRV )
+  add_executable( libclc::llvm-spirv IMPORTED GLOBAL )
+  set_target_properties( libclc::llvm-spirv PROPERTIES IMPORTED_LOCATION 
${LLVM_SPIRV} )
+endif()
+
 # List of all targets. Note that some are added dynamically below.
 set( LIBCLC_TARGETS_ALL
   amdgcn--
@@ -101,7 +106,7 @@ endif()
 
 # spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
 # llvm-spirv external tool.
-if( LLVM_SPIRV )
+if( TARGET libclc::llvm-spirv )
   list( APPEND LIBCLC_TARGETS_ALL  spirv-mesa3d- spirv64-mesa3d- )
 endif()
 
@@ -114,7 +119,7 @@ list( SORT LIBCLC_TARGETS_TO_BUILD )
 # Verify that the user hasn't requested mesa3d targets without an available
 # llvm-spirv tool.
 if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" 
IN_LIST LIBCLC_TARGETS_TO_BUILD )
-  if( NOT LLVM_SPIRV )
+  if( NOT TARGET libclc::llvm-spirv )
 message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not 
installed" )
   endif()
 endif()
@@ -363,7 +368,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT ${spv_suffix}
-COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
+COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} 
${builtins_link_lib}
 DEPENDS ${builtins_link_lib}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix build with Unix Makefiles (PR #89147)

2024-04-17 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/89147

Commit #87622 broke the build. Ninja was happy with creating the output 
directories as necessary, but Unix Makefiles isn't. Ensure they are always 
created.

Fixes #88626.

>From 7bd2001064a45c87ab9094a041a95a50e0234872 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 17 Apr 2024 22:28:03 +0100
Subject: [PATCH] [libclc] Fix build with Unix Makefiles

Commit #87622 broke the build. Ninja was happy with creating the output
directories as necessary, but Unix Makefiles isn't. Ensure they are
always created.

Fixes #88626.
---
 libclc/cmake/modules/AddLibclc.cmake | 4 
 1 file changed, 4 insertions(+)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index 5e09cde8035c27..bbedc244a72899 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -39,6 +39,10 @@ function(compile_to_bc)
 set( TARGET_ARG "-target" ${ARG_TRIPLE} )
   endif()
 
+  # Ensure the directory we are told to output to exists
+  get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY )
+  file( MAKE_DIRECTORY ${ARG_OUTPUT_DIR} )
+
   add_custom_command(
 OUTPUT ${ARG_OUTPUT}${TMP_SUFFIX}
 COMMAND libclc::clang

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-17 Thread Fraser Cormack via cfe-commits


@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s

frasercrmck wrote:

Fair enough, I hadn't really appreciated that `update_cc_test_checks` was 
orthogonal to all of these other LIT concepts like `REQUIRES` and features more 
broadly, but that's due to my misunderstanding of how that script worked.

Those clang codegen tests that do have `REQUIRES` are relegated to their own 
target-specific source files. What we want for libclc I think is ideally to be 
testing every libclc builtin with every target. I was hoping we could use a 
single set of test files to avoid duplication, but that doesn't seem possible.

So each libclc target would have their own copy of each test source file: 
`test/amdgcn/smoothstep.cl`, `test/nvidia/smoothstep.cl`, etc? That's not so 
bad as long as it's easy enough to bring up a new libclc target (maybe with a 
generator script, though maybe just copy/pasting a directory of tests, removing 
the old checks, and running `update_cc_test_checks` is sufficient)? I suppose 
the `amdgpu` tests would be amalgamated and would `RUN` over each sub-target 
(`r600`, `amdgcn-mesa3d`, etc., as appropriate). Similar for NVIDIA and other 
groups.

I understand the idea of having libclc targets linked to the backend targets. 
Some, like `clspv`/`clspv64` and `spirv`/`spirv64`, aren't intrinsically tied 
to any specific backend. `clspv` targets seem to use the "generic" spir/spir64 
triples so could probably be unconditionally enabled, and `spirv` targets are 
compiled to those same spir/spir64 triples before being compiled to SPIR-V, 
which we can't test here. My concern is that this might be a breaking change to 
some downstream users (we don't really know what they're doing with libclc). 
Either way I'm not sure this needs to concern this initial round of tests - we 
can probably stomach the complexity.

https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-17 Thread Fraser Cormack via cfe-commits


@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s

frasercrmck wrote:

I wasn't so much thinking that it would pretend to be generic, but rather that 
it'd use a custom test format (something like 
[analyzer_test.py](https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/analyzer_test.py))
 to run the test once for each target we build/test, substituting in the target 
triple and target-specific check prefix each time.

That way we could test all or a subset of all targets without worrying about 
the test failing on a target we haven't built.

In that sense these are a little different to clang codegen tests - aren't 
they? clang can always compile for any of its supported targets. With libclc, 
however, the user is allowed to build only a handful of the targets, and each 
of those targets can have drastically different builtin implementations through 
specialization.

We don't want the tests to fail if the user hasn't built certain targets, so I 
think we need some kind of configuration that allows tests to be skipped. But 
`update_cc_test_checks` doesn't handle features or `%if` or anything dynamic 
like that. It's really only suitable for the simplest of clang tests. So if we 
wanted to have each test file run on multiple targets, I think 
`update_cc_test_checks` could only be used if the user built all libclc 
targets, and each test had one `RUN` line for each target. I think we have ten 
targets so it might get a bit unwieldy, is all I'm saying. I do want us to be 
able to use that script as it's by far the best way of maintaining tests that 
we've got.

https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-17 Thread Fraser Cormack via cfe-commits


@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s

frasercrmck wrote:

Ach I misunderstood how `update_cc_test_checks` works. It doesn't actually go 
through the regular LIT infrastructure, so we can't do anything involving 
custom substitutions to configure which target is being run.

If we wanted to be able to use `update_cc_test_checks` I think we'd need to 
have every target explicit in every test file, which brings its own 
inflexibilities and maintenance problems.

https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-17 Thread Fraser Cormack via cfe-commits


@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s

frasercrmck wrote:

Yes, I was hoping to explore in that direction. I've kind of just copied the 
skeleton of the LIT tests we have downstream, but as you say, this isn't really 
workable as it assumes all tests will be able to use the same CHECK.

I think, for this to work, we'd have to configure LIT with all of the `libclc` 
targets (or, a subset we're interested in), then `RUN` each test multiple times 
with a unique `FileCheck` check prefix for each target. Then when running 
`update_cc_test_checks` it'd run the test on all targets.

I think we'd need a macro or substitution to expand a single `RUN` line to 
multiple architectures, to keep things maintainable.

We could also allow running the tests on just the one or a subset of 
architectures locally, using a `--param` to control the architectures to test.

Does that sound like a good direction? to take this in?

https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Allow building with pre-built tools (PR #88922)

2024-04-17 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/88922

>From bff3b97b599e1c9529a95ead9d61f9ecc9cad129 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 15:30:20 +0100
Subject: [PATCH 1/5] [libclc] Convert llvm-spirv to imported executable

This tool now behaves like the others, for consistency.
---
 libclc/CMakeLists.txt | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index f605c3bbbe9dce..c77da2d4f18e74 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -81,6 +81,11 @@ endif()
 # llvm-spirv is an optional dependency, used to build spirv-* targets.
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 
+if( LLVM_SPIRV )
+  add_executable( libclc::llvm-spirv IMPORTED GLOBAL )
+  set_target_properties( libclc::llvm-spirv PROPERTIES IMPORTED_LOCATION 
${LLVM_SPIRV} )
+endif()
+
 # List of all targets. Note that some are added dynamically below.
 set( LIBCLC_TARGETS_ALL
   amdgcn--
@@ -101,7 +106,7 @@ endif()
 
 # spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
 # llvm-spirv external tool.
-if( LLVM_SPIRV )
+if( TARGET libclc::llvm-spirv )
   list( APPEND LIBCLC_TARGETS_ALL  spirv-mesa3d- spirv64-mesa3d- )
 endif()
 
@@ -114,7 +119,7 @@ list( SORT LIBCLC_TARGETS_TO_BUILD )
 # Verify that the user hasn't requested mesa3d targets without an available
 # llvm-spirv tool.
 if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" 
IN_LIST LIBCLC_TARGETS_TO_BUILD )
-  if( NOT LLVM_SPIRV )
+  if( NOT TARGET libclc::llvm-spirv )
 message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not 
installed" )
   endif()
 endif()
@@ -363,7 +368,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT ${spv_suffix}
-COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
+COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} 
${builtins_link_lib}
 DEPENDS ${builtins_link_lib}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )

>From 98a9c4621c7814848c5b4fe18e41bd7c671b84ee Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 16:55:53 +0100
Subject: [PATCH 2/5] [libclc] Clarify option help message

This should make it more obvious it applies only to libclc.
---
 libclc/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c77da2d4f18e74..4442ff6daa61b8 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -32,7 +32,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
 set( LIBCLC_MIN_LLVM 3.9.0 )
 
 set( LIBCLC_TARGETS_TO_BUILD "all"
-CACHE STRING "Semicolon-separated list of targets to build, or 'all'." )
+CACHE STRING "Semicolon-separated list of libclc targets to build, or 
'all'." )
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 

>From 4257979d8ee548672b8507bd00486fae98481e3b Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 16:46:37 +0100
Subject: [PATCH 3/5] [libclc] Allow building with pre-built tools

Building the libclc project in-tree with debug tools can be very slow.
This commit adds an option for a user to specify a dierctory from which
to import (e.g., release-built) tools. All tools required by the project
must be imported from the same location, for simplicity.

Original patch downstream authored by @jchlanda.
---
 libclc/CMakeLists.txt | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 4442ff6daa61b8..b0c29ed77270cf 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -50,11 +50,13 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DI
   endif()
 
   # Import required tools as targets
-  foreach( tool IN ITEMS clang llvm-as llvm-link opt )
-find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-add_executable( libclc::${tool} IMPORTED GLOBAL )
-set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
-  endforeach()
+  if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
+foreach( tool IN ITEMS clang llvm-as llvm-link opt )
+  find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  add_executable( libclc::${tool} IMPORTED GLOBAL )
+  set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
+endforeach()
+  endif()
 else()
   # In-tree configuration
   set( LIBCLC_STANDALONE_BUILD FALSE )
@@ -68,8 +70,27 @@ else()
 message(FATAL_ERROR "Clang is not enabled, 

[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck edited 
https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Add initial LIT tests (PR #87989)

2024-04-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck edited 
https://github.com/llvm/llvm-project/pull/87989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [WIP] Libclc tests (PR #87989)

2024-04-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87989

>From 9048dbc6547fa14c78649d02f27d68fc27ca7e70 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 4 Apr 2024 17:49:13 +0100
Subject: [PATCH] [libclc] Add initial LIT tests

These tests aren't very meaningful and aren't immune to false positives,
but they do get the project building when running 'check-all' and so
enable libclc testing in CI.
---
 libclc/CMakeLists.txt  | 16 --
 libclc/test/CMakeLists.txt | 46 +++
 libclc/test/add_sat.cl |  3 ++
 libclc/test/as_type.cl |  5 ++-
 libclc/test/convert.cl |  5 ++-
 libclc/test/cos.cl |  5 ++-
 libclc/test/cross.cl   |  5 ++-
 libclc/test/fabs.cl|  5 ++-
 libclc/test/get_group_id.cl|  5 ++-
 libclc/test/lit.cfg.py | 57 ++
 libclc/test/lit.site.cfg.py.in | 24 ++
 libclc/test/rsqrt.cl   |  8 +++--
 libclc/test/subsat.cl  | 11 ---
 13 files changed, 180 insertions(+), 15 deletions(-)
 create mode 100644 libclc/test/CMakeLists.txt
 create mode 100644 libclc/test/lit.cfg.py
 create mode 100644 libclc/test/lit.site.cfg.py.in

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index f605c3bbbe9dce..ad68c1621c3c18 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -366,7 +366,10 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
 DEPENDS ${builtins_link_lib}
   )
-  add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
+  add_custom_target( prepare-${arch_suffix} ALL DEPENDS ${spv_suffix} )
+  set_target_properties( prepare-${arch_suffix}
+PROPERTIES TARGET_FILE ${spv_suffix}
+  )
   install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
  DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" )
 else()
@@ -392,7 +395,10 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   add_custom_command( OUTPUT ${obj_suffix}
 COMMAND prepare_builtins -o ${obj_suffix} ${builtins_opt_lib}
 DEPENDS ${builtins_opt_lib} prepare_builtins )
-  add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
+  add_custom_target( prepare-${arch_suffix} ALL DEPENDS ${obj_suffix} )
+  set_target_properties( prepare-${arch_suffix}
+PROPERTIES TARGET_FILE ${obj_suffix}
+  )
 
   # nvptx-- targets don't include workitem builtins
   if( NOT clang_triple MATCHES ".*ptx.*--$" )
@@ -406,9 +412,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 set( alias_suffix "${a}-${clang_triple}.bc" )
 add_custom_target( ${alias_suffix} ALL
   COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} 
${alias_suffix}
-  DEPENDS prepare-${obj_suffix} )
+  DEPENDS prepare-${arch_suffix} )
 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION 
"${CMAKE_INSTALL_DATADIR}/clc" )
   endforeach( a )
 endif()
   endforeach( d )
 endforeach( t )
+
+if( NOT LIBCLC_STANDALONE_BUILD )
+  add_subdirectory( test )
+endif()
diff --git a/libclc/test/CMakeLists.txt b/libclc/test/CMakeLists.txt
new file mode 100644
index 00..aa941a3450938d
--- /dev/null
+++ b/libclc/test/CMakeLists.txt
@@ -0,0 +1,46 @@
+set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
+  MAIN_CONFIG
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+)
+
+list(APPEND LIBCLC_TEST_DEPS
+  libclc::clang
+  FileCheck count not
+)
+
+add_custom_target(check-libclc)
+
+foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
+  foreach( d ${${t}_devices} )
+
+# The tests use LLVM IR, so we can't test SPIR-V libraries here.
+string( REPLACE "-" ";" TRIPLE  ${t} )
+list( GET TRIPLE 0 ARCH )
+if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+  continue()
+endif()
+
+get_libclc_device_info(
+  TRIPLE ${t}
+  DEVICE ${d}
+  CPU cpu
+  ARCH_SUFFIX arch_suffix
+  CLANG_TRIPLE clang_triple
+)
+
+add_lit_testsuite(check-libclc-${arch_suffix}
+  "Running libclc ${arch_suffix} regression tests"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  PARAMS "target=${clang_triple}" cpu=${cpu}
+"builtins=$"
+  DEPENDS prepare-${arch_suffix} ${LIBCLC_TEST_DEPS}
+)
+
+add_dependencies( check-libclc check-libclc-${arch_suffix} )
+
+  endforeach()
+endforeach()
diff --git a/libclc/test/add_sat.cl b/libclc/test/add_sat.cl
index 45c8567b440397..f23a105ac83386 100644
--- a/libclc/test/add_sat.cl
+++ b/libclc/test/add_sat.cl
@@ -1,3 +1,6 @@
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
 __kernel void foo(__global char *a, __global char *b, __global char *c) {
   *a = add_sat(*b, *c);
 }
diff --git a/libclc/test/as_type.cl b/libclc/test/as_type.cl

[libclc] [libclc] Allow building with pre-built tools (PR #88922)

2024-04-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/88922

Building the libclc project in-tree with debug tools can be very slow.
This commit adds an option for a user to specify a dierctory from which
to import (e.g., release-built) tools. All tools required by the project
must be imported from the same location, for simplicity.

Original patch downstream authored by @jchlanda.

>From bff3b97b599e1c9529a95ead9d61f9ecc9cad129 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 15:30:20 +0100
Subject: [PATCH 1/4] [libclc] Convert llvm-spirv to imported executable

This tool now behaves like the others, for consistency.
---
 libclc/CMakeLists.txt | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index f605c3bbbe9dce..c77da2d4f18e74 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -81,6 +81,11 @@ endif()
 # llvm-spirv is an optional dependency, used to build spirv-* targets.
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 
+if( LLVM_SPIRV )
+  add_executable( libclc::llvm-spirv IMPORTED GLOBAL )
+  set_target_properties( libclc::llvm-spirv PROPERTIES IMPORTED_LOCATION 
${LLVM_SPIRV} )
+endif()
+
 # List of all targets. Note that some are added dynamically below.
 set( LIBCLC_TARGETS_ALL
   amdgcn--
@@ -101,7 +106,7 @@ endif()
 
 # spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
 # llvm-spirv external tool.
-if( LLVM_SPIRV )
+if( TARGET libclc::llvm-spirv )
   list( APPEND LIBCLC_TARGETS_ALL  spirv-mesa3d- spirv64-mesa3d- )
 endif()
 
@@ -114,7 +119,7 @@ list( SORT LIBCLC_TARGETS_TO_BUILD )
 # Verify that the user hasn't requested mesa3d targets without an available
 # llvm-spirv tool.
 if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" 
IN_LIST LIBCLC_TARGETS_TO_BUILD )
-  if( NOT LLVM_SPIRV )
+  if( NOT TARGET libclc::llvm-spirv )
 message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not 
installed" )
   endif()
 endif()
@@ -363,7 +368,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT ${spv_suffix}
-COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
+COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} 
${builtins_link_lib}
 DEPENDS ${builtins_link_lib}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )

>From 98a9c4621c7814848c5b4fe18e41bd7c671b84ee Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 16:55:53 +0100
Subject: [PATCH 2/4] [libclc] Clarify option help message

This should make it more obvious it applies only to libclc.
---
 libclc/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c77da2d4f18e74..4442ff6daa61b8 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -32,7 +32,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
 set( LIBCLC_MIN_LLVM 3.9.0 )
 
 set( LIBCLC_TARGETS_TO_BUILD "all"
-CACHE STRING "Semicolon-separated list of targets to build, or 'all'." )
+CACHE STRING "Semicolon-separated list of libclc targets to build, or 
'all'." )
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 

>From 4257979d8ee548672b8507bd00486fae98481e3b Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 16 Apr 2024 16:46:37 +0100
Subject: [PATCH 3/4] [libclc] Allow building with pre-built tools

Building the libclc project in-tree with debug tools can be very slow.
This commit adds an option for a user to specify a dierctory from which
to import (e.g., release-built) tools. All tools required by the project
must be imported from the same location, for simplicity.

Original patch downstream authored by @jchlanda.
---
 libclc/CMakeLists.txt | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 4442ff6daa61b8..b0c29ed77270cf 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -50,11 +50,13 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DI
   endif()
 
   # Import required tools as targets
-  foreach( tool IN ITEMS clang llvm-as llvm-link opt )
-find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-add_executable( libclc::${tool} IMPORTED GLOBAL )
-set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
-  endforeach()
+  if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
+foreach( tool IN ITEMS clang llvm-as llvm-link opt )
+  find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  

[libclc] 9d11128 - [libclc] Improve clarity of CMake foreach. NFC.

2024-04-16 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-16T16:50:14+01:00
New Revision: 9d111286322ec99b32467eef3aeec6b588c49f18

URL: 
https://github.com/llvm/llvm-project/commit/9d111286322ec99b32467eef3aeec6b588c49f18
DIFF: 
https://github.com/llvm/llvm-project/commit/9d111286322ec99b32467eef3aeec6b588c49f18.diff

LOG: [libclc] Improve clarity of CMake foreach. NFC.

Should be a bit easier to read.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index ed2764847e709e..f605c3bbbe9dce 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -50,7 +50,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DI
   endif()
 
   # Import required tools as targets
-  foreach( tool clang llvm-as llvm-link opt )
+  foreach( tool IN ITEMS clang llvm-as llvm-link opt )
 find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 add_executable( libclc::${tool} IMPORTED GLOBAL )
 set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
@@ -68,7 +68,7 @@ else()
 message(FATAL_ERROR "Clang is not enabled, but is required to build libclc 
in-tree")
   endif()
 
-  foreach( tool clang llvm-as llvm-link opt )
+  foreach( tool IN ITEMS clang llvm-as llvm-link opt )
 add_executable(libclc::${tool} ALIAS ${tool})
   endforeach()
 endif()
@@ -181,7 +181,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc 
DESTINATION "${CMAKE_INSTAL
 install( DIRECTORY generic/include/clc DESTINATION 
"${CMAKE_INSTALL_INCLUDEDIR}" )
 
 if( ENABLE_RUNTIME_SUBNORMAL )
-  foreach( file subnormal_use_default subnormal_disable )
+  foreach( file IN ITEMS subnormal_use_default subnormal_disable )
 link_bc(
TARGET ${file}
INPUTS ${PROJECT_SOURCE_DIR}/generic/lib/${file}.ll



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 3d118f9 - [libclc] Fix dependencies between targets

2024-04-16 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-16T15:20:26+01:00
New Revision: 3d118f92081ea0c7048749dc5d08c8e8217be4eb

URL: 
https://github.com/llvm/llvm-project/commit/3d118f92081ea0c7048749dc5d08c8e8217be4eb
DIFF: 
https://github.com/llvm/llvm-project/commit/3d118f92081ea0c7048749dc5d08c8e8217be4eb.diff

LOG: [libclc] Fix dependencies between targets

We need file-level - not target-level - dependencies for these custom
commands to re-trigger when their dependencies change.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 302f559dba7a04..ed2764847e709e 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -364,7 +364,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT ${spv_suffix}
 COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
-DEPENDS ${builtins_link_lib_tgt}
+DEPENDS ${builtins_link_lib}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
   install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
@@ -376,7 +376,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc
 COMMAND libclc::opt ${opt_flags} -o ${builtins_opt_lib_tgt}.bc
   ${builtins_link_lib}
-DEPENDS libclc::opt ${builtins_link_lib_tgt}
+DEPENDS libclc::opt ${builtins_link_lib}
   )
   add_custom_target( ${builtins_opt_lib_tgt}
 ALL DEPENDS ${builtins_opt_lib_tgt}.bc
@@ -385,12 +385,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 PROPERTIES TARGET_FILE ${builtins_opt_lib_tgt}.bc
   )
 
+  set( builtins_opt_lib 
$ )
+
   # Add prepare target
   set( obj_suffix ${arch_suffix}.bc )
   add_custom_command( OUTPUT ${obj_suffix}
-COMMAND prepare_builtins -o ${obj_suffix}
-  $
-DEPENDS ${builtins_opt_lib_tgt} prepare_builtins )
+COMMAND prepare_builtins -o ${obj_suffix} ${builtins_opt_lib}
+DEPENDS ${builtins_opt_lib} prepare_builtins )
   add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
 
   # nvptx-- targets don't include workitem builtins



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] a0f8191 - [libclc] Give built bytecode objects a .bc extension. NFC

2024-04-16 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-16T15:20:26+01:00
New Revision: a0f8191af3945482f0f7a7c8f030e8c519a795b7

URL: 
https://github.com/llvm/llvm-project/commit/a0f8191af3945482f0f7a7c8f030e8c519a795b7
DIFF: 
https://github.com/llvm/llvm-project/commit/a0f8191af3945482f0f7a7c8f030e8c519a795b7.diff

LOG: [libclc] Give built bytecode objects a .bc extension. NFC

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 7528228b3b7f9b..302f559dba7a04 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -326,7 +326,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 # Generated files are given just as file names, which we must make
 # absolute to the binary directory.
 set( input_file ${CMAKE_CURRENT_BINARY_DIR}/${file} )
-set( output_file "${LIBCLC_ARCH_OBJFILE_DIR}/${file}.o" )
+set( output_file "${LIBCLC_ARCH_OBJFILE_DIR}/${file}.bc" )
   else()
 # Other files are originally relative to each SOURCE file, which are
 # then make relative to the libclc root directory. We must normalize
@@ -336,7 +336,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 get_filename_component( abs_path ${file} ABSOLUTE BASE_DIR 
${PROJECT_SOURCE_DIR} )
 file( RELATIVE_PATH root_rel_path ${PROJECT_SOURCE_DIR} ${abs_path} )
 set( input_file ${PROJECT_SOURCE_DIR}/${file} )
-set( output_file "${LIBCLC_ARCH_OBJFILE_DIR}/${root_rel_path}.o" )
+set( output_file "${LIBCLC_ARCH_OBJFILE_DIR}/${root_rel_path}.bc" )
   endif()
 
   get_filename_component( file_dir ${file} DIRECTORY )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [WIP] Libclc tests (PR #87989)

2024-04-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87989

>From c53dc3564822f305d09d19dc3b7327b33028fe11 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 4 Apr 2024 17:49:13 +0100
Subject: [PATCH] [libclc] Add initial LIT tests

---
 libclc/CMakeLists.txt  |  4 +++
 libclc/test/CMakeLists.txt | 38 +++
 libclc/test/add_sat.cl |  3 ++
 libclc/test/as_type.cl |  5 ++-
 libclc/test/convert.cl |  5 ++-
 libclc/test/cos.cl |  5 ++-
 libclc/test/cross.cl   |  5 ++-
 libclc/test/fabs.cl|  5 ++-
 libclc/test/get_group_id.cl|  5 ++-
 libclc/test/lit.cfg.py | 57 ++
 libclc/test/lit.site.cfg.py.in | 24 ++
 libclc/test/rsqrt.cl   |  8 +++--
 libclc/test/subsat.cl  | 11 ---
 13 files changed, 163 insertions(+), 12 deletions(-)
 create mode 100644 libclc/test/CMakeLists.txt
 create mode 100644 libclc/test/lit.cfg.py
 create mode 100644 libclc/test/lit.site.cfg.py.in

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 7528228b3b7f9b..ca5e5d1d1755d2 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -411,3 +411,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 endif()
   endforeach( d )
 endforeach( t )
+
+if( NOT LIBCLC_STANDALONE_BUILD )
+  add_subdirectory( test )
+endif()
diff --git a/libclc/test/CMakeLists.txt b/libclc/test/CMakeLists.txt
new file mode 100644
index 00..796b6a0e1e8544
--- /dev/null
+++ b/libclc/test/CMakeLists.txt
@@ -0,0 +1,38 @@
+set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
+  MAIN_CONFIG
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+)
+
+list(APPEND LIBCLC_TEST_DEPS
+  libclc::clang
+  FileCheck count not
+)
+
+add_custom_target(check-libclc)
+
+foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
+  foreach( d ${${t}_devices} )
+
+get_libclc_device_info(
+  TRIPLE ${t}
+  DEVICE ${d}
+  CPU cpu
+  ARCH_SUFFIX arch_suffix
+  CLANG_TRIPLE clang_triple
+)
+
+add_lit_testsuite(check-libclc-${arch_suffix}
+  "Running libclc ${arch_suffix} regression tests"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  PARAMS "target=${clang_triple}" cpu=${cpu} "builtins=${arch_suffix}.bc"
+  DEPENDS prepare-${arch_suffix}.bc ${LIBCLC_TEST_DEPS}
+)
+
+add_dependencies( check-libclc check-libclc-${arch_suffix} )
+
+  endforeach()
+endforeach()
diff --git a/libclc/test/add_sat.cl b/libclc/test/add_sat.cl
index 45c8567b440397..f23a105ac83386 100644
--- a/libclc/test/add_sat.cl
+++ b/libclc/test/add_sat.cl
@@ -1,3 +1,6 @@
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
 __kernel void foo(__global char *a, __global char *b, __global char *c) {
   *a = add_sat(*b, *c);
 }
diff --git a/libclc/test/as_type.cl b/libclc/test/as_type.cl
index e8fb1228d28d11..729303a53da051 100644
--- a/libclc/test/as_type.cl
+++ b/libclc/test/as_type.cl
@@ -1,3 +1,6 @@
-__kernel void foo(int4 *x, float4 *y) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void foo(__global int4 *x, __global float4 *y) {
   *x = as_int4(*y);
 }
diff --git a/libclc/test/convert.cl b/libclc/test/convert.cl
index 928fc326b6a18f..9ea5b192769a26 100644
--- a/libclc/test/convert.cl
+++ b/libclc/test/convert.cl
@@ -1,3 +1,6 @@
-__kernel void foo(int4 *x, float4 *y) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void foo(__global int4 *x, __global float4 *y) {
   *x = convert_int4(*y);
 }
diff --git a/libclc/test/cos.cl b/libclc/test/cos.cl
index 4230eb2a0e93c6..21384ba1d73dfd 100644
--- a/libclc/test/cos.cl
+++ b/libclc/test/cos.cl
@@ -1,3 +1,6 @@
-__kernel void foo(float4 *f) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void foo(__global float4 *f) {
   *f = cos(*f);
 }
diff --git a/libclc/test/cross.cl b/libclc/test/cross.cl
index 08955cbd9af568..c628a6656c5739 100644
--- a/libclc/test/cross.cl
+++ b/libclc/test/cross.cl
@@ -1,3 +1,6 @@
-__kernel void foo(float4 *f) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void foo(__global float4 *f) {
   *f = cross(f[0], f[1]);
 }
diff --git a/libclc/test/fabs.cl b/libclc/test/fabs.cl
index 91d42c466676fd..27881304224567 100644
--- a/libclc/test/fabs.cl
+++ b/libclc/test/fabs.cl
@@ -1,3 +1,6 @@
-__kernel void foo(float *f) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void foo(__global float *f) {
   *f = fabs(*f);
 }
diff --git a/libclc/test/get_group_id.cl b/libclc/test/get_group_id.cl
index 43725cda802710..cd4d114b59ed16 100644
--- a/libclc/test/get_group_id.cl
+++ b/libclc/test/get_group_id.cl
@@ -1,3 +1,6 @@
-__kernel void foo(int *i) {
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
+
+// CHECK: foo
+__kernel void 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-11 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/87622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-11 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87622

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/4] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87622

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/3] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87622

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/2] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

CC @mgorny -  I was unsure whether you are actively using and interested 
`libclc` or you were just looking after build bots or some other reason. I've 
successfully built the SPIR-V libraries out-of-tree but another pair of eyes 
can't hurt.

I was wondering - if we `libclc` building in-tree, would there be interest in 
building the SPIR-V targets with the LLVM SPIRV backend, rather than the 
external `llvm-spirv` tool?

https://github.com/llvm/llvm-project/pull/87622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-09 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87622

>From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 257 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 
 libclc/cmake/modules/AddLibclc.cmake  | 153 +++
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 305 insertions(+), 306 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c6e3cdf23fe0c8..ff4e4369a7af39 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
 
-# Print toolchain
-message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
-message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
-message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
-message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
-message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
-if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT 

[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> Thanks. Unfortunately, I'm still getting a build failure:
> 
> ```
> [1792/1922] cd /tmp/portage/dev-libs/libclc-19.0.0./work/libclc_build && 
> /usr/lib/llvm/17/bin/llvm-spirv --spirv-max-version=1.1 -o spirv-mesa3d-.spv 
> builtins.link.spirv-mesa3d-
> FAILED: spirv-mesa3d-.spv 
> /tmp/portage/dev-libs/libclc-19.0.0./work/libclc_build/spirv-mesa3d-.spv 
> cd /tmp/portage/dev-libs/libclc-19.0.0./work/libclc_build && 
> /usr/lib/llvm/17/bin/llvm-spirv --spirv-max-version=1.1 -o spirv-mesa3d-.spv 
> builtins.link.spirv-mesa3d-
> No such file or directory
> ```
> 
> It seems to be missing `.bc` suffix, I guess? Looking at the earlier mention, 
> shouldn't it be `$`?

Sorry, it should be properly fixed now - I was rushing things and that just 
made it worse. I hadn't noticed that the build I was testing hadn't found 
`llvm-spirv` and so those targets were missing. I've now built it locally 
successfully.

https://github.com/llvm/llvm-project/pull/87505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] b439140 - [libclc] Fix more spirv build dependencies

2024-04-08 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-08T16:51:30+01:00
New Revision: b439140e2982dd77ef28a9069e16ae77bbe2bc5a

URL: 
https://github.com/llvm/llvm-project/commit/b439140e2982dd77ef28a9069e16ae77bbe2bc5a
DIFF: 
https://github.com/llvm/llvm-project/commit/b439140e2982dd77ef28a9069e16ae77bbe2bc5a.diff

LOG: [libclc] Fix more spirv build dependencies

The last fix was incomplete.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 770f69a15a300f..c6e3cdf23fe0c8 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -332,7 +332,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 if( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT "${spv_suffix}"
-COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
${builtins_link_lib_tgt}
+COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
$
 DEPENDS ${builtins_link_lib_tgt} )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
   install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [WIP] Libclc tests (PR #87989)

2024-04-08 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87989

>From b87c2862491aed03f883d6b124a845b0d7c47699 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/4] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 233 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 -
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 -
 libclc/cmake/modules/AddLibclc.cmake  | 153 
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 293 insertions(+), 294 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 8750a65a717f9b..e509a61f51b927 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
+
+  # Import required tools as targets
+  foreach( tool clang llvm-as llvm-link opt )
+find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+add_executable( libclc::${tool} IMPORTED GLOBAL )
+set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
+  endforeach()
+else()
+  # In-tree 

[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> > > > ```
> > > >   set( spv_suffix ${arch_suffix}.spv )
> > > >   add_custom_command( OUTPUT "${spv_suffix}"
> > > > COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> > > > ${builtins_opt_lib_tgt}
> > > > DEPENDS ${builtins_link_lib_tgt} )
> > > > ```
> > > > 
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > > 
> > > >   
> > > > I think that ought to be `DEPENDS ${builtins_opt_lib_tgt}`. Do you need 
> > > > me to send a PR for that?
> > > 
> > > 
> > > Hmm yes you might be right. Just to confirm, does that fix the problem 
> > > for you?
> > > I can't be sure but it seems like that was a problem before 
> > > [61efea7](https://github.com/llvm/llvm-project/commit/61efea7142e904e6492e1ce0566ec23d9d221c1e)
> > >  when I last touched it, as least from a simple reading of the CMake.
> > 
> > 
> > I think the issue is not coming from the DEPENDS but from the source.
> > ```
> > - COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> > ${builtins_opt_lib_tgt}
> > + COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> > ${builtins_link_lib_tgt}
> > ```
> 
> Yes, that's it.

Should be fixed by f46f6465062b 

https://github.com/llvm/llvm-project/pull/87505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] f46f646 - [libclc] Fix spirv build dependencies

2024-04-08 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-08T15:48:15+01:00
New Revision: f46f6465062bd6ddc96e3838c50e1a0f85f92dd4

URL: 
https://github.com/llvm/llvm-project/commit/f46f6465062bd6ddc96e3838c50e1a0f85f92dd4
DIFF: 
https://github.com/llvm/llvm-project/commit/f46f6465062bd6ddc96e3838c50e1a0f85f92dd4.diff

LOG: [libclc] Fix spirv build dependencies

These were accidentally broken in 61efea7.

Thanks to @mgorny and @rjodinchr for spotting this.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 8750a65a717f9b..770f69a15a300f 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -332,7 +332,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 if( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" )
   set( spv_suffix ${arch_suffix}.spv )
   add_custom_command( OUTPUT "${spv_suffix}"
-COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
${builtins_opt_lib_tgt}
+COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
${builtins_link_lib_tgt}
 DEPENDS ${builtins_link_lib_tgt} )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
   install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> > > ```
> > >   set( spv_suffix ${arch_suffix}.spv )
> > >   add_custom_command( OUTPUT "${spv_suffix}"
> > > COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> > > ${builtins_opt_lib_tgt}
> > > DEPENDS ${builtins_link_lib_tgt} )
> > > ```
> > > 
> > > 
> > > 
> > >   
> > > 
> > > 
> > >   
> > > 
> > > 
> > > 
> > >   
> > > I think that ought to be `DEPENDS ${builtins_opt_lib_tgt}`. Do you need 
> > > me to send a PR for that?
> > 
> > 
> > Hmm yes you might be right. Just to confirm, does that fix the problem for 
> > you?
> > I can't be sure but it seems like that was a problem before 
> > [61efea7](https://github.com/llvm/llvm-project/commit/61efea7142e904e6492e1ce0566ec23d9d221c1e)
> >  when I last touched it, as least from a simple reading of the CMake.
> 
> I think the issue is not coming from the DEPENDS but from the source.
> 
> ```
> - COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" ${builtins_opt_lib_tgt}
> + COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> ${builtins_link_lib_tgt}
> ```

Yes, that's it.

https://github.com/llvm/llvm-project/pull/87505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> ```
>   set( spv_suffix ${arch_suffix}.spv )
>   add_custom_command( OUTPUT "${spv_suffix}"
> COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> ${builtins_opt_lib_tgt}
> DEPENDS ${builtins_link_lib_tgt} )
> ```
> 
> I think that ought to be `DEPENDS ${builtins_opt_lib_tgt}`. Do you need me to 
> send a PR for that?

Hmm yes you might be right. Just to confirm, does that fix the problem for you?

I can't be sure but it seems like that was a problem before 
61efea7142e904e6492e1ce0566ec23d9d221c1e when I last touched it, as least from 
a simple reading of the CMake.

https://github.com/llvm/llvm-project/pull/87505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [WIP] Libclc tests (PR #87989)

2024-04-08 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/87989

None

>From b87c2862491aed03f883d6b124a845b0d7c47699 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH 1/2] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 233 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 -
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 -
 libclc/cmake/modules/AddLibclc.cmake  | 153 
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 293 insertions(+), 294 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 8750a65a717f9b..e509a61f51b927 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
+
+  # Import required tools as targets
+  foreach( tool clang llvm-as llvm-link opt )
+find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+add_executable( libclc::${tool} IMPORTED GLOBAL )
+set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
+  endforeach()
+else()
+  # In-tree 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-08 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck edited 
https://github.com/llvm/llvm-project/pull/87622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-08 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/87622

>From b87c2862491aed03f883d6b124a845b0d7c47699 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 3 Apr 2024 16:09:30 +0100
Subject: [PATCH] [libclc] Refactor build system to allow in-tree builds

The previous build system was adding custom "OpenCL" and "LLVM IR"
languages in CMake to build the builtin libraries. This was making it
harder to build in-tree because the tool binaries needed to be present
at configure time.

This commit refactors the build system to use custom commands to build
the bytecode files one by one, and link them all together into the final
bytecode library. It also enables in-tree builds by aliasing the
clang/llvm-link/etc. tool targets to internal targets, which are
imported from the LLVM installation directory when building out of tree.

Diffing (with llvm-diff) all of the final bytecode libraries in an
out-of-tree configuration against those built using the current tip
system shows no changes. Note that there are textual changes to metadata
IDs which confuse regular diff, and that llvm-diff 14 and below may show
false-positives.

This commit also removes a file listed in one of the SOURCEs which
didn't exist and which was preventing the use of
ENABLE_RUNTIME_SUBNORMAL when configuring CMake.
---
 libclc/CMakeLists.txt | 233 ++
 libclc/cmake/CMakeCLCCompiler.cmake.in|   9 -
 libclc/cmake/CMakeCLCInformation.cmake|  12 -
 libclc/cmake/CMakeDetermineCLCCompiler.cmake  |  18 --
 .../cmake/CMakeDetermineLLAsmCompiler.cmake   |  24 --
 libclc/cmake/CMakeLLAsmCompiler.cmake.in  |  10 -
 libclc/cmake/CMakeLLAsmInformation.cmake  |  12 -
 libclc/cmake/CMakeTestCLCCompiler.cmake   |  56 -
 libclc/cmake/CMakeTestLLAsmCompiler.cmake |  56 -
 libclc/cmake/modules/AddLibclc.cmake  | 153 
 libclc/generic/lib/SOURCES|   1 -
 llvm/tools/CMakeLists.txt |   3 +
 12 files changed, 293 insertions(+), 294 deletions(-)
 delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in
 delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake
 delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake
 delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake
 create mode 100644 libclc/cmake/modules/AddLibclc.cmake

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 8750a65a717f9b..e509a61f51b927 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C)
 
 set(CMAKE_CXX_STANDARD 17)
 
+# Add path for custom modules
+list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" )
+
+set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
+set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
+set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir )
+
+include( AddLibclc )
+
 include( GNUInstallDirs )
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   amdgcn-amdhsa/lib/SOURCES;
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL 
CMAKE_CURRENT_SOURCE_DIR )
+  # Out-of-tree configuration
+  set( LIBCLC_STANDALONE_BUILD TRUE )
 
-message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
+  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+  include(AddLLVM)
 
-if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
-  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
-endif()
+  message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
-find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+  if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
+message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  endif()
+
+  # Import required tools as targets
+  foreach( tool clang llvm-as llvm-link opt )
+find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
+add_executable( libclc::${tool} IMPORTED GLOBAL )
+set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION 
${LLVM_TOOL_${tool}} )
+  endforeach()
+else()
+  # In-tree configuration
+ 

[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-08 Thread Fraser Cormack via cfe-commits


@@ -358,3 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 endif()
   endforeach( d )
 endforeach( t )
+
+if( NOT LIBCLC_STANDALONE_BUILD )
+  add_subdirectory( test )

frasercrmck wrote:

Ach yeah sorry, I have another path locally which adds some LIT tests - this 
should be in that one. I'll remove it for now, and we can maybe decide whether 
or not to add LIT testing to this PR or not.

https://github.com/llvm/llvm-project/pull/87622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-08 Thread Fraser Cormack via cfe-commits


@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
 
 option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
-find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-include(AddLLVM)
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)

frasercrmck wrote:

Yeah, I think you're right. I'm not 100%, but other LLVM sub-projects do it so 
I think we should too.

https://github.com/llvm/llvm-project/pull/87622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> This change broke standalone build against LLVM dylib — it now insists on 
> linking to non-existing static libraries:
> 
> ```
> FAILED: prepare_builtins 
> : && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -march=znver2 
> --param=l1-cache-size=32 --param=l1-cache-line-size=64 -O2 -pipe 
> -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed 
> -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,-rpath-link,  
> -Wl,--gc-sections 
> CMakeFiles/prepare_builtins.dir/utils/prepare-builtins.cpp.o -o 
> prepare_builtins  -Wl,-rpath,"\$ORIGIN/../lib64:/usr/lib/llvm/17/lib64"  
> -lLLVMBitReader  -lLLVMBitWriter  -lLLVMCore  -lLLVMIRReader  
> /usr/lib/llvm/17/lib64/libLLVMSupport.a  -lrt  -ldl  -lm  /usr/lib64/libz3.so 
>  /usr/lib64/libz.so  /usr/lib64/libzstd.so  /usr/lib64/libtinfo.so  
> /usr/lib/llvm/17/lib64/libLLVMDemangle.a && :
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lLLVMBitReader: No such file or directory
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lLLVMBitWriter: No such file or directory
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lLLVMCore: No such file or directory
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lLLVMIRReader: No such file or directory
> collect2: error: ld returned 1 exit status
> ```
> 
> Given that it apparently doesn't fix in-tree builds fully, please revert and 
> let's figure out how to do it properly without breaking its primary use case.

Ach, sorry about that, thanks for catching that. It's tricky without CI to 
catch this kind of thing, though that was particularly silly of me. I actually 
struggled to build LLVM locally with the kind of configuration that only has 
dynamic libraries available to reproduce.

That said, I've pushed 8461d901a770516cf2069fe3bce979a6f8fc8d76 which should 
just re-instate the old behaviour for out-of-tree builds. If that doesn't fix 
the issue then I'll revert properly - please let me know, thanks.

https://github.com/llvm/llvm-project/pull/87505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 8461d90 - [libclc] Restore linking against dynamic libLLVM for out-of-tree builds

2024-04-08 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-08T11:05:38+01:00
New Revision: 8461d901a770516cf2069fe3bce979a6f8fc8d76

URL: 
https://github.com/llvm/llvm-project/commit/8461d901a770516cf2069fe3bce979a6f8fc8d76
DIFF: 
https://github.com/llvm/llvm-project/commit/8461d901a770516cf2069fe3bce979a6f8fc8d76.diff

LOG: [libclc] Restore linking against dynamic libLLVM for out-of-tree builds

This fixes a regression where building against an installation without
the static libraries would fail. This just reinstates the old behaviour
for out-of-tree builds, assuming that in-tree builds (which still aren't
officially supported) will have the static libraries available. We can
refine this as we move towards supporting in-tree builds.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 21e5cac688227d..8750a65a717f9b 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -122,7 +122,11 @@ set(LLVM_LINK_COMPONENTS
   IRReader
   Support
 )
-add_llvm_utility( prepare_builtins utils/prepare-builtins.cpp )
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  add_llvm_executable( prepare_builtins utils/prepare-builtins.cpp )
+else()
+  add_llvm_utility( prepare_builtins utils/prepare-builtins.cpp )
+endif()
 target_compile_definitions( prepare_builtins PRIVATE ${LLVM_VERSION_DEFINE} )
 # These were not properly reported in early LLVM and we don't need them
 target_compile_options( prepare_builtins PRIVATE -fno-rtti -fno-exceptions )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] 338ecfb - [libclc] Use VERSION_GREATER_EQUAL where appropriate. NFC

2024-04-04 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-04-04T17:56:40+01:00
New Revision: 338ecfbac351e4b211836ad73d75bbdf729e9134

URL: 
https://github.com/llvm/llvm-project/commit/338ecfbac351e4b211836ad73d75bbdf729e9134
DIFF: 
https://github.com/llvm/llvm-project/commit/338ecfbac351e4b211836ad73d75bbdf729e9134.diff

LOG: [libclc] Use VERSION_GREATER_EQUAL where appropriate. NFC

This was added in CMake 3.7, which might explain why it wasn't used
before.

Also reformat a couple of comments.

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 2d000cf5cad8c4..21e5cac688227d 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -20,7 +20,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   spirv64/lib/SOURCES
 )
 
-set( LIBCLC_MIN_LLVM "3.9.0" )
+set( LIBCLC_MIN_LLVM 3.9.0 )
 
 set( LIBCLC_TARGETS_TO_BUILD "all"
 CACHE STRING "Semicolon-separated list of targets to build, or 'all'." )
@@ -32,7 +32,7 @@ include(AddLLVM)
 
 message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
-if( ${LLVM_PACKAGE_VERSION} VERSION_LESS ${LIBCLC_MIN_LLVM} )
+if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM )
   message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
 endif()
 
@@ -66,7 +66,7 @@ set( LIBCLC_TARGETS_ALL
 )
 
 # mesa3d environment is only available since LLVM 4.0
-if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "3.9.0" )
+if( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 )
   list( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d )
 endif()
 
@@ -102,7 +102,7 @@ set( LLVM_VERSION_DEFINE 
"-DHAVE_LLVM=0x${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MIN
 
 
 # LLVM 13 enables standard includes by default
-if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "12.99.99" )
+if( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 13.0.0 )
   set( CMAKE_LLAsm_FLAGS "${CMAKE_LLAsm_FLAGS} -cl-no-stdinc" )
   set( CMAKE_CLC_FLAGS "${CMAKE_CLC_FLAGS} -cl-no-stdinc" )
 endif()
@@ -205,7 +205,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 list( APPEND dirs amdgpu )
   endif()
 
-  #nvptx is special
+  # nvptx is special
   if( ${ARCH} STREQUAL nvptx OR ${ARCH} STREQUAL nvptx64 )
 set( DARCH ptx )
   else()
@@ -226,8 +226,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 endforeach()
   endforeach()
 
-  # Add the generated convert.cl here to prevent adding
-  # the one listed in SOURCES
+  # Add the generated convert.cl here to prevent adding the one listed in
+  # SOURCES
   if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
 if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL "clspv" AND
 NOT ${ARCH} STREQUAL "clspv64" )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Track dependencies through dependency files (PR #86965)

2024-03-28 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/86965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Track dependencies through dependency files (PR #86965)

2024-03-28 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> The build here seems to be trying to define clc as a language, which then 
> results in needing to rely on language support magic like this. I think it 
> would be better if this did what rocm-device-libs does and treat these as 
> custom targets. I don't think it's particularly helpful to pretend like this 
> is a normal host compiler detection situation.
> 
> https://github.com/ROCm/llvm-project/blob/efc7219da809b6bce7b1c92c1915a0eac68fb1f2/amd/device-libs/cmake/OCL.cmake#L136

Yes, I agree. It also makes building `libclc` in-tree a nuisance, because CMake 
needs to know the path to the "language compilers" at configure time, which 
leads to _fun_ like intuiting the final output path of `clang` and other tools 
and writing an empty string to those paths to ensure they exist on disk before 
you call `enable_language`.

So I agree that moving to custom targets would be beneficial for many reasons. 
I think overall it would be a simpler solution, not least because it's the more 
idiomatic way of doing CMake. I might look into that in the near future, but 
can't promise it.

https://github.com/llvm/llvm-project/pull/86965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Track dependencies through dependency files (PR #86965)

2024-03-28 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/86965

This commit fixes the problem of missing build dependencies between libclc 
source files and their various includes (namely headers and .inc files).

We would like to do this with compiler-generated dependency files because then 
the dependencies are accurate and there are no false positives, leading to 
unnecessary rebuilds. This is how regular C/C++ dependencies are usually 
tracked by CMake.

Note that this variable is an internal API so is not guaranteed to work, but 
then again *all* of CMake's support for new languages (which we use for CLC/LL 
languages) is an internal API. On balance this change is probably worth it due 
to how minimally invasive it is. It should work with all supported compilers 
and CMake generators.

>From 9dfb66dc1be0652fef199b51754fe017d330c43c Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 28 Mar 2024 15:43:29 +
Subject: [PATCH] [libclc] Track dependencies through dependency files

This commit fixes the problem of missing build dependencies between
libclc source files and their various includes (namely headers and .inc
files).

We would like to do this with compiler-generated dependency files
because then the dependencies are accurate and there are no false
positives, leading to unnecessary rebuilds. This is how regular C/C++
dependencies are usually tracked by CMake.

Note that this variable is an internal API so is not guaranteed to work,
but then again *all* of CMake's support for new languages (which we use
for CLC/LL languages) is an internal API. On balance this change is
probably worth it due to how minimally invasive it is. It should work
with all supported compilers and CMake generators.
---
 libclc/cmake/CMakeCLCInformation.cmake | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libclc/cmake/CMakeCLCInformation.cmake 
b/libclc/cmake/CMakeCLCInformation.cmake
index 6eecf4edf0e7bb..95327e44397222 100644
--- a/libclc/cmake/CMakeCLCInformation.cmake
+++ b/libclc/cmake/CMakeCLCInformation.cmake
@@ -9,3 +9,4 @@ if(NOT CMAKE_CLC_CREATE_STATIC_LIBRARY)
 endif()
 
 set(CMAKE_INCLUDE_FLAG_CLC "-I")
+set(CMAKE_DEPFILE_FLAGS_CLC "-MD -MT  -MF ")

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Make CMake messages better fit into LLVM (PR #86945)

2024-03-28 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/86945
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Make CMake messages better fit into LLVM (PR #86945)

2024-03-28 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/86945

The libclc project is currently only properly supported as an external project. 
However, when trying to get it to also build in-tree, the CMake configuration 
messages it outputs stand out amongst the rest of the LLVM projects and 
sub-projects.

This commit makes all messages clear that they belong to the libclc project, as 
well as turning them into 'STATUS' messages where appropriate.

>From 45e1aca14d23784d53b8b2689c87916a26355d4b Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 28 Mar 2024 12:37:37 +
Subject: [PATCH] [libclc] Make CMake messages better fit into LLVM

The libclc project is currently only properly supported as an external
project. However, when trying to get it to also build in-tree, the CMake
configuration messages it outputs stand out amongst the rest of the LLVM
projects and sub-projects.

This commit makes all messages clear that they belong to the libclc
project, as well as turning them into 'STATUS' messages where
appropriate.
---
 libclc/CMakeLists.txt | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 745b848fba4901..9236f09d366782 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -45,7 +45,7 @@ option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of 
subnormal support."
 find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
 include(AddLLVM)
 
-message( "LLVM version: ${LLVM_PACKAGE_VERSION}" )
+message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
 if( ${LLVM_PACKAGE_VERSION} VERSION_LESS ${LIBCLC_MIN_LLVM} )
   message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
@@ -67,14 +67,13 @@ find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 
 # Print toolchain
-message( "clang: ${LLVM_CLANG}" )
-message( "llvm-as: ${LLVM_AS}" )
-message( "llvm-link: ${LLVM_LINK}" )
-message( "opt: ${LLVM_OPT}" )
-message( "llvm-spirv: ${LLVM_SPIRV}" )
-message( "" )
+message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
+message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
+message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
+message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
+message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
 if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK )
-  message( FATAL_ERROR "toolchain incomplete!" )
+  message( FATAL_ERROR "libclc toolchain incomplete!" )
 endif()
 
 list( SORT LIBCLC_TARGETS_TO_BUILD )
@@ -182,7 +181,7 @@ add_custom_target( "clspv-generate_convert.cl" DEPENDS 
clspv-convert.cl )
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
-  message( "BUILDING ${t}" )
+  message( STATUS "libclc target '${t}' is enabled" )
   string( REPLACE "-" ";" TRIPLE  ${t} )
   list( GET TRIPLE 0 ARCH )
   list( GET TRIPLE 1 VENDOR )
@@ -265,7 +264,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   set( mcpu "-mcpu=${d}" )
   set( arch_suffix "${d}-${t}" )
 endif()
-message( "  DEVICE: ${d} ( ${${d}_aliases} )" )
+message( STATUS "  device: ${d} ( ${${d}_aliases} )" )
 
 if ( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" )
   if( ${ARCH} STREQUAL "spirv" )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b369ff - [analyzer][NFC] Fix unused variable warning

2024-03-20 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-03-20T11:43:38Z
New Revision: 4b369ff076d9205ddbcfcdef89276a737a83ce0e

URL: 
https://github.com/llvm/llvm-project/commit/4b369ff076d9205ddbcfcdef89276a737a83ce0e
DIFF: 
https://github.com/llvm/llvm-project/commit/4b369ff076d9205ddbcfcdef89276a737a83ce0e.diff

LOG: [analyzer][NFC] Fix unused variable warning

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 1a9d6d3127fb7f..b36fa95bc73f3e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -43,8 +43,7 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
 if (auto *call = dyn_cast(E)) {
   if (auto *memberCall = dyn_cast(call)) {
 if (auto *decl = memberCall->getMethodDecl()) {
-  std::optional IsGetterOfRefCt =
-  isGetterOfRefCounted(memberCall->getMethodDecl());
+  std::optional IsGetterOfRefCt = isGetterOfRefCounted(decl);
   if (IsGetterOfRefCt && *IsGetterOfRefCt) {
 E = memberCall->getImplicitObjectArgument();
 if (StopAtFirstRefCountedObj) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Convert tabs to spaces in CMake (PR #85634)

2024-03-18 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> > FWIW I don't think the build bots are actually building `libclc`.
> > Locally, at least, it's not sufficient to specify 
> > `LLVM_ENABLE_PROJECTS=libclc` - you _also_ need 
> > `LLVM_EXTERNAL_PROJECTS=libclc`. Even then, it doesn't build for me 
> > in-tree, because it assumes `CMAKE_SOURCE_DIR` is its own top-level 
> > directory, which it isn't as it's `llvm/`.
> > I had a patch locally to switch `CMAKE_SOURCE_DIR` to `PROJECT_SOURCE_DIR` 
> > which I think is sufficient to cover both build styles. Should I contribute 
> > this upstream?
> > Another problem is that all `libclc` targets are enabled by default, but 
> > the `spirv-mesa3d` and `spirv64-mesa3d` targets both need `llvm-spirv` 
> > which I doubt our buildbots have available. Should those be disabled by 
> > default, or should the buildbots disable them?
> 
> I'm not aware of any bots building libclc. It would be nice if you could 
> build libclc more easily, it does not fit in with the rest of the projects 
> right now. Any improvements you want to make in this area would be welcome.

Ah, yeah that's possible. I mentioned it because 
https://github.com/llvm/llvm-project/blob/main/.github/workflows/libclc-tests.yml
 and  
https://buildkite.com/llvm-project/github-pull-requests/builds/48183#018e5157-23d0-4c70-b8bc-54bbdceabb6c
 look like they're ostensibly trying to build it, but aren't.

I'll see what I can do to improve the situation. We're mostly working with 
libclc downstream in DPC++ and it's been changed quite significantly, so it's a 
bit delicate to get the balance right.

https://github.com/llvm/llvm-project/pull/85634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Convert tabs to spaces in CMake (PR #85634)

2024-03-18 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/85634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Convert tabs to spaces in CMake (PR #85634)

2024-03-18 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

FWIW I don't think the build bots are actually building `libclc`.

Locally, at least, it's not sufficient to specify `LLVM_ENABLE_PROJECTS=libclc` 
- you _also_ need `LLVM_EXTERNAL_PROJECTS=libclc`. Even then, it doesn't build 
for me in-tree, because it assumes `CMAKE_SOURCE_DIR` is its own top-level 
directory, which it isn't as it's `llvm/`.

I had a patch locally to switch `CMAKE_SOURCE_DIR` to `PROJECT_SOURCE_DIR` 
which I think is sufficient to cover both build styles. Should I contribute 
this upstream?

Another problem is that all `libclc` targets are enabled by default, but the 
`spirv-mesa3d` and `spirv64-mesa3d` targets both need `llvm-spirv` which I 
doubt our buildbots have available. Should those be disabled by default, or 
should the buildbots disable them?

https://github.com/llvm/llvm-project/pull/85634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Convert tabs to spaces in CMake (PR #85634)

2024-03-18 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

@tstellar are you the code owner for `libclc`?

https://github.com/llvm/llvm-project/pull/85634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Convert tabs to spaces in CMake (PR #85634)

2024-03-18 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/85634

Having a mix of tabs and spaces makes the diff of any changes to the build 
system noisier than necessary. This commit unifies them to two spaces.

This includes some minor cosmetic changes such as with joining things on one 
line where appropriate.

There are other files in libclc which have tabs but those haven't been touched 
at this time. Those could come at another time if desired, though they might be 
more contentious as the project isn't clang-formatted at all and so that might 
invite larger discussions around formatting.

>From 97a5c5d9b6e9a3e38aee92cd6670abb395495c6e Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Mon, 18 Mar 2024 11:27:55 +
Subject: [PATCH] [libclc] Convert tabs to spaces in CMake

Having a mix of tabs and spaces makes the diff of any changes to the
build system noisier than necessary. This commit unifies them to two
spaces.

This includes some minor cosmetic changes such as with joining things on
one line where appropriate.

There are other files in libclc which have tabs but those haven't been
touched at this time. Those could come at another time if desired,
though they might be more contentious as the project isn't
clang-formatted at all and so that might invite larger discussions
around formatting.
---
 libclc/CMakeLists.txt| 408 +++
 libclc/check_external_calls.sh   |  16 +-
 libclc/cmake/CMakeLLAsmInformation.cmake |   4 +-
 3 files changed, 206 insertions(+), 222 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 18f77940e76669..745b848fba4901 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -40,8 +40,7 @@ set( LIBCLC_MIN_LLVM "3.9.0" )
 set( LIBCLC_TARGETS_TO_BUILD "all"
 CACHE STRING "Semicolon-separated list of targets to build, or 'all'." )
 
-option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support."
-OFF )
+option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal 
support." OFF )
 
 find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
 include(AddLLVM)
@@ -49,16 +48,16 @@ include(AddLLVM)
 message( "LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
 if( ${LLVM_PACKAGE_VERSION} VERSION_LESS ${LIBCLC_MIN_LLVM} )
-   message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
+  message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
 endif()
 
 # mesa3d environment is only available since LLVM 4.0
 if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "3.9.0" )
-   set( LIBCLC_TARGETS_ALL ${LIBCLC_TARGETS_ALL} amdgcn-mesa-mesa3d )
+  set( LIBCLC_TARGETS_ALL ${LIBCLC_TARGETS_ALL} amdgcn-mesa-mesa3d )
 endif()
 
 if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
-   set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
+  set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
 endif()
 
 find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
@@ -75,15 +74,15 @@ message( "opt: ${LLVM_OPT}" )
 message( "llvm-spirv: ${LLVM_SPIRV}" )
 message( "" )
 if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK )
-   message( FATAL_ERROR "toolchain incomplete!" )
+  message( FATAL_ERROR "toolchain incomplete!" )
 endif()
 
 list( SORT LIBCLC_TARGETS_TO_BUILD )
 
 if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" 
IN_LIST LIBCLC_TARGETS_TO_BUILD )
-   if( NOT LLVM_SPIRV )
-   message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools 
is not installed" )
-   endif()
+  if( NOT LLVM_SPIRV )
+message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not 
installed" )
+  endif()
 endif()
 
 set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
@@ -99,8 +98,8 @@ set( LLVM_VERSION_DEFINE 
"-DHAVE_LLVM=0x${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MIN
 
 # LLVM 13 enables standard includes by default
 if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "12.99.99" )
-   set( CMAKE_LLAsm_FLAGS "${CMAKE_LLAsm_FLAGS} 
-cl-no-stdinc")
-   set( CMAKE_CLC_FLAGS "${CMAKE_CLC_FLAGS} 
-cl-no-stdinc")
+  set( CMAKE_LLAsm_FLAGS "${CMAKE_LLAsm_FLAGS} -cl-no-stdinc" )
+  set( CMAKE_CLC_FLAGS "${CMAKE_CLC_FLAGS} -cl-no-stdinc" )
 endif()
 
 enable_language( CLC LLAsm )
@@ -142,14 +141,14 @@ set( cypress_aliases hemlock )
 set( barts_aliases turks caicos )
 set( cayman_aliases aruba )
 set( tahiti_aliases pitcairn verde oland hainan bonaire kabini kaveri hawaii
-   mullins tonga tongapro iceland carrizo fiji stoney polaris10 polaris11
-   gfx602 gfx705 gfx805
-   gfx900 gfx902 gfx904 gfx906 gfx908 gfx909 gfx90a gfx90c gfx940 gfx941 
gfx942
-   gfx1010 gfx1011 gfx1012 gfx1013
-   gfx1030 gfx1031 gfx1032 gfx1033 gfx1034 gfx1035 gfx1036
-   gfx1100 gfx1101 gfx1102 gfx1103
-   gfx1150 gfx1151
-   gfx1200 gfx1201
+  mullins tonga tongapro iceland carrizo fiji stoney polaris10 polaris11
+  gfx602 

[libclc] 37a3de1 - libclc: Fix signed integer underflow in abs_diff

2023-08-31 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2023-08-31T14:28:16+01:00
New Revision: 37a3de1e2eedf848b8442217ef3790436f69a7db

URL: 
https://github.com/llvm/llvm-project/commit/37a3de1e2eedf848b8442217ef3790436f69a7db
DIFF: 
https://github.com/llvm/llvm-project/commit/37a3de1e2eedf848b8442217ef3790436f69a7db.diff

LOG: libclc: Fix signed integer underflow in abs_diff

We noticed this same issue in our own implementation of abs_diff, and
the same issue also came up in the abs_diff reference function in the
OpenCL CTS.

Reviewed By: rjodinchr

Differential Revision: https://reviews.llvm.org/D159275

Added: 


Modified: 
libclc/generic/lib/integer/abs_diff.inc

Removed: 




diff  --git a/libclc/generic/lib/integer/abs_
diff .inc b/libclc/generic/lib/integer/abs_
diff .inc
index f39c3ff4d3e8ab..2d3c492cae0e68 100644
--- a/libclc/generic/lib/integer/abs_
diff .inc
+++ b/libclc/generic/lib/integer/abs_
diff .inc
@@ -1,3 +1,5 @@
 _CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_
diff (__CLC_GENTYPE x, __CLC_GENTYPE y) {
-  return __builtin_astype((__CLC_GENTYPE)(x > y ? x-y : y-x), __CLC_U_GENTYPE);
+  __CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
+  __CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
+  return x > y ? ux - uy : uy - ux;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7793db3 - [OpenCL] Check for extension string extension lookup

2020-11-27 Thread Fraser Cormack via cfe-commits

Author: Erik Tomusk
Date: 2020-11-27T13:16:39Z
New Revision: 7793db35ca2c1fe63687c0a7140cbec540a9aded

URL: 
https://github.com/llvm/llvm-project/commit/7793db35ca2c1fe63687c0a7140cbec540a9aded
DIFF: 
https://github.com/llvm/llvm-project/commit/7793db35ca2c1fe63687c0a7140cbec540a9aded.diff

LOG: [OpenCL] Check for extension string extension lookup

Calling any of the OpenCLOptions::is*() functions (except isKnown())
with an unknown extension string results in a seg fault. This patch
checks that the extension exists in the map before attempting to access
it.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D90928

Added: 


Modified: 
clang/include/clang/Basic/OpenCLOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLOptions.h 
b/clang/include/clang/Basic/OpenCLOptions.h
index 15661154eab5..66dd06db5b83 100644
--- a/clang/include/clang/Basic/OpenCLOptions.h
+++ b/clang/include/clang/Basic/OpenCLOptions.h
@@ -32,38 +32,71 @@ class OpenCLOptions {
   };
   llvm::StringMap OptMap;
 public:
+  /// Check if \c Ext is a recognized OpenCL extension.
+  ///
+  /// \param Ext - Extension to look up.
+  /// \returns \c true if \c Ext is known, \c false otherwise.
   bool isKnown(llvm::StringRef Ext) const {
 return OptMap.find(Ext) != OptMap.end();
   }
 
+  /// Check if \c Ext is an enabled OpenCL extension.
+  ///
+  /// \param Ext - Extension to look up.
+  /// \returns \c true if \c Ext is known and enabled, \c false otherwise.
   bool isEnabled(llvm::StringRef Ext) const {
-return OptMap.find(Ext)->second.Enabled;
+auto E = OptMap.find(Ext);
+return E != OptMap.end() && E->second.Enabled;
   }
 
-  // Is supported as either an extension or an (optional) core feature for
-  // OpenCL version \p CLVer.
+  /// Check if \c Ext is supported as either an extension or an (optional) core
+  /// feature for the given OpenCL version.
+  ///
+  /// \param Ext - Extension to look up.
+  /// \param LO - \c LangOptions specifying the OpenCL version.
+  /// \returns \c true if \c Ext is known and supported, \c false otherwise.
   bool isSupported(llvm::StringRef Ext, const LangOptions ) const {
+auto E = OptMap.find(Ext);
+if (E == OptMap.end()) {
+  return false;
+}
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
-auto I = OptMap.find(Ext)->getValue();
+auto I = E->getValue();
 return I.Supported && I.Avail <= CLVer;
   }
 
-  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
-  // For supported extension, return false.
+  /// Check if \c Ext is supported as an (optional) OpenCL core features for
+  /// the given OpenCL version.
+  ///
+  /// \param Ext - Extension to look up.
+  /// \param LO - \c LangOptions specifying the OpenCL version.
+  /// \returns \c true if \c Ext is known and supported, \c false otherwise.
   bool isSupportedCore(llvm::StringRef Ext, const LangOptions ) const {
+auto E = OptMap.find(Ext);
+if (E == OptMap.end()) {
+  return false;
+}
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
-auto I = OptMap.find(Ext)->getValue();
+auto I = E->getValue();
 return I.Supported && I.Avail <= CLVer && I.Core != ~0U && CLVer >= I.Core;
   }
 
-  // Is supported OpenCL extension for OpenCL version \p CLVer.
-  // For supported (optional) core feature, return false.
+  /// Check if \c Ext is a supported OpenCL extension for the given OpenCL
+  /// version.
+  ///
+  /// \param Ext - Extension to look up.
+  /// \param LO - \c LangOptions specifying the OpenCL version.
+  /// \returns \c true if \c Ext is known and supported, \c false otherwise.
   bool isSupportedExtension(llvm::StringRef Ext, const LangOptions ) const {
+auto E = OptMap.find(Ext);
+if (E == OptMap.end()) {
+  return false;
+}
 // In C++ mode all extensions should work at least as in v2.0.
 auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
-auto I = OptMap.find(Ext)->getValue();
+auto I = E->getValue();
 return I.Supported && I.Avail <= CLVer && (I.Core == ~0U || CLVer < 
I.Core);
   }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits