Skip to content

Commit 87f982f

Browse files
author
Jenkins
committed
SWDEV-179954 - OpenCL/LC - Merge branch amd-master into amd-common
Change-Id: I8e9da63ae446b153bcdc8439a8142cf75e02a4b7
2 parents 13e299c + 62bdfd8 commit 87f982f

File tree

118 files changed

+6155
-1203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+6155
-1203
lines changed

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,31 @@ option(LLVM_ENABLE_THREADS "Use threads if available." ON)
377377

378378
option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
379379

380+
set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
381+
382+
find_package(Z3 4.7.1)
383+
384+
if (LLVM_Z3_INSTALL_DIR)
385+
if (NOT Z3_FOUND)
386+
message(FATAL_ERROR "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
387+
endif()
388+
endif()
389+
390+
set(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}")
391+
392+
option(LLVM_ENABLE_Z3_SOLVER
393+
"Enable Support for the Z3 constraint solver in LLVM."
394+
${LLVM_ENABLE_Z3_SOLVER_DEFAULT}
395+
)
396+
397+
if (LLVM_ENABLE_Z3_SOLVER)
398+
if (NOT Z3_FOUND)
399+
message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.")
400+
endif()
401+
402+
set(LLVM_WITH_Z3 1)
403+
endif()
404+
380405
if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
381406
set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
382407
endif()

cmake/modules/FindZ3.cmake

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
INCLUDE(CheckCXXSourceRuns)
2+
3+
# Function to check Z3's version
4+
function(check_z3_version z3_include z3_lib)
5+
# The program that will be executed to print Z3's version.
6+
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.c
7+
"#include <assert.h>
8+
#include <z3.h>
9+
int main() {
10+
unsigned int major, minor, build, rev;
11+
Z3_get_version(&major, &minor, &build, &rev);
12+
printf(\"%u.%u.%u\", major, minor, build);
13+
return 0;
14+
}")
15+
16+
# Get lib path
17+
get_filename_component(z3_lib_path ${z3_lib} PATH)
18+
19+
try_run(
20+
Z3_RETURNCODE
21+
Z3_COMPILED
22+
${CMAKE_BINARY_DIR}
23+
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.c
24+
COMPILE_DEFINITIONS -I"${z3_include}"
25+
LINK_LIBRARIES -L${z3_lib_path} -lz3
26+
RUN_OUTPUT_VARIABLE SRC_OUTPUT
27+
)
28+
29+
if(Z3_COMPILED)
30+
string(REGEX REPLACE "([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*)" "\\1"
31+
z3_version "${SRC_OUTPUT}")
32+
set(Z3_VERSION_STRING ${z3_version} PARENT_SCOPE)
33+
endif()
34+
endfunction(check_z3_version)
35+
36+
# Looking for Z3 in LLVM_Z3_INSTALL_DIR
37+
find_path(Z3_INCLUDE_DIR NAMES z3.h
38+
NO_DEFAULT_PATH
39+
PATHS ${LLVM_Z3_INSTALL_DIR}/include
40+
PATH_SUFFIXES libz3 z3
41+
)
42+
43+
find_library(Z3_LIBRARIES NAMES z3 libz3
44+
NO_DEFAULT_PATH
45+
PATHS ${LLVM_Z3_INSTALL_DIR}
46+
PATH_SUFFIXES lib bin
47+
)
48+
49+
# If Z3 has not been found in LLVM_Z3_INSTALL_DIR look in the default directories
50+
find_path(Z3_INCLUDE_DIR NAMES z3.h
51+
PATH_SUFFIXES libz3 z3
52+
)
53+
54+
find_library(Z3_LIBRARIES NAMES z3 libz3
55+
PATH_SUFFIXES lib bin
56+
)
57+
58+
# Searching for the version of the Z3 library is a best-effort task
59+
unset(Z3_VERSION_STRING)
60+
61+
# First, try to check it dynamically, by compiling a small program that
62+
# prints Z3's version
63+
if(Z3_INCLUDE_DIR AND Z3_LIBRARIES)
64+
# We do not have the Z3 binary to query for a version. Try to use
65+
# a small C++ program to detect it via the Z3_get_version() API call.
66+
check_z3_version(${Z3_INCLUDE_DIR} ${Z3_LIBRARIES})
67+
endif()
68+
69+
# If the dynamic check fails, we might be cross compiling: if that's the case,
70+
# check the version in the headers, otherwise, fail with a message
71+
if(NOT Z3_VERSION_STRING AND (CMAKE_CROSSCOMPILING AND
72+
Z3_INCLUDE_DIR AND
73+
EXISTS "${Z3_INCLUDE_DIR}/z3_version.h"))
74+
# TODO: print message warning that we couldn't find a compatible lib?
75+
76+
# Z3 4.8.1+ has the version is in a public header.
77+
file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
78+
z3_version_str REGEX "^#define[\t ]+Z3_MAJOR_VERSION[\t ]+.*")
79+
string(REGEX REPLACE "^.*Z3_MAJOR_VERSION[\t ]+([0-9]).*$" "\\1"
80+
Z3_MAJOR "${z3_version_str}")
81+
82+
file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
83+
z3_version_str REGEX "^#define[\t ]+Z3_MINOR_VERSION[\t ]+.*")
84+
string(REGEX REPLACE "^.*Z3_MINOR_VERSION[\t ]+([0-9]).*$" "\\1"
85+
Z3_MINOR "${z3_version_str}")
86+
87+
file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
88+
z3_version_str REGEX "^#define[\t ]+Z3_BUILD_NUMBER[\t ]+.*")
89+
string(REGEX REPLACE "^.*Z3_BUILD_VERSION[\t ]+([0-9]).*$" "\\1"
90+
Z3_BUILD "${z3_version_str}")
91+
92+
set(Z3_VERSION_STRING ${Z3_MAJOR}.${Z3_MINOR}.${Z3_BUILD})
93+
unset(z3_version_str)
94+
endif()
95+
96+
if(NOT Z3_VERSION_STRING)
97+
# Give up: we are unable to obtain a version of the Z3 library. Be
98+
# conservative and force the found version to 0.0.0 to make version
99+
# checks always fail.
100+
set(Z3_VERSION_STRING "0.0.0")
101+
endif()
102+
103+
# handle the QUIETLY and REQUIRED arguments and set Z3_FOUND to TRUE if
104+
# all listed variables are TRUE
105+
include(FindPackageHandleStandardArgs)
106+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Z3
107+
REQUIRED_VARS Z3_LIBRARIES Z3_INCLUDE_DIR
108+
VERSION_VAR Z3_VERSION_STRING)
109+
110+
mark_as_advanced(Z3_INCLUDE_DIR Z3_LIBRARIES)

cmake/modules/LLVMConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@)
4444

4545
set(LLVM_LIBXML2_ENABLED @LLVM_LIBXML2_ENABLED@)
4646

47+
set(LLVM_WITH_Z3 @LLVM_WITH_Z3@)
48+
4749
set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@)
4850

4951
set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)

docs/AMDGPUUsage.rst

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -323,62 +323,80 @@ is conservatively correct for OpenCL.
323323
.. table:: AMDHSA LLVM Sync Scopes
324324
:name: amdgpu-amdhsa-llvm-sync-scopes-table
325325

326-
================ ==========================================================
327-
LLVM Sync Scope Description
328-
================ ==========================================================
329-
*none* The default: ``system``.
330-
331-
Synchronizes with, and participates in modification and
332-
seq_cst total orderings with, other operations (except
333-
image operations) for all address spaces (except private,
334-
or generic that accesses private) provided the other
335-
operation's sync scope is:
336-
337-
- ``system``.
338-
- ``agent`` and executed by a thread on the same agent.
339-
- ``workgroup`` and executed by a thread in the same
340-
workgroup.
341-
- ``wavefront`` and executed by a thread in the same
342-
wavefront.
343-
344-
``agent`` Synchronizes with, and participates in modification and
345-
seq_cst total orderings with, other operations (except
346-
image operations) for all address spaces (except private,
347-
or generic that accesses private) provided the other
348-
operation's sync scope is:
349-
350-
- ``system`` or ``agent`` and executed by a thread on the
351-
same agent.
352-
- ``workgroup`` and executed by a thread in the same
353-
workgroup.
354-
- ``wavefront`` and executed by a thread in the same
355-
wavefront.
356-
357-
``workgroup`` Synchronizes with, and participates in modification and
358-
seq_cst total orderings with, other operations (except
359-
image operations) for all address spaces (except private,
360-
or generic that accesses private) provided the other
361-
operation's sync scope is:
362-
363-
- ``system``, ``agent`` or ``workgroup`` and executed by a
364-
thread in the same workgroup.
365-
- ``wavefront`` and executed by a thread in the same
366-
wavefront.
367-
368-
``wavefront`` Synchronizes with, and participates in modification and
369-
seq_cst total orderings with, other operations (except
370-
image operations) for all address spaces (except private,
371-
or generic that accesses private) provided the other
372-
operation's sync scope is:
373-
374-
- ``system``, ``agent``, ``workgroup`` or ``wavefront``
375-
and executed by a thread in the same wavefront.
376-
377-
``singlethread`` Only synchronizes with, and participates in modification
378-
and seq_cst total orderings with, other operations (except
379-
image operations) running in the same thread for all
380-
address spaces (for example, in signal handlers).
381-
================ ==========================================================
326+
======================= ===================================================
327+
LLVM Sync Scope Description
328+
======================= ===================================================
329+
*none* The default: ``system``.
330+
331+
Synchronizes with, and participates in modification
332+
and seq_cst total orderings with, other operations
333+
(except image operations) for all address spaces
334+
(except private, or generic that accesses private)
335+
provided the other operation's sync scope is:
336+
337+
- ``system``.
338+
- ``agent`` and executed by a thread on the same
339+
agent.
340+
- ``workgroup`` and executed by a thread in the
341+
same workgroup.
342+
- ``wavefront`` and executed by a thread in the
343+
same wavefront.
344+
345+
``agent`` Synchronizes with, and participates in modification
346+
and seq_cst total orderings with, other operations
347+
(except image operations) for all address spaces
348+
(except private, or generic that accesses private)
349+
provided the other operation's sync scope is:
350+
351+
- ``system`` or ``agent`` and executed by a thread
352+
on the same agent.
353+
- ``workgroup`` and executed by a thread in the
354+
same workgroup.
355+
- ``wavefront`` and executed by a thread in the
356+
same wavefront.
357+
358+
``workgroup`` Synchronizes with, and participates in modification
359+
and seq_cst total orderings with, other operations
360+
(except image operations) for all address spaces
361+
(except private, or generic that accesses private)
362+
provided the other operation's sync scope is:
363+
364+
- ``system``, ``agent`` or ``workgroup`` and
365+
executed by a thread in the same workgroup.
366+
- ``wavefront`` and executed by a thread in the
367+
same wavefront.
368+
369+
``wavefront`` Synchronizes with, and participates in modification
370+
and seq_cst total orderings with, other operations
371+
(except image operations) for all address spaces
372+
(except private, or generic that accesses private)
373+
provided the other operation's sync scope is:
374+
375+
- ``system``, ``agent``, ``workgroup`` or
376+
``wavefront`` and executed by a thread in the
377+
same wavefront.
378+
379+
``singlethread`` Only synchronizes with, and participates in
380+
modification and seq_cst total orderings with,
381+
other operations (except image operations) running
382+
in the same thread for all address spaces (for
383+
example, in signal handlers).
384+
385+
``one-as`` Same as ``system`` but only synchronizes with other
386+
operations within the same address space.
387+
388+
``agent-one-as`` Same as ``agent`` but only synchronizes with other
389+
operations within the same address space.
390+
391+
``workgroup-one-as`` Same as ``workgroup`` but only synchronizes with
392+
other operations within the same address space.
393+
394+
``wavefront-one-as`` Same as ``wavefront`` but only synchronizes with
395+
other operations within the same address space.
396+
397+
``singlethread-one-as`` Same as ``singlethread`` but only synchronizes with
398+
other operations within the same address space.
399+
======================= ===================================================
382400

383401
AMDGPU Intrinsics
384402
-----------------

include/llvm-c/Core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,13 @@ LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
24022402
*/
24032403
void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
24042404

2405+
/**
2406+
* Obtain the intrinsic ID number which matches the given function name.
2407+
*
2408+
* @see llvm::Function::lookupIntrinsicID()
2409+
*/
2410+
unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
2411+
24052412
/**
24062413
* Obtain the ID number from a function instance.
24072414
*

include/llvm/Config/config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@
344344
/* Whether GlobalISel rule coverage is being collected */
345345
#cmakedefine01 LLVM_GISEL_COV_ENABLED
346346

347+
/* Define if we have z3 and want to build it */
348+
#cmakedefine LLVM_WITH_Z3 ${LLVM_WITH_Z3}
349+
347350
/* Define to the default GlobalISel coverage file prefix */
348351
#cmakedefine LLVM_GISEL_COV_PREFIX "${LLVM_GISEL_COV_PREFIX}"
349352

0 commit comments

Comments
 (0)