@@ -70,15 +70,15 @@ class GlobalDecl {
7070 GlobalDecl (const VarDecl *D) { Init (D);}
7171 GlobalDecl (const FunctionDecl *D, unsigned MVIndex = 0 )
7272 : MultiVersionIndex(MVIndex) {
73- if (! D->hasAttr <CUDAGlobalAttr> ()) {
74- Init (D );
73+ if (D->isReferenceableKernel ()) {
74+ Value. setPointerAndInt (D, unsigned ( getDefaultKernelReference (D)) );
7575 return ;
7676 }
77- Value. setPointerAndInt (D, unsigned ( getDefaultKernelReference (D)) );
77+ Init (D );
7878 }
7979 GlobalDecl (const FunctionDecl *D, KernelReferenceKind Kind)
8080 : Value(D, unsigned (Kind)) {
81- assert (D->hasAttr <CUDAGlobalAttr> () && " Decl is not a GPU kernel!" );
81+ assert (D->isReferenceableKernel () && " Decl is not a GPU kernel!" );
8282 }
8383 GlobalDecl (const NamedDecl *D) { Init (D); }
8484 GlobalDecl (const BlockDecl *D) { Init (D); }
@@ -131,12 +131,13 @@ class GlobalDecl {
131131
132132 KernelReferenceKind getKernelReferenceKind () const {
133133 assert (((isa<FunctionDecl>(getDecl ()) &&
134- cast<FunctionDecl>(getDecl ())->hasAttr <CUDAGlobalAttr> ()) ||
134+ cast<FunctionDecl>(getDecl ())->isReferenceableKernel ()) ||
135135 (isa<FunctionTemplateDecl>(getDecl ()) &&
136136 cast<FunctionTemplateDecl>(getDecl ())
137137 ->getTemplatedDecl ()
138138 ->hasAttr <CUDAGlobalAttr>())) &&
139139 " Decl is not a GPU kernel!" );
140+
140141 return static_cast <KernelReferenceKind>(Value.getInt ());
141142 }
142143
@@ -160,8 +161,9 @@ class GlobalDecl {
160161 }
161162
162163 static KernelReferenceKind getDefaultKernelReference (const FunctionDecl *D) {
163- return D->getLangOpts ().CUDAIsDevice ? KernelReferenceKind::Kernel
164- : KernelReferenceKind::Stub;
164+ return (D->hasAttr <OpenCLKernelAttr>() || D->getLangOpts ().CUDAIsDevice )
165+ ? KernelReferenceKind::Kernel
166+ : KernelReferenceKind::Stub;
165167 }
166168
167169 GlobalDecl getWithDecl (const Decl *D) {
@@ -197,7 +199,7 @@ class GlobalDecl {
197199
198200 GlobalDecl getWithKernelReferenceKind (KernelReferenceKind Kind) {
199201 assert (isa<FunctionDecl>(getDecl ()) &&
200- cast<FunctionDecl>(getDecl ())->hasAttr <CUDAGlobalAttr> () &&
202+ cast<FunctionDecl>(getDecl ())->isReferenceableKernel () &&
201203 " Decl is not a GPU kernel!" );
202204 GlobalDecl Result (*this );
203205 Result.Value .setInt (unsigned (Kind));
0 commit comments