Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,10 @@ class ASTNodeTraverser
void
VisitUnresolvedSYCLKernelCallStmt(const UnresolvedSYCLKernelCallStmt *Node) {
Visit(Node->getOriginalStmt());
if (Traversal != TK_IgnoreUnlessSpelledInSource)
if (Traversal != TK_IgnoreUnlessSpelledInSource) {
Visit(Node->getKernelLaunchIdExpr());
Visit(Node->getSpecArgsIdExpr());
}
}

void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) {
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,7 @@ DEF_TRAVERSE_STMT(UnresolvedSYCLKernelCallStmt, {
if (getDerived().shouldVisitImplicitCode()) {
TRY_TO(TraverseStmt(S->getOriginalStmt()));
TRY_TO(TraverseStmt(S->getKernelLaunchIdExpr()));
TRY_TO(TraverseStmt(S->getSpecArgsIdExpr()));
ShouldVisitChildren = false;
}
})
Expand Down
26 changes: 19 additions & 7 deletions clang/include/clang/AST/StmtSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,33 @@ class UnresolvedSYCLKernelCallStmt : public Stmt {
Stmt *OriginalStmt = nullptr;
// KernelLaunchIdExpr stores an UnresolvedLookupExpr or UnresolvedMemberExpr
// corresponding to the SYCL kernel launch function for which a call
// will be synthesized during template instantiation.
// will be synthesized during template instantiation of the host code.
Expr *KernelLaunchIdExpr = nullptr;

UnresolvedSYCLKernelCallStmt(CompoundStmt *CS, Expr *IdExpr)
// Similar to KernelLaunchIdExpr HandleSYCLSpecialParamsIdExpr stores an
// UnresolvedLookupExpr or UnresolvedMemberExpr corresponding to the fuction
// handling of special SYCL kernel parameters for which a call will be
// synthesized during template instantiation of the device code.
Expr *HandleSYCLSpecialParamsIdExpr = nullptr;

UnresolvedSYCLKernelCallStmt(CompoundStmt *CS, Expr *IdExpr,
Expr *HandleSYCLSpecialParamsIdExpr)
: Stmt(UnresolvedSYCLKernelCallStmtClass), OriginalStmt(CS),
KernelLaunchIdExpr(IdExpr) {}
KernelLaunchIdExpr(IdExpr),
HandleSYCLSpecialParamsIdExpr(HandleSYCLSpecialParamsIdExpr) {}

void setOriginalStmt(CompoundStmt *CS) { OriginalStmt = CS; }

void setKernelLaunchIdExpr(Expr *IdExpr) { KernelLaunchIdExpr = IdExpr; }

public:
static UnresolvedSYCLKernelCallStmt *Create(const ASTContext &C,
CompoundStmt *CS, Expr *IdExpr) {
return new (C) UnresolvedSYCLKernelCallStmt(CS, IdExpr);
CompoundStmt *CS, Expr *IdExpr,
Expr *SpecArgsExpr) {
return new (C) UnresolvedSYCLKernelCallStmt(CS, IdExpr, SpecArgsExpr);
}

static UnresolvedSYCLKernelCallStmt *CreateEmpty(const ASTContext &C) {
return new (C) UnresolvedSYCLKernelCallStmt(nullptr, nullptr);
return new (C) UnresolvedSYCLKernelCallStmt(nullptr, nullptr, nullptr);
}

CompoundStmt *getOriginalStmt() { return cast<CompoundStmt>(OriginalStmt); }
Expand All @@ -133,6 +141,10 @@ class UnresolvedSYCLKernelCallStmt : public Stmt {

Expr *getKernelLaunchIdExpr() { return KernelLaunchIdExpr; }
const Expr *getKernelLaunchIdExpr() const { return KernelLaunchIdExpr; }
Expr *getSpecArgsIdExpr() { return HandleSYCLSpecialParamsIdExpr; }
const Expr *getSpecArgsIdExpr() const {
return HandleSYCLSpecialParamsIdExpr;
}

SourceLocation getBeginLoc() const LLVM_READONLY {
return getOriginalStmt()->getBeginLoc();
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,13 @@ def SYCLSpecialClass: InheritableAttr {
let Documentation = [SYCLSpecialClassDocs];
}

def SYCLSpecialKernelParameter : InheritableAttr {
let Spellings = [CXX11<"clang", "sycl_special_kernel_parameter">];
let Subjects = SubjectList<[CXXRecord]>;
let LangOpts = [SYCLHost, SYCLDevice];
let Documentation = [Undocumented];
}

def C11NoReturn : InheritableAttr {
let Spellings = [CustomKeyword<"_Noreturn">];
let Subjects = SubjectList<[Function], ErrorDiag>;
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/ScopeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ class FunctionScopeInfo {
/// to a SYCL kernel launch function in a dependent context.
Expr *SYCLKernelLaunchIdExpr = nullptr;

/// An unresolved identifier lookup expression for an implicit call
/// to a handling function for SYCL kernel special parameters.
Expr *HandleSYCLSpecialParamsIdExpr = nullptr;

public:
/// Represents a simple identification of a weak object.
///
Expand Down
9 changes: 6 additions & 3 deletions clang/include/clang/Sema/SemaSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ class SemaSYCL : public SemaBase {
/// passed as the 'LaunchIdExpr' argument in a call to either
/// BuildSYCLKernelCallStmt() or BuildUnresolvedSYCLKernelCallStmt() after
/// the function body has been parsed.
ExprResult BuildSYCLKernelLaunchIdExpr(FunctionDecl *FD, QualType KernelName);
ExprResult BuildSYCLKernelLaunchIdExpr(FunctionDecl *FD, QualType KernelName,
StringRef FuncName);

/// Builds a SYCLKernelCallStmt to wrap 'Body' and to be used as the body of
/// 'FD'. 'LaunchIdExpr' specifies the lookup result returned by a previous
/// call to BuildSYCLKernelLaunchIdExpr().
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body,
Expr *LaunchIdExpr);
Expr *LaunchIdExpr,
Expr *HandleSpecParamsExpr);

/// Builds an UnresolvedSYCLKernelCallStmt to wrap 'Body'. 'LaunchIdExpr'
/// specifies the lookup result returned by a previous call to
/// BuildSYCLKernelLaunchIdExpr().
StmtResult BuildUnresolvedSYCLKernelCallStmt(CompoundStmt *Body,
Expr *LaunchIdExpr);
Expr *LaunchIdExpr,
Expr *HandleSpecParamsExpr);
};

} // namespace clang
Expand Down
18 changes: 14 additions & 4 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16466,7 +16466,7 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
const auto *SKEPAttr = FD->getAttr<SYCLKernelEntryPointAttr>();
if (!SKEPAttr->isInvalidAttr()) {
ExprResult LaunchIdExpr =
SYCL().BuildSYCLKernelLaunchIdExpr(FD, SKEPAttr->getKernelName());
SYCL().BuildSYCLKernelLaunchIdExpr(FD, SKEPAttr->getKernelName(), "sycl_kernel_launch");
// Do not mark 'FD' as invalid if construction of `LaunchIDExpr` produces
// an invalid result. Name lookup failure for 'sycl_kernel_launch' is
// treated as an error in the definition of 'FD'; treating it as an error
Expand All @@ -16475,6 +16475,13 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
// 'LaunchIDExpr' failed, then 'SYCLKernelLaunchIdExpr' will be assigned
// a null pointer value below; that is expected.
getCurFunction()->SYCLKernelLaunchIdExpr = LaunchIdExpr.get();
if (!LaunchIdExpr.isInvalid() &&
!LaunchIdExpr.get()->getType()->isVoidType()) {
ExprResult HSPSPIdExpr = SYCL().BuildSYCLKernelLaunchIdExpr(
FD, SKEPAttr->getKernelName(),
"sycl_handle_special_kernel_parameters");
getCurFunction()->HandleSYCLSpecialParamsIdExpr = HSPSPIdExpr.get();
}
}
}

Expand Down Expand Up @@ -16690,19 +16697,22 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, bool IsInstantiation,
// The function body should already be a SYCLKernelCallStmt in this
// case, but might not be if there were previous errors.
SR = Body;
} else if (!getCurFunction()->SYCLKernelLaunchIdExpr) {
} else if (!getCurFunction()->SYCLKernelLaunchIdExpr ||
!getCurFunction()->HandleSYCLSpecialParamsIdExpr) {
// If name lookup for a template named sycl_kernel_launch failed
// earlier, don't try to build a SYCL kernel call statement as that
// would cause additional errors to be issued; just proceed with the
// original function body.
SR = Body;
} else if (FD->isTemplated()) {
SR = SYCL().BuildUnresolvedSYCLKernelCallStmt(
cast<CompoundStmt>(Body), getCurFunction()->SYCLKernelLaunchIdExpr);
cast<CompoundStmt>(Body), getCurFunction()->SYCLKernelLaunchIdExpr,
getCurFunction()->HandleSYCLSpecialParamsIdExpr);
} else {
SR = SYCL().BuildSYCLKernelCallStmt(
FD, cast<CompoundStmt>(Body),
getCurFunction()->SYCLKernelLaunchIdExpr);
getCurFunction()->SYCLKernelLaunchIdExpr,
getCurFunction()->HandleSYCLSpecialParamsIdExpr);
}
// If construction of the replacement body fails, just continue with the
// original function body. An early error return here is not valid; the
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7753,6 +7753,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
case ParsedAttr::AT_SYCLSpecialClass:
handleSimpleAttribute<SYCLSpecialClassAttr>(S, D, AL);
break;
case ParsedAttr::AT_SYCLSpecialKernelParameter:
handleSimpleAttribute<SYCLSpecialKernelParameterAttr>(S, D, AL);
break;
case ParsedAttr::AT_Format:
handleFormatAttr(S, D, AL);
break;
Expand Down
Loading