Skip to content

Commit c2f11e0

Browse files
committed
Use sycl_type to denote host pipes instead of new attribute
1 parent dc84cb9 commit c2f11e0

File tree

5 files changed

+32
-43
lines changed

5 files changed

+32
-43
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,12 @@ def SYCLType: InheritableAttr {
13311331
"specialization_id", "kernel_handler", "buffer_location",
13321332
"no_alias", "accessor_property_list", "group",
13331333
"private_memory", "aspect", "annotated_ptr", "annotated_arg",
1334-
"stream", "sampler"],
1334+
"stream", "sampler", "host_pipe"],
13351335
["accessor", "local_accessor", "spec_constant",
13361336
"specialization_id", "kernel_handler", "buffer_location",
13371337
"no_alias", "accessor_property_list", "group",
13381338
"private_memory", "aspect", "annotated_ptr", "annotated_arg",
1339-
"stream", "sampler"]>];
1339+
"stream", "sampler", "host_pipe"]>];
13401340
// Only used internally by SYCL implementation
13411341
let Documentation = [InternalOnly];
13421342
}
@@ -1554,15 +1554,6 @@ def SYCLDeviceGlobal: InheritableAttr {
15541554
let SimpleHandler = 1;
15551555
}
15561556

1557-
def SYCLHostPipe: InheritableAttr {
1558-
let Spellings = [CXX11<"__sycl_detail__", "host_pipe">];
1559-
let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
1560-
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
1561-
// Only used internally by SYCL implementation
1562-
let Documentation = [SYCLHostPipeAttrDocs];
1563-
let SimpleHandler = 1;
1564-
}
1565-
15661557
def SYCLGlobalVariableAllowed : InheritableAttr {
15671558
let Spellings = [CXX11<"__sycl_detail__", "global_variable_allowed">];
15681559
let Subjects = SubjectList<[CXXRecord], ErrorDiag>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,26 +3124,6 @@ so we have this attribute in sycl_detail namespace.
31243124
}];
31253125
}
31263126

3127-
def SYCLHostPipeAttrDocs : Documentation {
3128-
let Category = DocCatType;
3129-
let Heading = "__sycl_detail__::host_pipe";
3130-
let Content = [{
3131-
This attribute is part of support for SYCL host_pipe feature.
3132-
Global or static variables of type decorated with this attribute have
3133-
`sycl-unique-id`, an LLVM IR attribute, added to the definition of each such
3134-
variable, which provides a unique string identifier using
3135-
__builtin_sycl_unique_stable_id.
3136-
We do not intend to support this as a general attribute that user code can use,
3137-
so we have this attribute in sycl_detail namespace.
3138-
3139-
.. code-block:: c++
3140-
struct
3141-
[[__sycl_detail__::host_pipe]] __pipeType {}
3142-
3143-
__pipeType __pipe;
3144-
}];
3145-
}
3146-
31473127
def SYCLGlobalVariableAllowedAttrDocs : Documentation {
31483128
let Category = DocCatType;
31493129
let Heading = "__sycl_detail__::global_variable_allowed";

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ static bool SYCLCUDAIsSYCLDevice(const clang::LangOptions &LangOpts) {
110110
return LangOpts.SYCLIsDevice && LangOpts.CUDA && !LangOpts.CUDAIsDevice;
111111
}
112112

113+
static bool isSyclType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) {
114+
const auto *RD = Ty->getAsCXXRecordDecl();
115+
if (!RD)
116+
return false;
117+
118+
if (const auto *Attr = RD->getAttr<SYCLTypeAttr>())
119+
return Attr->getType() == TypeName;
120+
121+
if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
122+
if (CXXRecordDecl *TemplateDecl =
123+
CTSD->getSpecializedTemplate()->getTemplatedDecl())
124+
if (const auto *Attr = TemplateDecl->getAttr<SYCLTypeAttr>())
125+
return Attr->getType() == TypeName;
126+
127+
return false;
128+
}
129+
113130
CodeGenModule::CodeGenModule(ASTContext &C,
114131
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
115132
const HeaderSearchOptions &HSO,
@@ -5512,10 +5529,15 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
55125529
// type.
55135530
if (RD && RD->hasAttr<SYCLAddIRAttributesGlobalVariableAttr>())
55145531
AddGlobalSYCLIRAttributes(GV, RD);
5515-
// If VarDecl has a type decorated with SYCL device_global attribute or
5516-
// SYCL host_pipe attribute, emit IR attribute 'sycl-unique-id'.
5517-
if (RD && (RD->hasAttr<SYCLDeviceGlobalAttr>() ||
5518-
RD->hasAttr<SYCLHostPipeAttr>()))
5532+
// If VarDecl has a type decorated with SYCL device_global attribute
5533+
// emit IR attribute 'sycl-unique-id'.
5534+
if (RD && (RD->hasAttr<SYCLDeviceGlobalAttr>()))
5535+
addSYCLUniqueID(GV, D, Context);
5536+
5537+
// If VarDecl type is SYCLTypeAttr::host_pipe, emit the IR attribute
5538+
// 'sycl-unique-id'.
5539+
auto Ty = D->getType();
5540+
if (isSyclType(Ty, SYCLTypeAttr::host_pipe))
55195541
addSYCLUniqueID(GV, D, Context);
55205542
}
55215543

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5377,7 +5377,7 @@ void SYCLIntegrationFooter::addVarDecl(const VarDecl *VD) {
53775377
return;
53785378
// Step 1: ensure that this is of the correct type template specialization.
53795379
if (!isSyclType(VD->getType(), SYCLTypeAttr::specialization_id) &&
5380-
!S.isTypeDecoratedWithDeclAttribute<SYCLHostPipeAttr>(VD->getType()) &&
5380+
!isSyclType(VD->getType(), SYCLTypeAttr::host_pipe) &&
53815381
!S.isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
53825382
VD->getType())) {
53835383
// Handle the case where this could be a deduced type, such as a deduction
@@ -5563,9 +5563,8 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
55635563
// Skip if this isn't a SpecIdType, DeviceGlobal, or HostPipe. This
55645564
// can happen if it was a deduced type.
55655565
if (!isSyclType(VD->getType(), SYCLTypeAttr::specialization_id) &&
5566+
!isSyclType(VD->getType(), SYCLTypeAttr::host_pipe) &&
55665567
!S.isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
5567-
VD->getType()) &&
5568-
!S.isTypeDecoratedWithDeclAttribute<SYCLHostPipeAttr>(
55695568
VD->getType()))
55705569
continue;
55715570

@@ -5595,8 +5594,7 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
55955594
DeviceGlobOS << SYCLUniqueStableIdExpr::ComputeName(S.getASTContext(),
55965595
VD);
55975596
DeviceGlobOS << "\");\n";
5598-
} else if (S.isTypeDecoratedWithDeclAttribute<SYCLHostPipeAttr>(
5599-
VD->getType())) {
5597+
} else if (isSyclType(VD->getType(), SYCLTypeAttr::host_pipe)) {
56005598
HostPipesEmitted = true;
56015599
HostPipesOS << "host_pipe_map::add(";
56025600
HostPipesOS << "(void *)&";

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ host_pipe {
163163
public:
164164
struct
165165
#ifdef __SYCL_DEVICE_ONLY__
166-
// [[ __sycl_detail__::add_ir_attributes_global_variable(
167-
// "sycl-host-pipe", nullptr)]] [[__sycl_detail__::host_pipe]]
168-
[[__sycl_detail__::host_pipe]]
166+
[[__sycl_detail__::sycl_type(host_pipe)]]
169167
#endif
170168
__pipeType { const char __p; };
171169

0 commit comments

Comments
 (0)