Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -428,6 +428,26 @@ EmitNounwindRuntimeCall(F, args); } +static void removeImageAccessQualifier(std::string& TyName) { + std::string ReadOnlyQual("__read_only"); + std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual); + if (ReadOnlyPos != std::string::npos) + // "+ 1" for the space after access qualifier. + TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1); + else { + std::string WriteOnlyQual("__write_only"); + std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual); + if (WriteOnlyPos != std::string::npos) + TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1); + else { + std::string ReadWriteQual("__read_write"); + std::string::size_type ReadWritePos = TyName.find(ReadWriteQual); + if (ReadWritePos != std::string::npos) + TyName.erase(ReadWritePos, ReadWriteQual.size() + 1); + } + } +} + // 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. @@ -524,8 +544,6 @@ if (ty.isCanonical() && pos != std::string::npos) typeName.erase(pos+1, 8); - argTypeNames.push_back(llvm::MDString::get(Context, typeName)); - std::string baseTypeName; if (isPipe) baseTypeName = ty.getCanonicalType()->getAs() @@ -535,6 +553,17 @@ baseTypeName = ty.getUnqualifiedType().getCanonicalType().getAsString(Policy); + // Remove access qualifiers on images + // (as they are inseparable from type in clang implementation, + // but OpenCL spec provides a special query to get access qualifier + // via clGetKernelArgInfo with CL_KERNEL_ARG_ACCESS_QUALIFIER): + if (ty->isImageType()) { + removeImageAccessQualifier(typeName); + removeImageAccessQualifier(baseTypeName); + } + + argTypeNames.push_back(llvm::MDString::get(Context, typeName)); + // Turn "unsigned type" to "utype" pos = baseTypeName.find("unsigned"); if (pos != std::string::npos) Index: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl =================================================================== --- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl +++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s -// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO +// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s +// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO kernel void foo(__global int * restrict X, const int Y, volatile int anotherArg, __constant float * restrict Z) { @@ -14,7 +14,7 @@ // CHECK-NOT: !kernel_arg_name // ARGINFO: !kernel_arg_name ![[MD15:[0-9]+]] -kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3) { +kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3, read_write image1d_t img4) { } // CHECK: define spir_kernel void @foo2{{[^!]+}} // CHECK: !kernel_arg_addr_space ![[MD21:[0-9]+]] @@ -65,11 +65,11 @@ // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*"} // CHECK: ![[MD14]] = !{!"restrict", !"const", !"volatile", !"restrict const"} // ARGINFO: ![[MD15]] = !{!"X", !"Y", !"anotherArg", !"Z"} -// CHECK: ![[MD21]] = !{i32 1, i32 1, i32 1} -// CHECK: ![[MD22]] = !{!"read_only", !"read_only", !"write_only"} -// CHECK: ![[MD23]] = !{!"__read_only image1d_t", !"__read_only image2d_t", !"__write_only image2d_array_t"} -// CHECK: ![[MD24]] = !{!"", !"", !""} -// ARGINFO: ![[MD25]] = !{!"img1", !"img2", !"img3"} +// CHECK: ![[MD21]] = !{i32 1, i32 1, i32 1, i32 1} +// CHECK: ![[MD22]] = !{!"read_only", !"read_only", !"write_only", !"read_write"} +// CHECK: ![[MD23]] = !{!"image1d_t", !"image2d_t", !"image2d_array_t", !"image1d_t"} +// CHECK: ![[MD24]] = !{!"", !"", !"", !""} +// ARGINFO: ![[MD25]] = !{!"img1", !"img2", !"img3", !"img4"} // CHECK: ![[MD31]] = !{i32 1} // CHECK: ![[MD32]] = !{!"none"} // CHECK: ![[MD33]] = !{!"half*"} @@ -82,7 +82,7 @@ // CHECK: ![[MD45]] = !{!"", !""} // ARGINFO: ![[MD46]] = !{!"X", !"Y"} // CHECK: ![[MD51]] = !{!"read_only", !"write_only"} -// CHECK: ![[MD52]] = !{!"myImage", !"__write_only image1d_t"} -// CHECK: ![[MD53]] = !{!"__read_only image1d_t", !"__write_only image1d_t"} +// CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"} +// CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"} // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}