diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1475,6 +1475,37 @@ QualType ty = parm->getType(); std::string typeQuals; + // Get image and pipe access qualifier: + if (ty->isImageType() || ty->isPipeType()) { + const Decl *PDecl = parm; + if (auto *TD = dyn_cast(ty)) + PDecl = TD->getDecl(); + const OpenCLAccessAttr *A = PDecl->getAttr(); + if (A && A->isWriteOnly()) + accessQuals.push_back(llvm::MDString::get(VMContext, "write_only")); + else if (A && A->isReadWrite()) + accessQuals.push_back(llvm::MDString::get(VMContext, "read_write")); + else + accessQuals.push_back(llvm::MDString::get(VMContext, "read_only")); + } else + accessQuals.push_back(llvm::MDString::get(VMContext, "none")); + + // Get argument name. + argNames.push_back(llvm::MDString::get(VMContext, parm->getName())); + + auto getTypeSpelling = [&](QualType Ty) { + auto typeName = Ty.getUnqualifiedType().getAsString(Policy); + + if (Ty.isCanonical()) { + StringRef typeNameRef = typeName; + // Turn "unsigned type" to "utype" + if (typeNameRef.consume_front("unsigned ")) + return std::string("u") + typeNameRef.str(); + } + + return typeName; + }; + if (ty->isPointerType()) { QualType pointeeTy = ty->getPointeeType(); @@ -1484,26 +1515,10 @@ ArgInfoAddressSpace(pointeeTy.getAddressSpace())))); // Get argument type name. - std::string typeName = - pointeeTy.getUnqualifiedType().getAsString(Policy) + "*"; - - // Turn "unsigned type" to "utype" - std::string::size_type pos = typeName.find("unsigned"); - if (pointeeTy.isCanonical() && pos != std::string::npos) - typeName.erase(pos + 1, 8); - - argTypeNames.push_back(llvm::MDString::get(VMContext, typeName)); - + std::string typeName = getTypeSpelling(pointeeTy) + "*"; 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); - + getTypeSpelling(pointeeTy.getCanonicalType()) + "*"; + argTypeNames.push_back(llvm::MDString::get(VMContext, typeName)); argBaseTypeNames.push_back( llvm::MDString::get(VMContext, baseTypeName)); @@ -1525,30 +1540,9 @@ llvm::ConstantAsMetadata::get(CGF->Builder.getInt32(AddrSpc))); // Get argument type name. - std::string typeName; - if (isPipe) - typeName = ty.getCanonicalType() - ->castAs() - ->getElementType() - .getAsString(Policy); - else - typeName = ty.getUnqualifiedType().getAsString(Policy); - - // Turn "unsigned type" to "utype" - std::string::size_type pos = typeName.find("unsigned"); - if (ty.isCanonical() && pos != std::string::npos) - typeName.erase(pos + 1, 8); - - std::string baseTypeName; - if (isPipe) - baseTypeName = ty.getCanonicalType() - ->castAs() - ->getElementType() - .getCanonicalType() - .getAsString(Policy); - else - baseTypeName = - ty.getUnqualifiedType().getCanonicalType().getAsString(Policy); + ty = isPipe ? ty->castAs()->getElementType() : ty; + std::string typeName = getTypeSpelling(ty); + std::string baseTypeName = getTypeSpelling(ty.getCanonicalType()); // Remove access qualifiers on images // (as they are inseparable from type in clang implementation, @@ -1560,38 +1554,13 @@ } argTypeNames.push_back(llvm::MDString::get(VMContext, typeName)); - - // 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(VMContext, baseTypeName)); if (isPipe) typeQuals = "pipe"; } - argTypeQuals.push_back(llvm::MDString::get(VMContext, typeQuals)); - - // Get image and pipe access qualifier: - if (ty->isImageType() || ty->isPipeType()) { - const Decl *PDecl = parm; - if (auto *TD = dyn_cast(ty)) - PDecl = TD->getDecl(); - const OpenCLAccessAttr *A = PDecl->getAttr(); - if (A && A->isWriteOnly()) - accessQuals.push_back(llvm::MDString::get(VMContext, "write_only")); - else if (A && A->isReadWrite()) - accessQuals.push_back(llvm::MDString::get(VMContext, "read_write")); - else - accessQuals.push_back(llvm::MDString::get(VMContext, "read_only")); - } else - accessQuals.push_back(llvm::MDString::get(VMContext, "none")); - - // Get argument name. - argNames.push_back(llvm::MDString::get(VMContext, parm->getName())); } Fn->setMetadata("kernel_arg_addr_space", diff --git a/clang/test/CodeGenOpenCL/kernel-arg-info.cl b/clang/test/CodeGenOpenCL/kernel-arg-info.cl --- a/clang/test/CodeGenOpenCL/kernel-arg-info.cl +++ b/clang/test/CodeGenOpenCL/kernel-arg-info.cl @@ -85,6 +85,7 @@ typedef read_write image1d_t RWImage; kernel void foo7(ROImage ro, WOImage wo, RWImage rw) { } + // CHECK: define{{.*}} spir_kernel void @foo7{{[^!]+}} // CHECK: !kernel_arg_addr_space ![[MD71:[0-9]+]] // CHECK: !kernel_arg_access_qual ![[MD72:[0-9]+]] @@ -94,6 +95,18 @@ // CHECK-NOT: !kernel_arg_name // ARGINFO: !kernel_arg_name ![[MD76:[0-9]+]] +typedef unsigned char uchar; +typedef uchar uchar2 __attribute__((ext_vector_type(2))); +kernel void foo8(pipe int p1, pipe uchar p2, pipe uchar2 p3, const pipe uchar p4, write_only pipe uchar p5) {} +// CHECK: define{{.*}} spir_kernel void @foo8{{[^!]+}} +// CHECK: !kernel_arg_addr_space ![[PIPE_AS_QUAL:[0-9]+]] +// CHECK: !kernel_arg_access_qual ![[PIPE_ACCESS_QUAL:[0-9]+]] +// CHECK: !kernel_arg_type ![[PIPE_TY:[0-9]+]] +// CHECK: !kernel_arg_base_type ![[PIPE_BASE_TY:[0-9]+]] +// CHECK: !kernel_arg_type_qual ![[PIPE_QUAL:[0-9]+]] +// CHECK-NOT: !kernel_arg_name +// ARGINFO: !kernel_arg_name ![[PIPE_ARG_NAMES:[0-9]+]] + // CHECK: ![[MD11]] = !{i32 1, i32 1, i32 1, i32 1, i32 2, i32 2, i32 1, i32 1, i32 1, i32 1, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 0, i32 0, i32 0, i32 0} // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none"} // CHECK: ![[MD13]] = !{!"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int", !"int", !"int", !"int"} @@ -127,4 +140,9 @@ // CHECK: ![[MD74]] = !{!"image1d_t", !"image1d_t", !"image1d_t"} // CHECK: ![[MD75]] = !{!"", !"", !""} // ARGINFO: ![[MD76]] = !{!"ro", !"wo", !"rw"} - +// CHECK: ![[PIPE_AS_QUAL]] = !{i32 1, i32 1, i32 1, i32 1, i32 1} +// CHECK: ![[PIPE_ACCESS_QUAL]] = !{!"read_only", !"read_only", !"read_only", !"read_only", !"write_only"} +// CHECK: ![[PIPE_TY]] = !{!"int", !"uchar", !"uchar2", !"uchar", !"uchar"} +// CHECK: ![[PIPE_BASE_TY]] = !{!"int", !"uchar", !"uchar __attribute__((ext_vector_type(2)))", !"uchar", !"uchar"} +// CHECK: ![[PIPE_QUAL]] = !{!"pipe", !"pipe", !"pipe", !"pipe", !"pipe"} +// ARGINFO: ![[PIPE_ARG_NAMES]] = !{!"p1", !"p2", !"p3", !"p4", !"p5"}