[cfe-dev] [OpenCL patch] kernel attributes implementation
Anton Lokhmotov
Anton.Lokhmotov at arm.com
Fri Jan 6 08:06:53 PST 2012
Hi Tanya and Guy,
> - Add some comments to the function EmitOpenCLKernelMetadata. Maybe one
> sentence to say what the metadata is and reference to spec.
Done.
> - Remove the type specifier diagnostic. I don't think its needed (can
> you just use the existing one?) and its unrelated to the metadata.
While I appreciate Guy's concern that:
__kernel __attribute__((vec_type_hint(mmm))) void foo( void ){}
should generate a better error message, with his code I still see three
other confusing messages:
kernel-attributes-invalid.cl:7:39: error: type name requires a specifier or
qualifier
__kernel __attribute__((vec_type_hint(mm))) void foo( void ){}
^
kernel-attributes-invalid.cl:7:39: error: OpenCL requires a type specifier
for all declarations
__kernel __attribute__((vec_type_hint(mm))) void foo( void ){}
^~~
kernel-attributes-invalid.cl:7:39: error: expected ')'
__kernel __attribute__((vec_type_hint(mm))) void foo( void ){}
^
)
kernel-attributes-invalid.cl:7:44: error: expected identifier or '('
__kernel __attribute__((vec_type_hint(mm))) void foo( void ){}
I think we should try to come up with a better solution...
> - The DummyType is a creative solution. I think we'll need Doug to sign
> off on that change though.
Please see below an excerpt from an alternative solution handling the
vec_type_hint parameter as an identifier (yuck!). Hopefully, it's enough to
convince Doug ;).
Cheers,
Anton.
+static void handleOpenCLVecTypeHint(Sema &S, Decl *D, const AttributeList
&Attr)
+{
+ if (!Attr.getParameterName()) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
+ return;
+ }
+
+ IdentifierInfo *II = Attr.getParameterName();
+
+ llvm::StringRef IIStr = II->getName();
+
+ ParsedType TypeRep =
+ S.getTypeName(*II, Attr.getLoc(),
+ S.getScopeForContext(D->getDeclContext()->getParent()));
+
+ QualType QT;
+
+ if (!TypeRep) {
+ // Try to recognise keywords
+ QT = llvm::StringSwitch<QualType>(IIStr)
+ .Case("char", S.Context.CharTy)
+ .Case("int", S.Context.IntTy)
+ .Case("short", S.Context.ShortTy)
+ .Case("long", S.Context.LongTy)
+ .Case("float", S.Context.FloatTy)
+ .Case("double", S.Context.DoubleTy)
+ .Case("half", S.Context.HalfTy)
+ .Default(QualType())
+ ;
+ if (QT.isNull()) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_argument_invalid_type) <<
II;
+ return;
+ }
+ } else QT = TypeRep.get();
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kernel_optional_attribute_qualifiers.patch
Type: application/octet-stream
Size: 19115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120106/4ab44821/attachment.obj>
More information about the cfe-dev
mailing list