summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch')
-rw-r--r--dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch143
1 files changed, 143 insertions, 0 deletions
diff --git a/dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch b/dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch
new file mode 100644
index 00000000..750a0494
--- /dev/null
+++ b/dynamic-layers/clang-layer/recipes-opencl/igc/files/c707d1e2244aec988bdd5d2a7473ef3a32a5bac7.patch
@@ -0,0 +1,143 @@
1From c707d1e2244aec988bdd5d2a7473ef3a32a5bac7 Mon Sep 17 00:00:00 2001
2From: Artem Gindinson <artem.gindinson@intel.com>
3Date: Thu, 17 Nov 2022 18:51:03 +0000
4Subject: [PATCH] Disable opaque pointers in IGC stack for LLVM 15+
5
6While IGC is a long way from supporting opaque pointers, LLVM 15 has them
7enabled by default. Enforce typed pointers explicitly within all LLVM
8pipelines employed by our stack (unless CMake instructs otherwise).
9
10Upstream-Status: Backport
11Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
12---
13 IGC/BiFModule/CMakeLists.txt | 4 ++--
14 IGC/CMakeLists.txt | 4 ++++
15 IGC/Compiler/CodeGenContext.cpp | 3 +++
16 IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp | 4 ++++
17 IGC/VectorCompiler/lib/BiF/CMakeLists.txt | 4 ++--
18 IGC/cmake/igc_llvm.cmake | 24 +++++++++++++++++++++++
19 6 files changed, 39 insertions(+), 4 deletions(-)
20
21diff --git a/IGC/BiFModule/CMakeLists.txt b/IGC/BiFModule/CMakeLists.txt
22index 60fc5cf8d7d..e87288ca6da 100644
23--- a/IGC/BiFModule/CMakeLists.txt
24+++ b/IGC/BiFModule/CMakeLists.txt
25@@ -251,7 +251,7 @@ function(igc_bif_build_bc)
26 add_custom_command(
27 OUTPUT "${_bcTempFilePath}"
28 COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "${CMAKE_COMMAND}" -E make_directory "${_outBcFileDir}"
29- COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "$<TARGET_FILE:clang-tool>" -cc1 -x cl -fblocks -fpreserve-vec3-type -opencl-builtins "-triple=${_archTriple}" -w -emit-llvm-bc -o "${_bcTempFilePath}" ${_pchFlags} ${_incFileFlags} ${_includeDirsFlags} ${_defineFlags} ${_options_DEFAULT} ${_options_CL} "${_srcFilePath}"
30+ COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "$<TARGET_FILE:clang-tool>" -cc1 ${IGC_LLVM_DEPENDENT_CLANG_FLAGS} -x cl -fblocks -fpreserve-vec3-type -opencl-builtins "-triple=${_archTriple}" -w -emit-llvm-bc -o "${_bcTempFilePath}" ${_pchFlags} ${_incFileFlags} ${_includeDirsFlags} ${_defineFlags} ${_options_DEFAULT} ${_options_CL} "${_srcFilePath}"
31 DEPENDS clang-tool ${_pchFilePath} ${_incFilePaths} "${_srcFilePath}" ${_dependencies}
32 COMMENT "BiF: \"${_outBcFileName}\": Compiling OpenCL source: \"${_srcFileName}\""
33 )
34@@ -351,7 +351,7 @@ function(igc_bif_build_bc)
35 add_custom_command(
36 OUTPUT "${_bcTempFilePath}"
37 COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "${CMAKE_COMMAND}" -E make_directory "${_outBcFileDir}"
38- COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "${bif-llvm-opt_exe}" -O2 -o "${_bcTempFilePath}" ${_options_DEFAULT} ${_options_OPT} ${_bcFiles}
39+ COMMAND "${CMAKE_COMMAND}" -E compare_files ${BiFModule_PREBUILD_SHA_PATH} ${BiFModule_SRC_SHA_PATH} || "${bif-llvm-opt_exe}" -O2 -o "${_bcTempFilePath}" ${IGC_LLVM_DEPENDENT_OPT_ARGS} ${_options_DEFAULT} ${_options_OPT} ${_bcFiles}
40 DEPENDS ${_bcFiles} ${_dependencies}
41 COMMENT "BiF: \"${_outBcFileName}\": Optmizing output .bc."
42 )
43diff --git a/IGC/CMakeLists.txt b/IGC/CMakeLists.txt
44index 930a552121c..66ea2a3b5ca 100644
45--- a/IGC/CMakeLists.txt
46+++ b/IGC/CMakeLists.txt
47@@ -275,6 +275,10 @@ endif()
48 # Remove this condition after transition period is over
49 option(IGC_OPTION__USE_KHRONOS_SPIRV_TRANSLATOR_IN_SC "[Experimental] Enable usage of Khronos SPIRV-LLVM-Translator in Scalar Compiler" OFF)
50
51+# TODO: Change this flag to opt-out or remove completely once
52+# opaque pointers are fully supported within the IGC stack.
53+option(IGC_OPTION__LLVM_OPAQUE_POINTERS_ENABLED "[Experimental] Allow usage of opaque pointers within LLVM transformations" OFF)
54+
55 option(IGC_OPTION__ENABLE_LIT_TESTS "Enable lit testing for IGC compiler. May require additional tools like llvm lit and opt" OFF)
56
57 set(IGC_OPTION__BIF_SRC_OCL_DIR "${IGC_SOURCE_DIR}/BiFModule"
58diff --git a/IGC/Compiler/CodeGenContext.cpp b/IGC/Compiler/CodeGenContext.cpp
59index 4abd6e4bf4a..0058571cd27 100644
60--- a/IGC/Compiler/CodeGenContext.cpp
61+++ b/IGC/Compiler/CodeGenContext.cpp
62@@ -231,6 +231,9 @@ namespace IGC
63 {
64 CreateResourceDimensionTypes(*this);
65 }
66+#ifdef __IGC_OPAQUE_POINTERS_FORCE_DISABLED__
67+ this->setOpaquePointers(false);
68+#endif
69 }
70
71 void LLVMContextWrapper::AddRef()
72diff --git a/IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp b/IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp
73index ef0e5cacd96..c26bfcea74c 100644
74--- a/IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp
75+++ b/IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp
76@@ -1494,6 +1494,10 @@ namespace TC
77 optionsEx += " -debug-info-kind=line-tables-only -dwarf-version=4";
78 }
79
80+#ifdef __IGC_OPAQUE_POINTERS_FORCE_DISABLED__
81+ optionsEx += " -no-opaque-pointers";
82+#endif
83+
84 std::string extensionsFromInternalOptions = GetSubstring(pInternalOptions, "-cl-ext=");
85
86 std::string extensions;
87diff --git a/IGC/VectorCompiler/lib/BiF/CMakeLists.txt b/IGC/VectorCompiler/lib/BiF/CMakeLists.txt
88index 3181a13403c..6235fc1d21e 100644
89--- a/IGC/VectorCompiler/lib/BiF/CMakeLists.txt
90+++ b/IGC/VectorCompiler/lib/BiF/CMakeLists.txt
91@@ -90,7 +90,7 @@ function(vc_build_bif RES_FILE CMCL_SRC_PATH BIF_NAME PTR_BIT_SIZE)
92
93 add_custom_command(OUTPUT "${BIF_CLANG_BC_PATH}"
94 COMMAND clang-tool -cc1 ${CMCL_INCLUDES} ${VC_INCLUDES} ${UTILS_HEADERS}
95- ${EXTRA_CLANG_INCLUDES} ${EXTRA_CLANG_FLAGS}
96+ ${EXTRA_CLANG_INCLUDES} ${IGC_LLVM_DEPENDENT_CLANG_FLAGS} ${EXTRA_CLANG_FLAGS}
97 -x cl -cl-std=clc++ -triple=${SPIR_TARGET}
98 -O2 -disable-llvm-passes -emit-llvm-bc -o "${BIF_CLANG_BC_NAME}" ${CMCL_SRC}
99 COMMENT "vc_build_bif: Compiling CMCL source ${CMCL_SRC} to BC ${BIF_CLANG_BC_NAME}"
100@@ -110,7 +110,7 @@ function(vc_build_bif RES_FILE CMCL_SRC_PATH BIF_NAME PTR_BIT_SIZE)
101 COMMENT "vc_build_bif: Translating CMCL builtins: ${BIF_CLANG_BC_NAME_FINAL} -> ${BIF_CMCL_BC_NAME}"
102 DEPENDS CMCLTranslatorTool ${BIF_CLANG_BC_PATH_FINAL})
103 add_custom_command(OUTPUT ${BIF_OPT_BC_PATH}
104- COMMAND ${LLVM_OPT_EXE} --O2 -o ${BIF_OPT_BC_NAME} ${BIF_CMCL_BC_NAME}
105+ COMMAND ${LLVM_OPT_EXE} ${IGC_LLVM_DEPENDENT_OPT_FLAGS} --O2 -o ${BIF_OPT_BC_NAME} ${BIF_CMCL_BC_NAME}
106 COMMENT "vc_build_bif: running opt with O2: ${BIF_CMCL_BC_NAME} -> ${BIF_OPT_BC_NAME}"
107 DEPENDS opt ${BIF_CMCL_BC_PATH})
108 set(${RES_FILE} ${BIF_OPT_BC_NAME} PARENT_SCOPE)
109diff --git a/IGC/cmake/igc_llvm.cmake b/IGC/cmake/igc_llvm.cmake
110index c0f74dcea14..96e3b0d1117 100644
111--- a/IGC/cmake/igc_llvm.cmake
112+++ b/IGC/cmake/igc_llvm.cmake
113@@ -69,6 +69,30 @@ list(TRANSFORM LLVM_INCLUDE_DIRS PREPEND "-I=" OUTPUT_VARIABLE LLVM_TABLEGEN_FLA
114 # Add major version definition for llvm wrapper.
115 add_compile_definitions(LLVM_VERSION_MAJOR=${LLVM_VERSION_MAJOR})
116
117+set(IGC_LLVM_DEPENDENT_CLANG_FLAGS "")
118+set(IGC_LLVM_DEPENDENT_OPT_FLAGS "")
119+
120+# Disable the opaque pointers' usage explicitly, unless the block below deems that unnecessary
121+set(IGC_OPAQUE_POINTERS_FORCE_DISABLED ON)
122+if(IGC_OPTION__LLVM_OPAQUE_POINTERS_ENABLED)
123+ if(LLVM_VERSION_MAJOR LESS 14)
124+ message(WARNING "IGC_OPTION__LLVM_OPAQUE_POINTERS_ENABLED ignored: opaque pointers are not available prior to LLVM 14")
125+ endif()
126+ set(IGC_OPAQUE_POINTERS_FORCE_DISABLED OFF)
127+elseif(LLVM_VERSION_MAJOR LESS 15)
128+ # Opaque pointers are either absent (LLVM <14) or disabled by default. No need to force-disable
129+ set(IGC_OPAQUE_POINTERS_FORCE_DISABLED OFF)
130+endif(IGC_OPTION__LLVM_OPAQUE_POINTERS_ENABLED)
131+
132+if(IGC_OPAQUE_POINTERS_FORCE_DISABLED)
133+ # Once we've figured out that explicit disabling is needed, propagate
134+ # corresponding options to all the in-tree calls of clang/opt tools.
135+ list(APPEND IGC_LLVM_DEPENDENT_CLANG_FLAGS "-no-opaque-pointers")
136+ list(APPEND IGC_LLVM_DEPENDENT_OPT_FLAGS "-opaque-pointers=0")
137+ # Also inform the preprocessor.
138+ add_compile_definitions(__IGC_OPAQUE_POINTERS_FORCE_DISABLED__)
139+endif()
140+
141 # Include LLVM headers as system ones.
142 # This will disable warnings on linux.
143 include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})