llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nick Sarnie (sarnex)

<details>
<summary>Changes</summary>

SPIR-V does not allow pointer kernel arguments to be in the generic address 
space. For offload, we already coerece them to the global address space if not 
specified. 

We are seeing that we need to do the same for SPIR-V directly as some of the 
liboffload unit tests are compiled for `spirv64-intel` directly, otherwise we 
produce invalid SPIR-V.

---
Full diff: https://github.com/llvm/llvm-project/pull/185498.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+5-4) 
- (added) clang/test/CodeGenSPIRV/spirv-intel-kernel.c (+18) 


``````````diff
diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index 52d019b855dbc..88ac65b91d03e 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -146,11 +146,12 @@ void CommonSPIRABIInfo::setCCs() {
 }
 
 ABIArgInfo SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
-  if (getContext().getLangOpts().isTargetDevice()) {
+  if (getContext().getLangOpts().isTargetDevice() ||
+      getTarget().getTriple().getVendor() == llvm::Triple::Intel) {
     // Coerce pointer arguments with default address space to CrossWorkGroup
-    // pointers for target devices as default address space kernel arguments
-    // are not allowed. We use the opencl_global language address space which
-    // always maps to CrossWorkGroup.
+    // pointers for target/Intel devices as default address space kernel
+    // arguments are not allowed. We use the opencl_global language address
+    // space which always maps to CrossWorkGroup.
     llvm::Type *LTy = CGT.ConvertType(Ty);
     auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default);
     auto GlobalAS = getContext().getTargetAddressSpace(LangAS::opencl_global);
diff --git a/clang/test/CodeGenSPIRV/spirv-intel-kernel.c 
b/clang/test/CodeGenSPIRV/spirv-intel-kernel.c
new file mode 100644
index 0000000000000..f709df7af9903
--- /dev/null
+++ b/clang/test/CodeGenSPIRV/spirv-intel-kernel.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple spirv64-intel %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple spirv32-intel %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: define spir_func void @func(ptr addrspace(4) noundef %{{.*}})
+void func(int* arg) {
+}
+
+// CHECK: define spir_kernel void @kernel(ptr addrspace(1) noundef %{{.*}})
+void __attribute__((device_kernel)) kernel(int* arg) {
+// CHECK: call spir_func{{.*}} void @func(ptr addrspace(4) noundef %{{.*}})
+  func(arg);
+}
+
+// CHECK: define spir_kernel void @kernel_spec(ptr addrspace(2) noundef 
%{{.*}})
+void __attribute__((device_kernel)) 
kernel_spec(__attribute__((address_space(2))) int* arg) {
+// CHECK: call spir_func{{.*}} void @func(ptr addrspace(4) noundef %{{.*}})
+  func((int*)arg);
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/185498
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to