Skip to content

[SYCL][FPGA] Drop the duplicate attribute when adding or merging #3389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 29, 2021
Merged
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
200 changes: 115 additions & 85 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3233,10 +3233,12 @@ void Sema::AddIntelReqdSubGroupSize(Decl *D, const AttributeCommonInfo &CI,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
Expand All @@ -3251,13 +3253,16 @@ Sema::MergeIntelReqdSubGroupSizeAttr(Decl *D,
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<IntelReqdSubGroupSizeAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}
return ::new (Context) IntelReqdSubGroupSizeAttr(Context, A, A.getValue());
Expand Down Expand Up @@ -3295,10 +3300,12 @@ void Sema::AddSYCLIntelNumSimdWorkItemsAttr(Decl *D,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
Expand Down Expand Up @@ -3326,13 +3333,15 @@ SYCLIntelNumSimdWorkItemsAttr *Sema::MergeSYCLIntelNumSimdWorkItemsAttr(
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}
return ::new (Context)
Expand Down Expand Up @@ -3389,10 +3398,12 @@ void Sema::AddSYCLIntelSchedulerTargetFmaxMhzAttr(Decl *D,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
Expand All @@ -3409,13 +3420,16 @@ Sema::MergeSYCLIntelSchedulerTargetFmaxMhzAttr(
// already applied to the declaration.
if (const auto *DeclAttr =
D->getAttr<SYCLIntelSchedulerTargetFmaxMhzAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}
return ::new (Context)
Expand Down Expand Up @@ -3472,15 +3486,6 @@ void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelLoopFuseAttr>()) {
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
return;
}
// [[intel::loop_fuse]] and [[intel::loop_fuse_independent]] are
// incompatible.
// FIXME: If additional spellings are provided for this attribute,
Expand All @@ -3492,6 +3497,17 @@ void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
Diag(DeclAttr->getLocation(), diag::note_conflicting_attribute);
return;
}
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
}

Expand All @@ -3503,14 +3519,6 @@ Sema::MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A) {
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelLoopFuseAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
}
// [[intel::loop_fuse]] and [[intel::loop_fuse_independent]] are
// incompatible.
// FIXME: If additional spellings are provided for this attribute,
Expand All @@ -3522,6 +3530,16 @@ Sema::MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A) {
Diag(DeclAttr->getLoc(), diag::note_conflicting_attribute);
return nullptr;
}
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}

return ::new (Context) SYCLIntelLoopFuseAttr(Context, A, A.getValue());
Expand Down Expand Up @@ -5764,10 +5782,12 @@ void Sema::AddSYCLIntelNoGlobalWorkOffsetAttr(Decl *D,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
Expand All @@ -5781,13 +5801,15 @@ SYCLIntelNoGlobalWorkOffsetAttr *Sema::MergeSYCLIntelNoGlobalWorkOffsetAttr(
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelNoGlobalWorkOffsetAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}
return ::new (Context)
Expand Down Expand Up @@ -5967,10 +5989,12 @@ void Sema::AddIntelFPGAMaxReplicatesAttr(Decl *D, const AttributeCommonInfo &CI,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLocation(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
Expand All @@ -5996,13 +6020,15 @@ Sema::MergeIntelFPGAMaxReplicatesAttr(Decl *D,
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<IntelFPGAMaxReplicatesAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue())) {
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
}
// Do not add a duplicate attribute.
return nullptr;
}
}
}
// [[intel::fpga_register]] and [[intel::max_replicates()]]
Expand Down Expand Up @@ -6166,24 +6192,28 @@ void Sema::AddIntelFPGAPrivateCopiesAttr(Decl *D, const AttributeCommonInfo &CI,
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue())) {
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
}
// Drop the duplicate attribute.
return;
}
}
// [[intel::fpga_register]] and [[intel::private_copies()]]
// attributes are incompatible.
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(*this, D, CI))
return;
// If the declaration does not have [[intel::memory]]
// attribute, this creates default implicit memory.
if (!D->hasAttr<IntelFPGAMemoryAttr>())
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
Context, IntelFPGAMemoryAttr::Default));
}

// [[intel::fpga_register]] and [[intel::private_copies()]]
// attributes are incompatible.
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(*this, D, CI))
return;

// If the declaration does not have [[intel::memory]]
// attribute, this creates default implicit memory.
if (!D->hasAttr<IntelFPGAMemoryAttr>())
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
Context, IntelFPGAMemoryAttr::Default));

D->addAttr(::new (Context) IntelFPGAPrivateCopiesAttr(Context, CI, E));
}

Expand Down
10 changes: 1 addition & 9 deletions clang/test/SemaSYCL/intel-fpga-local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,16 @@ void check_ast()
//CHECK-NEXT: ConstantExpr
//CHECK-NEXT: value:{{.*}}12
//CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}
//CHECK: IntelFPGAMaxReplicatesAttr
//CHECK-NEXT: ConstantExpr
//CHECK-NEXT: value:{{.*}}12
//CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}
[[intel::max_replicates(12)]]
[[intel::max_replicates(12)]] int var_max_replicates; // OK

// Checking of duplicate argument values.
// Check duplicate argument values.
//CHECK: VarDecl{{.*}}var_private_copies
//CHECK: IntelFPGAMemoryAttr{{.*}}Implicit
//CHECK: IntelFPGAPrivateCopiesAttr
//CHECK-NEXT: ConstantExpr
//CHECK-NEXT: value:{{.*}}12
//CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}
//CHECK: IntelFPGAPrivateCopiesAttr
//CHECK-NEXT: ConstantExpr
//CHECK-NEXT: value:{{.*}}12
//CHECK-NEXT: IntegerLiteral{{.*}}12{{$}}
[[intel::private_copies(12)]]
[[intel::private_copies(12)]] int var_private_copies; // OK

Expand Down
15 changes: 12 additions & 3 deletions clang/test/SemaSYCL/intel-fpga-no-global-work-offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,25 @@ int main() {
h.single_task<class test_kernel4>(
[]() [[intel::no_global_work_offset(-1)]]{});

// expected-error@+2{{integral constant expression must have integral or unscoped enumeration type, not 'const char [4]'}}
// Ignore duplicate attribute.
h.single_task<class test_kernel5>(
// CHECK: SYCLIntelNoGlobalWorkOffsetAttr {{.*}}
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
// CHECK-NEXT: value: Int 1
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
[]() [[intel::no_global_work_offset,
intel::no_global_work_offset]]{}); // OK

// expected-error@+2{{integral constant expression must have integral or unscoped enumeration type, not 'const char [4]'}}
h.single_task<class test_kernel6>(
[]() [[intel::no_global_work_offset("foo")]]{});

h.single_task<class test_kernel6>([]() {
h.single_task<class test_kernel7>([]() {
// expected-error@+1{{'no_global_work_offset' attribute only applies to functions}}
[[intel::no_global_work_offset(1)]] int a;
});

h.single_task<class test_kernel7>(
h.single_task<class test_kernel8>(
[]() [[intel::no_global_work_offset(0), // expected-note {{previous attribute is here}}
intel::no_global_work_offset(1)]]{}); // expected-warning{{attribute 'no_global_work_offset' is already applied with different arguments}}
});
Expand Down
3 changes: 1 addition & 2 deletions clang/test/SemaSYCL/loop_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
[[intel::loop_fuse(0, 1)]] void func3() {} // expected-error{{'loop_fuse' attribute takes no more than 1 argument}}
[[intel::loop_fuse_independent(2, 3)]] void func4() {} // expected-error{{'loop_fuse_independent' attribute takes no more than 1 argument}}

// Tests for Intel FPGA loop attributes duplication
// No diagnostic is thrown since arguments match. Duplicate attribute is silently ignored.
// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored.
[[intel::loop_fuse]] [[intel::loop_fuse]] void func5() {}
[[intel::loop_fuse_independent(10)]] [[intel::loop_fuse_independent(10)]] void func6() {}

Expand Down
Loading