Skip to content

Commit 8bd8d76

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 5e39487 + e5af883 commit 8bd8d76

File tree

62 files changed

+919
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+919
-662
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -11360,7 +11360,7 @@ def err_conflicting_sycl_function_attributes : Error<
1136011360
def err_sycl_function_attribute_mismatch : Error<
1136111361
"SYCL kernel without %0 attribute can't call a function with this attribute">;
1136211362
def err_sycl_x_y_z_arguments_must_be_one : Error<
11363-
"%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">;
11363+
"all %0 attribute arguments must be '1' when the %1 attribute argument is '0'">;
1136411364
def err_sycl_attribute_internal_function
1136511365
: Error<"%0 attribute cannot be applied to a "
1136611366
"static function or function in an anonymous namespace">;

clang/include/clang/Sema/Sema.h

+5-34
Original file line numberDiff line numberDiff line change
@@ -10316,8 +10316,6 @@ class Sema final {
1031610316
void AddIntelFPGABankBitsAttr(Decl *D, const AttributeCommonInfo &CI,
1031710317
Expr **Exprs, unsigned Size);
1031810318
template <typename AttrType>
10319-
void addIntelSingleArgAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E);
10320-
template <typename AttrType>
1032110319
void addIntelTripleArgAttr(Decl *D, const AttributeCommonInfo &CI,
1032210320
Expr *XDimExpr, Expr *YDimExpr, Expr *ZDimExpr);
1032310321
void AddWorkGroupSizeHintAttr(Decl *D, const AttributeCommonInfo &CI,
@@ -10373,7 +10371,11 @@ class Sema final {
1037310371

1037410372
SYCLIntelFPGAMaxConcurrencyAttr *MergeSYCLIntelFPGAMaxConcurrencyAttr(
1037510373
Decl *D, const SYCLIntelFPGAMaxConcurrencyAttr &A);
10376-
10374+
void AddSYCLIntelMaxGlobalWorkDimAttr(Decl *D, const AttributeCommonInfo &CI,
10375+
Expr *E);
10376+
SYCLIntelMaxGlobalWorkDimAttr *
10377+
MergeSYCLIntelMaxGlobalWorkDimAttr(Decl *D,
10378+
const SYCLIntelMaxGlobalWorkDimAttr &A);
1037710379
/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
1037810380
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
1037910381
bool IsPackExpansion);
@@ -13307,37 +13309,6 @@ class Sema final {
1330713309
}
1330813310
};
1330913311

13310-
template <typename AttrType>
13311-
void Sema::addIntelSingleArgAttr(Decl *D, const AttributeCommonInfo &CI,
13312-
Expr *E) {
13313-
assert(E && "Attribute must have an argument.");
13314-
13315-
if (!E->isInstantiationDependent()) {
13316-
llvm::APSInt ArgVal;
13317-
ExprResult ICE = VerifyIntegerConstantExpression(E, &ArgVal);
13318-
if (ICE.isInvalid())
13319-
return;
13320-
E = ICE.get();
13321-
int32_t ArgInt = ArgVal.getSExtValue();
13322-
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
13323-
if (ArgInt < 0) {
13324-
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
13325-
<< CI << /*non-negative*/ 1;
13326-
return;
13327-
}
13328-
}
13329-
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
13330-
if (ArgInt > 3) {
13331-
Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
13332-
<< CI << 0 << 3 << E->getSourceRange();
13333-
return;
13334-
}
13335-
}
13336-
}
13337-
13338-
D->addAttr(::new (Context) AttrType(Context, CI, E));
13339-
}
13340-
1334113312
inline Expr *checkMaxWorkSizeAttrExpr(Sema &S, const AttributeCommonInfo &CI,
1334213313
Expr *E) {
1334313314
assert(E && "Attribute must have an argument.");

clang/lib/Driver/ToolChains/Clang.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -4232,6 +4232,17 @@ static bool ContainsWrapperAction(const Action *A) {
42324232
return false;
42334233
}
42344234

4235+
/// Check whether the given input tree contains any append footer actions
4236+
static bool ContainsAppendFooterAction(const Action *A) {
4237+
if (isa<AppendFooterJobAction>(A))
4238+
return true;
4239+
for (const auto &AI : A->inputs())
4240+
if (ContainsAppendFooterAction(AI))
4241+
return true;
4242+
4243+
return false;
4244+
}
4245+
42354246
// Put together an external compiler compilation call which is used instead
42364247
// of the clang invocation for the host compile of an offload compilation.
42374248
// Enabling command line: clang++ -fsycl -fsycl-host-compiler=<HostExe>
@@ -4669,8 +4680,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46694680
if (!IsSYCLOffloadDevice) {
46704681
// Add the -include option to add the integration header
46714682
StringRef Header = D.getIntegrationHeader(Input.getBaseInput());
4683+
// Do not add the integration header if we are compiling after the
4684+
// integration footer has been applied. Check for the append job
4685+
// action to determine this.
46724686
if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
4673-
!Header.empty()) {
4687+
!Header.empty() && !ContainsAppendFooterAction(&JA)) {
46744688
CmdArgs.push_back("-include");
46754689
CmdArgs.push_back(Args.MakeArgString(Header));
46764690
// When creating dependency information, filter out the generated

clang/lib/Sema/SemaDecl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
26452645
NewAttr = S.MergeSYCLIntelFPGAInitiationIntervalAttr(D, *A);
26462646
else if (const auto *A = dyn_cast<WorkGroupSizeHintAttr>(Attr))
26472647
NewAttr = S.MergeWorkGroupSizeHintAttr(D, *A);
2648+
else if (const auto *A = dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(Attr))
2649+
NewAttr = S.MergeSYCLIntelMaxGlobalWorkDimAttr(D, *A);
26482650
else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))
26492651
NewAttr = cast<InheritableAttr>(Attr->clone(S.Context));
26502652

clang/lib/Sema/SemaDeclAttr.cpp

+147-57
Original file line numberDiff line numberDiff line change
@@ -3004,19 +3004,6 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
30043004
// they hold equal values (1, 1, 1).
30053005
static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
30063006
bool Result = true;
3007-
auto checkZeroDim = [&S, &AL](auto &A, size_t X, size_t Y, size_t Z,
3008-
bool ReverseAttrs = false) -> bool {
3009-
if (X != 1 || Y != 1 || Z != 1) {
3010-
auto Diag =
3011-
S.Diag(AL.getLoc(), diag::err_sycl_x_y_z_arguments_must_be_one);
3012-
if (ReverseAttrs)
3013-
Diag << AL << A;
3014-
else
3015-
Diag << A << AL;
3016-
return false;
3017-
}
3018-
return true;
3019-
};
30203007

30213008
// Returns the unsigned constant integer value represented by
30223009
// given expression.
@@ -3026,30 +3013,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
30263013

30273014
ASTContext &Ctx = S.getASTContext();
30283015

3029-
if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
3030-
ArrayRef<const Expr *> Dims;
3031-
Attr *B = nullptr;
3032-
if (const auto *B = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>())
3033-
Dims = B->dimensions();
3034-
else if (const auto *B = D->getAttr<ReqdWorkGroupSizeAttr>())
3035-
Dims = B->dimensions();
3036-
if (B) {
3037-
Result &=
3038-
checkZeroDim(B, getExprValue(Dims[0], Ctx),
3039-
getExprValue(Dims[1], Ctx), getExprValue(Dims[2], Ctx));
3040-
}
3041-
return Result;
3042-
}
3043-
3044-
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
3045-
if ((A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue()) == 0) {
3046-
Result &= checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), Ctx),
3047-
getExprValue(AL.getArgAsExpr(1), Ctx),
3048-
getExprValue(AL.getArgAsExpr(2), Ctx),
3049-
/*ReverseAttrs=*/true);
3050-
}
3051-
}
3052-
30533016
if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
30543017
if (!((getExprValue(AL.getArgAsExpr(0), Ctx) <=
30553018
getExprValue(A->getXDim(), Ctx)) &&
@@ -3159,6 +3122,27 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
31593122
}
31603123
}
31613124

3125+
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr or
3126+
// ReqdWorkGroupSizeAttr, check to see if they hold equal values
3127+
// (1, 1, 1) in case the value of SYCLIntelMaxGlobalWorkDimAttr
3128+
// equals to 0.
3129+
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
3130+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
3131+
// If the value is dependent, we can not test anything.
3132+
if (!DeclExpr)
3133+
return;
3134+
3135+
// Test the attribute value.
3136+
if (DeclExpr->getResultAsAPSInt() == 0 &&
3137+
(XDimVal.getZExtValue() != 1 || YDimVal.getZExtValue() != 1 ||
3138+
ZDimVal.getZExtValue() != 1)) {
3139+
S.Diag(AL.getLoc(), diag::err_sycl_x_y_z_arguments_must_be_one)
3140+
<< AL << DeclAttr;
3141+
return;
3142+
}
3143+
}
3144+
}
3145+
31623146
if (const auto *ExistingAttr = D->getAttr<WorkGroupAttr>()) {
31633147
// Compare attribute arguments value and warn for a mismatch.
31643148
if (ExistingAttr->getXDimVal(Ctx) != XDimVal ||
@@ -3661,23 +3645,130 @@ static void handleSYCLIntelSchedulerTargetFmaxMhzAttr(Sema &S, Decl *D,
36613645
}
36623646

36633647
// Handles max_global_work_dim.
3664-
static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D, const ParsedAttr &A) {
3665-
if (D->isInvalidDecl())
3666-
return;
3648+
// Returns a OneArgResult value; EqualToOne means all argument values are
3649+
// equal to one, NotEqualToOne means at least one argument value is not
3650+
// equal to one, and Unknown means that at least one of the argument values
3651+
// could not be determined.
3652+
enum class OneArgResult { Unknown, EqualToOne, NotEqualToOne };
3653+
static OneArgResult AreAllArgsOne(const Expr *Args[], size_t Count) {
3654+
3655+
for (size_t Idx = 0; Idx < Count; ++Idx) {
3656+
const auto *CE = dyn_cast<ConstantExpr>(Args[Idx]);
3657+
if (!CE)
3658+
return OneArgResult::Unknown;
3659+
if (CE->getResultAsAPSInt() != 1)
3660+
return OneArgResult::NotEqualToOne;
3661+
}
3662+
return OneArgResult::EqualToOne;
3663+
}
3664+
3665+
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr or
3666+
// ReqdWorkGroupSizeAttr, check to see if they hold equal values
3667+
// (1, 1, 1). Returns true if diagnosed.
3668+
template <typename AttrTy>
3669+
static bool checkWorkGroupSizeAttrExpr(Sema &S, Decl *D,
3670+
const AttributeCommonInfo &AL) {
3671+
if (const auto *A = D->getAttr<AttrTy>()) {
3672+
const Expr *Args[3] = {A->getXDim(), A->getYDim(), A->getZDim()};
3673+
if (OneArgResult::NotEqualToOne == AreAllArgsOne(Args, 3)) {
3674+
S.Diag(A->getLocation(), diag::err_sycl_x_y_z_arguments_must_be_one)
3675+
<< A << AL;
3676+
return true;
3677+
}
3678+
}
3679+
return false;
3680+
}
36673681

3668-
Expr *E = A.getArgAsExpr(0);
3682+
void Sema::AddSYCLIntelMaxGlobalWorkDimAttr(Decl *D,
3683+
const AttributeCommonInfo &CI,
3684+
Expr *E) {
3685+
if (!E->isValueDependent()) {
3686+
// Validate that we have an integer constant expression and then store the
3687+
// converted constant expression into the semantic attribute so that we
3688+
// don't have to evaluate it again later.
3689+
llvm::APSInt ArgVal;
3690+
ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
3691+
if (Res.isInvalid())
3692+
return;
3693+
E = Res.get();
36693694

3670-
if (!checkWorkGroupSizeValues(S, D, A)) {
3671-
D->setInvalidDecl();
3672-
return;
3695+
// This attribute must be in the range [0, 3].
3696+
if (ArgVal < 0 || ArgVal > 3) {
3697+
Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
3698+
<< CI << 0 << 3 << E->getSourceRange();
3699+
return;
3700+
}
3701+
3702+
// Check to see if there's a duplicate attribute with different values
3703+
// already applied to the declaration.
3704+
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
3705+
// If the other attribute argument is instantiation dependent, we won't
3706+
// have converted it to a constant expression yet and thus we test
3707+
// whether this is a null pointer.
3708+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
3709+
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
3710+
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
3711+
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
3712+
}
3713+
// Drop the duplicate attribute.
3714+
return;
3715+
}
3716+
}
3717+
3718+
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr or
3719+
// ReqdWorkGroupSizeAttr, check to see if they hold equal values
3720+
// (1, 1, 1) in case the value of SYCLIntelMaxGlobalWorkDimAttr
3721+
// equals to 0.
3722+
if (ArgVal == 0) {
3723+
if (checkWorkGroupSizeAttrExpr<SYCLIntelMaxWorkGroupSizeAttr>(*this, D,
3724+
CI) ||
3725+
checkWorkGroupSizeAttrExpr<ReqdWorkGroupSizeAttr>(*this, D, CI))
3726+
return;
3727+
}
36733728
}
36743729

3675-
if (D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
3676-
S.Diag(A.getLoc(), diag::warn_duplicate_attribute) << A;
3730+
D->addAttr(::new (Context) SYCLIntelMaxGlobalWorkDimAttr(Context, CI, E));
3731+
}
36773732

3678-
S.CheckDeprecatedSYCLAttributeSpelling(A);
3733+
SYCLIntelMaxGlobalWorkDimAttr *Sema::MergeSYCLIntelMaxGlobalWorkDimAttr(
3734+
Decl *D, const SYCLIntelMaxGlobalWorkDimAttr &A) {
3735+
// Check to see if there's a duplicate attribute with different values
3736+
// already applied to the declaration.
3737+
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
3738+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
3739+
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
3740+
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
3741+
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
3742+
Diag(A.getLoc(), diag::note_previous_attribute);
3743+
}
3744+
// Do not add a duplicate attribute.
3745+
return nullptr;
3746+
}
3747+
}
3748+
}
3749+
3750+
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr or
3751+
// ReqdWorkGroupSizeAttr, check to see if they hold equal values
3752+
// (1, 1, 1) in case the value of SYCLIntelMaxGlobalWorkDimAttr
3753+
// equals to 0.
3754+
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
3755+
if (MergeExpr->getResultAsAPSInt() == 0) {
3756+
if (checkWorkGroupSizeAttrExpr<SYCLIntelMaxWorkGroupSizeAttr>(*this, D,
3757+
A) ||
3758+
checkWorkGroupSizeAttrExpr<ReqdWorkGroupSizeAttr>(*this, D, A))
3759+
return nullptr;
3760+
}
36793761

3680-
S.addIntelSingleArgAttr<SYCLIntelMaxGlobalWorkDimAttr>(D, A, E);
3762+
return ::new (Context)
3763+
SYCLIntelMaxGlobalWorkDimAttr(Context, A, A.getValue());
3764+
}
3765+
3766+
static void handleSYCLIntelMaxGlobalWorkDimAttr(Sema &S, Decl *D,
3767+
const ParsedAttr &AL) {
3768+
S.CheckDeprecatedSYCLAttributeSpelling(AL);
3769+
3770+
Expr *E = AL.getArgAsExpr(0);
3771+
S.AddSYCLIntelMaxGlobalWorkDimAttr(D, AL, E);
36813772
}
36823773

36833774
// Handles [[intel::loop_fuse]] and [[intel::loop_fuse_independent]].
@@ -5250,14 +5341,6 @@ static void handleSYCLDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52505341
}
52515342

52525343
handleSimpleAttribute<SYCLDeviceAttr>(S, D, AL);
5253-
// constexpr variable may already get an implicit constant attr, which should
5254-
// be replaced by the explicit constant attr.
5255-
if (auto *A = D->getAttr<CUDAConstantAttr>()) {
5256-
if (!A->isImplicit())
5257-
return;
5258-
D->dropAttr<CUDAConstantAttr>();
5259-
}
5260-
D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL));
52615344
}
52625345

52635346
static void handleSYCLDeviceIndirectlyCallableAttr(Sema &S, Decl *D,
@@ -5355,6 +5438,13 @@ static void handleConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
53555438
S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
53565439
return;
53575440
}
5441+
// constexpr variable may already get an implicit constant attr, which should
5442+
// be replaced by the explicit constant attr.
5443+
if (auto *A = D->getAttr<CUDAConstantAttr>()) {
5444+
if (!A->isImplicit())
5445+
return;
5446+
D->dropAttr<CUDAConstantAttr>();
5447+
}
53585448
D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL));
53595449
}
53605450

@@ -9554,7 +9644,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
95549644
handleSYCLIntelSchedulerTargetFmaxMhzAttr(S, D, AL);
95559645
break;
95569646
case ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim:
9557-
handleMaxGlobalWorkDimAttr(S, D, AL);
9647+
handleSYCLIntelMaxGlobalWorkDimAttr(S, D, AL);
95589648
break;
95599649
case ParsedAttr::AT_SYCLIntelNoGlobalWorkOffset:
95609650
handleSYCLIntelNoGlobalWorkOffsetAttr(S, D, AL);

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,14 @@ static void instantiateSYCLIntelNoGlobalWorkOffsetAttr(
682682
S.AddSYCLIntelNoGlobalWorkOffsetAttr(New, *A, Result.getAs<Expr>());
683683
}
684684

685-
template <typename AttrName>
686-
static void instantiateIntelSYCLFunctionAttr(
685+
static void instantiateSYCLIntelMaxGlobalWorkDimAttr(
687686
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
688-
const AttrName *Attr, Decl *New) {
687+
const SYCLIntelMaxGlobalWorkDimAttr *A, Decl *New) {
689688
EnterExpressionEvaluationContext Unevaluated(
690689
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
691-
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
690+
ExprResult Result = S.SubstExpr(A->getValue(), TemplateArgs);
692691
if (!Result.isInvalid())
693-
S.addIntelSingleArgAttr<AttrName>(New, *Attr, Result.getAs<Expr>());
692+
S.AddSYCLIntelMaxGlobalWorkDimAttr(New, *A, Result.getAs<Expr>());
694693
}
695694

696695
static void instantiateSYCLIntelFPGAMaxConcurrencyAttr(
@@ -960,8 +959,8 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
960959
}
961960
if (const auto *SYCLIntelMaxGlobalWorkDim =
962961
dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(TmplAttr)) {
963-
instantiateIntelSYCLFunctionAttr<SYCLIntelMaxGlobalWorkDimAttr>(
964-
*this, TemplateArgs, SYCLIntelMaxGlobalWorkDim, New);
962+
instantiateSYCLIntelMaxGlobalWorkDimAttr(*this, TemplateArgs,
963+
SYCLIntelMaxGlobalWorkDim, New);
965964
continue;
966965
}
967966
if (const auto *SYCLIntelLoopFuse =

0 commit comments

Comments
 (0)