[llvm-branch-commits] [cfe-branch] r287239 - Merge 286819 and 286821: [OpenCL] always use SPIR address spaces for kernel_arg_addr_space MD

Pekka Jaaskelainen via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 17 09:30:57 PST 2016


Author: pjaaskel
Date: Thu Nov 17 11:30:56 2016
New Revision: 287239

URL: http://llvm.org/viewvc/llvm-project?rev=287239&view=rev
Log:
Merge 286819 and 286821: [OpenCL] always use SPIR address spaces for kernel_arg_addr_space MD

Added:
    cfe/branches/release_39/test/CodeGenOpenCL/kernel-arg-info-single-as.cl
Modified:
    cfe/branches/release_39/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/branches/release_39/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/CodeGen/CodeGenFunction.cpp?rev=287239&r1=287238&r2=287239&view=diff
==============================================================================
--- cfe/branches/release_39/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/branches/release_39/lib/CodeGen/CodeGenFunction.cpp Thu Nov 17 11:30:56 2016
@@ -436,6 +436,23 @@ void CodeGenFunction::EmitMCountInstrume
   EmitNounwindRuntimeCall(MCountFn);
 }
 
+// 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.
@@ -476,7 +493,7 @@ static void GenOpenCLArgMetadata(const F
 
       // 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 =
@@ -513,8 +530,7 @@ static void GenOpenCLArgMetadata(const F
       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)));

Added: cfe/branches/release_39/test/CodeGenOpenCL/kernel-arg-info-single-as.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/CodeGenOpenCL/kernel-arg-info-single-as.cl?rev=287239&view=auto
==============================================================================
--- cfe/branches/release_39/test/CodeGenOpenCL/kernel-arg-info-single-as.cl (added)
+++ cfe/branches/release_39/test/CodeGenOpenCL/kernel-arg-info-single-as.cl Thu Nov 17 11:30:56 2016
@@ -0,0 +1,9 @@
+// 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}




More information about the llvm-branch-commits mailing list