summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>2016-11-14 13:08:30 +0000
committerPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>2016-11-14 13:08:30 +0000
commit2a1cc587bf7753b4eeb5dc295674aeb61f74fb86 (patch)
treeda92ab5c59660e6aec6c91832201aa89ab5844d6
parent6a051ba61498863fa41d4a85db8c18fa5e5f032a (diff)
downloadbcm5719-llvm-2a1cc587bf7753b4eeb5dc295674aeb61f74fb86.tar.gz
bcm5719-llvm-2a1cc587bf7753b4eeb5dc295674aeb61f74fb86.zip
[OpenCL] always use SPIR address spaces for kernel_arg_addr_space MD
It doesn't make sense to use the target's address space ids in this context as this is metadata that should be referring to the "logical" OpenCL address spaces. For flat AS machines like all "CPUs" in general, the logical AS info gets lost as there's only one address space (0). This commit changes the logic such that we always use the SPIR address space ids for the argument metadata. It thus allows implementing the clGetKernelArgInfo() and the other detection needs. https://reviews.llvm.org/D26157 llvm-svn: 286819
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp22
-rw-r--r--clang/test/CodeGenOpenCL/kernel-arg-info-single-as.cl27
2 files changed, 46 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index b2243bcea1e..1507e8e073f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -466,6 +466,23 @@ static void removeImageAccessQualifier(std::string& TyName) {
}
}
+// Returns the address space id that should be produced to the
+// kernel_arg_addr_space metadata. This is always fixed to the ids
+// as specified in the SPIR 2.0 specification in order to differentiate
+// for example in clGetKernelArgInfo() implementation between the address
+// spaces with targets without unique mapping to the OpenCL address spaces
+// (basically all single AS CPUs).
+static unsigned ArgInfoAddressSpace(unsigned LangAS) {
+ switch (LangAS) {
+ case LangAS::opencl_global: return 1;
+ case LangAS::opencl_constant: return 2;
+ case LangAS::opencl_local: return 3;
+ case LangAS::opencl_generic: return 4; // Not in SPIR 2.0 specs.
+ default:
+ return 0; // Assume private.
+ }
+}
+
// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
// information in the program executable. The argument information stored
// includes the argument name, its type, the address and access qualifiers used.
@@ -506,7 +523,7 @@ static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn,
// Get address qualifier.
addressQuals.push_back(llvm::ConstantAsMetadata::get(Builder.getInt32(
- ASTCtx.getTargetAddressSpace(pointeeTy.getAddressSpace()))));
+ ArgInfoAddressSpace(pointeeTy.getAddressSpace()))));
// Get argument type name.
std::string typeName =
@@ -543,8 +560,7 @@ static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn,
uint32_t AddrSpc = 0;
bool isPipe = ty->isPipeType();
if (ty->isImageType() || isPipe)
- AddrSpc =
- CGM.getContext().getTargetAddressSpace(LangAS::opencl_global);
+ AddrSpc = ArgInfoAddressSpace(LangAS::opencl_global);
addressQuals.push_back(
llvm::ConstantAsMetadata::get(Builder.getInt32(AddrSpc)));
diff --git a/clang/test/CodeGenOpenCL/kernel-arg-info-single-as.cl b/clang/test/CodeGenOpenCL/kernel-arg-info-single-as.cl
new file mode 100644
index 00000000000..34800dc8029
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/kernel-arg-info-single-as.cl
@@ -0,0 +1,27 @@
+// Test that the kernel argument info always refers to SPIR address spaces,
+// even if the target has only one address space like x86_64 does.
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple x86_64-unknown-unknown -cl-kernel-arg-info | FileCheck %s
+
+kernel void foo(__global int * G, __constant int *C, __local int *L) {
+ *G = *C + *L;
+}
+// CHECK: !kernel_arg_addr_space ![[MD123:[0-9]+]]
+// CHECK: ![[MD123]] = !{i32 1, i32 2, i32 3}
+// Test that the kernel argument info always refers to SPIR address spaces,
+// even if the target has only one address space like x86_64 does.
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple x86_64-unknown-unknown -cl-kernel-arg-info | FileCheck %s
+
+kernel void foo(__global int * G, __constant int *C, __local int *L) {
+ *G = *C + *L;
+}
+// CHECK: !kernel_arg_addr_space ![[MD123:[0-9]+]]
+// CHECK: ![[MD123]] = !{i32 1, i32 2, i32 3}
+// Test that the kernel argument info always refers to SPIR address spaces,
+// even if the target has only one address space like x86_64 does.
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple x86_64-unknown-unknown -cl-kernel-arg-info | FileCheck %s
+
+kernel void foo(__global int * G, __constant int *C, __local int *L) {
+ *G = *C + *L;
+}
+// CHECK: !kernel_arg_addr_space ![[MD123:[0-9]+]]
+// CHECK: ![[MD123]] = !{i32 1, i32 2, i32 3}
OpenPOWER on IntegriCloud