[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 23 10:37:19 PDT 2025
================
@@ -12937,6 +12937,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (D->hasAttr<WeakRefAttr>())
return false;
+ if (LangOpts.SYCLIsDevice && !D->hasAttr<SYCLKernelEntryPointAttr>() &&
+ !D->hasAttr<SYCLExternalAttr>())
----------------
erichkeane wrote:
Hmmm... this skips quite a bit which causes obvious discomfort.
There's quite a bit inside of the function itself that get skipped too, which is a little concerning, particularly with us all-over-the-place.
IMO, I think a better formulation for the purposes of readability of this would to better integrate these in this function.
~12956 (though perhaps higher than 12950?):
```
// Some comment about how other attributes/etc are all irrelevant for the purposes of SYCL.
if (LangOpts.SYCLIsDevice)
return FD->hasAttr<SYCLKernelEntryPointAttr>() || FD->hasAttr<SYCLExternalAttr>();
```
Then around 12990:
```
// Some comment about how global variables should never be emitted
if(LangOpts.SYCLIsDevice) return false;
```
That way this requires MUCH less tea-leaf reading of the rest of the function to figure out when/why we're excluding these.
https://github.com/llvm/llvm-project/pull/140282
More information about the cfe-commits
mailing list