This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter
ClosedPublic

Authored by svenvh on Feb 21 2022, 10:00 AM.

Details

Summary

Until now, any types that had TypeExtensions attached to them were not
guarded with those extensions. Extend the OpenCLBuiltinFileEmitter
such that all required extensions are emitted for the types of a
builtin function.

The clang-tblgen -gen-clang-opencl-builtin-tests emitter will now
produce e.g.:

#if defined(cl_khr_fp16) && defined(cl_khr_fp64)
half8 test11802_convert_half8_rtp(double8 arg1) {
  return convert_half8_rtp(arg1);
}
#endif // TypeExtension

Diff Detail

Event Timeline

svenvh created this revision.Feb 21 2022, 10:00 AM
svenvh requested review of this revision.Feb 21 2022, 10:00 AM
arkangath added inline comments.
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
296–306

Shouldn't what the return value means be documented here?

1191–1192

Seems to me that this is the only assignment to the OptionalEndif variable. In which case, can't it be a StringRef ? And the return of the function be StringRef too ?

svenvh updated this revision to Diff 410822.Feb 23 2022, 7:33 AM

Use StringRef and extend comment.

svenvh marked 2 inline comments as done.Feb 23 2022, 7:34 AM
svenvh added inline comments.
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
296–306

Good catch, added.

1191–1192

Indeed; updated.

arkangath added inline comments.Feb 23 2022, 7:55 AM
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
1174

Just in case if relevant, your "KeepEmpty" will default to true here.
I don't know if it is possible or not (not enough context for me), but could the .td file have "Extension0 Extention1" (two spaces) that could lead to one empty StringRef here?

1182

Arguably it _may_ be better to early-return here instead of increasing the indentation, but I'm not asking for a change; just suggesting.
The assigned values into OptionalEndif could be just returned directly rather than storing in a local variable, unless you're predicting further changes to this function benefit from this temporary existing.

svenvh marked 2 inline comments as done.Feb 23 2022, 9:00 AM
svenvh added inline comments.
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
1174

That would lead to generation of #if defined(Extension0) && defined(), which would cause a compilation error. I think that's not unreasonable behavior to keep, to enforce that extensions are separated by exactly one space in the .td file for the sake of consistency.

1182

You are right, that would align better with the style of emitExtensionGuard too; I'll apply your suggestion prior to committing.

arkangath added inline comments.Feb 23 2022, 9:23 AM
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
1174

Ok, that's fine with me. I just wondered if it'd be easier to just set KeepEmpty=false on the split() call.

arkangath accepted this revision.Feb 24 2022, 1:54 AM
This revision is now accepted and ready to land.Feb 24 2022, 1:54 AM
This revision was landed with ongoing or failed builds.Feb 24 2022, 7:18 AM
This revision was automatically updated to reflect the committed changes.