Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
premanandrao committed Dec 27, 2024
1 parent 70caead commit f447b82
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 83 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Sema/SemaSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ class SemaSYCL : public SemaBase {
void handleSYCLIntelMaxWorkGroupsPerMultiprocessor(Decl *D,
const ParsedAttr &AL);
void handleSYCLScopeAttr(Decl *D, const ParsedAttr &AL);
void handleSYCLRegisteredKernels(Decl *D, const ParsedAttr &AL);

void checkSYCLAddIRAttributesFunctionAttrConflicts(Decl *D);

Expand Down
83 changes: 1 addition & 82 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5537,87 +5537,6 @@ static void handlePatchableFunctionEntryAttr(Sema &S, Decl *D,
PatchableFunctionEntryAttr(S.Context, AL, Count, Offset));
}

static bool isFreeFunctionKernel(Sema &S, FunctionDecl *FD) {
/* If it does not have the attribute, return false. */
if (!FD->hasAttr<SYCLAddIRAttributesFunctionAttr>())
return false;
/* If it does, traverse through the pairs and return true, if
it is one of the two free function types. */
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
SAIRAttr->getFilteredAttributeNameValuePairs(S.Context);
for (const auto &NVPair : NameValuePairs) {
if (!NVPair.first.compare("sycl-single-task-kernel") ||
!NVPair.first.compare("sycl-nd-range-kernel"))
return true;
}
/* If it does not have free function attributes, return false. */
return false;
}

static void handleSYCLRegisteredKernels(Sema &S, Decl *D, const ParsedAttr &A) {
unsigned NumArgs = A.getNumArgs();
/* When declared, we expect at least one item in the list. */
if (NumArgs == 0) {
S.Diag(A.getLoc(), diag::err_registered_kernels_num_of_args);
return;
}

/* Traverse through the items in the list. */
for (unsigned I = 0; I < NumArgs; I++) {
assert(A.isArgExpr(I) && "Expected expression argument");
/* Each item in the list must be an initializer list expression. */
Expr *ArgExpr = A.getArgAsExpr(I);
if (!isa<InitListExpr>(ArgExpr)) {
S.Diag(ArgExpr->getExprLoc(), diag::err_registered_kernels_init_list);
return;
}

const auto *ArgListE = cast<InitListExpr>(ArgExpr);
unsigned NumInits = ArgListE->getNumInits();
/* Each init-list expression must have a pair of values. */
if (NumInits != 2) {
S.Diag(ArgExpr->getExprLoc(),
diag::err_registered_kernels_init_list_pair_values);
return;
}

/* The first value of the pair muse be a string. */
const Expr *FirstExpr = ArgListE->getInit(0);
StringRef CurStr;
SourceLocation Loc = FirstExpr->getExprLoc();
if (!S.checkStringLiteralArgumentAttr(A, FirstExpr, CurStr, &Loc))
return;

/* Resolve the FunctionDecl from the second value of the pair. */
auto *SecondE = const_cast<Expr *>(ArgListE->getInit(1));
FunctionDecl *FD = nullptr;
if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(SecondE)) {
FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true);
Loc = ULE->getExprLoc();
} else {
while (isa<CastExpr>(SecondE))
SecondE = cast<CastExpr>(SecondE)->getSubExpr();
auto *DRE = dyn_cast<DeclRefExpr>(SecondE);
if (DRE)
FD = dyn_cast<FunctionDecl>(DRE->getDecl());
Loc = SecondE->getExprLoc();
}
/* Issue a diagnostic if we are unable to resolve the FunctionDecl. */
if (!FD) {
S.Diag(Loc, diag::err_registered_kernels_resolve_function) << CurStr;
return;
}
/* Issue a diagnostic is the FunctionDecl is not a SYCL free function. */
if (!isFreeFunctionKernel(S, FD)) {
S.Diag(FD->getLocation(), diag::err_not_sycl_free_function) << CurStr;
return;
}
/* Construct a free function kernel. */
S.SYCL().constructFreeFunctionKernel(FD, CurStr);
}
}

static bool SYCLAliasValid(ASTContext &Context, unsigned BuiltinID) {
constexpr llvm::StringLiteral Prefix = "__builtin_intel_sycl";
return Context.BuiltinInfo.getName(BuiltinID).starts_with(Prefix);
Expand Down Expand Up @@ -7506,7 +7425,7 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
S.SYCL().handleSYCLAddIRAnnotationsMemberAttr(D, AL);
break;
case ParsedAttr::AT_SYCLRegisteredKernels:
handleSYCLRegisteredKernels(S, D, AL);
S.SYCL().handleSYCLRegisteredKernels(D, AL);
break;

// Swift attributes.
Expand Down
85 changes: 85 additions & 0 deletions clang/lib/Sema/SemaSYCLDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3162,3 +3162,88 @@ void SemaSYCL::checkSYCLAddIRAttributesFunctionAttrConflicts(Decl *D) {
Diag(Attr->getLoc(), diag::warn_sycl_old_and_new_kernel_attributes)
<< Attr;
}

static bool isFreeFunctionKernel(SemaSYCL &S, FunctionDecl *FD) {
/* If it does not have the attribute, return false. */
if (!FD->hasAttr<SYCLAddIRAttributesFunctionAttr>())
return false;
/* If it does, traverse through the pairs and return true, if
it is one of the two free function types. */
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
SAIRAttr->getFilteredAttributeNameValuePairs(S.getASTContext());
for (const auto &NVPair : NameValuePairs) {
if (!NVPair.first.compare("sycl-single-task-kernel") ||
!NVPair.first.compare("sycl-nd-range-kernel"))
return true;
}
/* If it does not have free function attributes, return false. */
return false;
}

void SemaSYCL::handleSYCLRegisteredKernels(Decl *D, const ParsedAttr &A) {
// Check for SYCL device compilation context.
if (!getLangOpts().SYCLIsDevice)
return;

unsigned NumArgs = A.getNumArgs();
/* When declared, we expect at least one item in the list. */
if (NumArgs == 0) {
Diag(A.getLoc(), diag::err_registered_kernels_num_of_args);
return;
}

/* Traverse through the items in the list. */
for (unsigned I = 0; I < NumArgs; I++) {
assert(A.isArgExpr(I) && "Expected expression argument");
/* Each item in the list must be an initializer list expression. */
Expr *ArgExpr = A.getArgAsExpr(I);
if (!isa<InitListExpr>(ArgExpr)) {
Diag(ArgExpr->getExprLoc(), diag::err_registered_kernels_init_list);
return;
}

const auto *ArgListE = cast<InitListExpr>(ArgExpr);
unsigned NumInits = ArgListE->getNumInits();
/* Each init-list expression must have a pair of values. */
if (NumInits != 2) {
Diag(ArgExpr->getExprLoc(),
diag::err_registered_kernels_init_list_pair_values);
return;
}

/* The first value of the pair muse be a string. */
const Expr *FirstExpr = ArgListE->getInit(0);
StringRef CurStr;
SourceLocation Loc = FirstExpr->getExprLoc();
if (!SemaRef.checkStringLiteralArgumentAttr(A, FirstExpr, CurStr, &Loc))
return;

/* Resolve the FunctionDecl from the second value of the pair. */
auto *SecondE = const_cast<Expr *>(ArgListE->getInit(1));
FunctionDecl *FD = nullptr;
if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(SecondE)) {
FD = SemaRef.ResolveSingleFunctionTemplateSpecialization(ULE, true);
Loc = ULE->getExprLoc();
} else {
while (isa<CastExpr>(SecondE))
SecondE = cast<CastExpr>(SecondE)->getSubExpr();
auto *DRE = dyn_cast<DeclRefExpr>(SecondE);
if (DRE)
FD = dyn_cast<FunctionDecl>(DRE->getDecl());
Loc = SecondE->getExprLoc();
}
/* Issue a diagnostic if we are unable to resolve the FunctionDecl. */
if (!FD) {
Diag(Loc, diag::err_registered_kernels_resolve_function) << CurStr;
return;
}
/* Issue a diagnostic is the FunctionDecl is not a SYCL free function. */
if (!isFreeFunctionKernel(*this, FD)) {
Diag(FD->getLocation(), diag::err_not_sycl_free_function) << CurStr;
return;
}
/* Construct a free function kernel. */
constructFreeFunctionKernel(FD, CurStr);
}
}
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/registered-kernel-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <typename T>
__attribute__((sycl_device))
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
void tempfoo2(T pt) {
T t;
T t;
}

template void tempfoo2<int>(int);
Expand Down

0 comments on commit f447b82

Please sign in to comment.