r214308 - Add OpenCL/SPIR kernel_arg_base_type metadata node

Fraser Cormack fraser at codeplay.com
Wed Jul 30 07:39:54 PDT 2014


Author: fcormack
Date: Wed Jul 30 09:39:53 2014
New Revision: 214308

URL: http://llvm.org/viewvc/llvm-project?rev=214308&view=rev
Log:
Add OpenCL/SPIR kernel_arg_base_type metadata node

As defined in the SPIR 1.2 specification, this node behaves similarly to
kernel_arg_type but will print the underlying type name, e.g., without
typedefs.

Example:
  typedef unsigned int myunsignedint;
would report:
  'myunsignedint' in the kernel_arg_type node
  'uint' in the kernel_arg_base_type node

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=214308&r1=214307&r2=214308&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Jul 30 09:39:53 2014
@@ -358,6 +358,11 @@ static void GenOpenCLArgMetadata(const F
   SmallVector<llvm::Value*, 8> argTypeNames;
   argTypeNames.push_back(llvm::MDString::get(Context, "kernel_arg_type"));
 
+  // MDNode for the kernel argument base type names.
+  SmallVector<llvm::Value*, 8> argBaseTypeNames;
+  argBaseTypeNames.push_back(
+      llvm::MDString::get(Context, "kernel_arg_base_type"));
+
   // MDNode for the kernel argument type qualifiers.
   SmallVector<llvm::Value*, 8> argTypeQuals;
   argTypeQuals.push_back(llvm::MDString::get(Context, "kernel_arg_type_qual"));
@@ -389,6 +394,18 @@ static void GenOpenCLArgMetadata(const F
 
       argTypeNames.push_back(llvm::MDString::get(Context, typeName));
 
+      std::string baseTypeName =
+          pointeeTy.getUnqualifiedType().getCanonicalType().getAsString(
+              Policy) +
+          "*";
+
+      // Turn "unsigned type" to "utype"
+      pos = baseTypeName.find("unsigned");
+      if (pos != std::string::npos)
+        baseTypeName.erase(pos+1, 8);
+
+      argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
+
       // Get argument type qualifiers:
       if (ty.isRestrictQualified())
         typeQuals = "restrict";
@@ -415,6 +432,16 @@ static void GenOpenCLArgMetadata(const F
 
       argTypeNames.push_back(llvm::MDString::get(Context, typeName));
 
+      std::string baseTypeName =
+          ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);
+
+      // Turn "unsigned type" to "utype"
+      pos = baseTypeName.find("unsigned");
+      if (pos != std::string::npos)
+        baseTypeName.erase(pos+1, 8);
+
+      argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
+
       // Get argument type qualifiers:
       if (ty.isConstQualified())
         typeQuals = "const";
@@ -442,6 +469,7 @@ static void GenOpenCLArgMetadata(const F
   kernelMDArgs.push_back(llvm::MDNode::get(Context, addressQuals));
   kernelMDArgs.push_back(llvm::MDNode::get(Context, accessQuals));
   kernelMDArgs.push_back(llvm::MDNode::get(Context, argTypeNames));
+  kernelMDArgs.push_back(llvm::MDNode::get(Context, argBaseTypeNames));
   kernelMDArgs.push_back(llvm::MDNode::get(Context, argTypeQuals));
   kernelMDArgs.push_back(llvm::MDNode::get(Context, argNames));
 }

Modified: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl?rev=214308&r1=214307&r2=214308&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl Wed Jul 30 09:39:53 2014
@@ -8,6 +8,7 @@ kernel void foo(__global int * restrict
 // CHECK: metadata !{metadata !"kernel_arg_addr_space", i32 1, i32 0, i32 0, i32 2}
 // CHECK: metadata !{metadata !"kernel_arg_access_qual", metadata !"none", metadata !"none", metadata !"none", metadata !"none"}
 // CHECK: metadata !{metadata !"kernel_arg_type", metadata !"int*", metadata !"int", metadata !"int", metadata !"float*"}
+// CHECK: metadata !{metadata !"kernel_arg_base_type", metadata !"int*", metadata !"int", metadata !"int", metadata !"float*"}
 // CHECK: metadata !{metadata !"kernel_arg_type_qual", metadata !"restrict", metadata !"const", metadata !"volatile", metadata !"restrict const"}
 // CHECK: metadata !{metadata !"kernel_arg_name", metadata !"X", metadata !"Y", metadata !"anotherArg", metadata !"Z"}
 
@@ -16,6 +17,7 @@ kernel void foo2(read_only image1d_t img
 // CHECK: metadata !{metadata !"kernel_arg_addr_space", i32 1, i32 1, i32 1}
 // CHECK: metadata !{metadata !"kernel_arg_access_qual", metadata !"read_only", metadata !"read_only", metadata !"write_only"}
 // CHECK: metadata !{metadata !"kernel_arg_type", metadata !"image1d_t", metadata !"image2d_t", metadata !"image2d_array_t"}
+// CHECK: metadata !{metadata !"kernel_arg_base_type", metadata !"image1d_t", metadata !"image2d_t", metadata !"image2d_array_t"}
 // CHECK: metadata !{metadata !"kernel_arg_type_qual", metadata !"", metadata !"", metadata !""}
 // CHECK: metadata !{metadata !"kernel_arg_name", metadata !"img1", metadata !"img2", metadata !"img3"}
 
@@ -24,6 +26,7 @@ kernel void foo3(__global half * X) {
 // CHECK: metadata !{metadata !"kernel_arg_addr_space", i32 1}
 // CHECK: metadata !{metadata !"kernel_arg_access_qual", metadata !"none"}
 // CHECK: metadata !{metadata !"kernel_arg_type", metadata !"half*"}
+// CHECK: metadata !{metadata !"kernel_arg_base_type", metadata !"half*"}
 // CHECK: metadata !{metadata !"kernel_arg_type_qual", metadata !""}
 // CHECK: metadata !{metadata !"kernel_arg_name", metadata !"X"}
 
@@ -33,5 +36,14 @@ kernel void foo4(__global unsigned int *
 // CHECK: metadata !{metadata !"kernel_arg_addr_space", i32 1, i32 1}
 // CHECK: metadata !{metadata !"kernel_arg_access_qual", metadata !"none", metadata !"none"}
 // CHECK: metadata !{metadata !"kernel_arg_type", metadata !"uint*", metadata !"myunsignedint*"}
+// CHECK: metadata !{metadata !"kernel_arg_base_type", metadata !"uint*", metadata !"uint*"}
 // CHECK: metadata !{metadata !"kernel_arg_type_qual", metadata !"", metadata !""}
 // CHECK: metadata !{metadata !"kernel_arg_name", metadata !"X", metadata !"Y"}
+
+typedef image1d_t myImage;
+kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+}
+// CHECK: metadata !{metadata !"kernel_arg_access_qual", metadata !"read_only", metadata !"write_only"}
+// CHECK: metadata !{metadata !"kernel_arg_type", metadata !"myImage", metadata !"image1d_t"}
+// CHECK: metadata !{metadata !"kernel_arg_base_type", metadata !"image1d_t", metadata !"image1d_t"}
+// CHECK: metadata !{metadata !"kernel_arg_name", metadata !"img1", metadata !"img2"}





More information about the cfe-commits mailing list