-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes #3251
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
Conversation
…ates()]] attributes This patch 1. refactors two declaration attributes: [[intel::private_copies()] and [[intel::max_replicates()]] using intel#3224 as a template to better fit for community standards. 2. refactors the way we handle duplicate attributes and mutually exclusive attributes logic when present on a given declaration. 3. handles redeclarations or template instantiations properly. 4. adds test Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
The patch will be rebased after #3234 lands. |
Signed-off-by: Soumi Manna <[email protected]>
Thanks @AaronBallman for feedbacks. I will address them and submit new patch. |
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
// [[intel::max_replicates()]] and [[intel::fpga_register]] | ||
// attributes are incompatible. | ||
if (const auto *DeclAttr = D->getAttr<IntelFPGARegisterAttr>()) { | ||
Diag(DeclAttr->getLoc(), diag::err_attributes_are_not_compatible) | ||
<< &A << DeclAttr; | ||
Diag(A.getLoc(), diag::note_conflicting_attribute); | ||
return nullptr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not add checkAttrMutualExclusion<> here since this will generate incompatible attribute on first line instead of second line
// Merging of incompatible args
[[intel::max_replicates(12)]] extern const int var_max_replicates_2;
[[intel::fpga_register]] const int var_max_replicates_2 = 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the other merge*Attr
use checkAttrMutualExclusion()
, so I don't think the order is incorrect.
D
holds the attributes we've already applied, so if D
has an IntelFPGARegisterAttr
, then the conflict we want to report is not with that attribute, but with the one we're about to add (IntelFPGAMaxReplicatesAttr
). From that perspective, I think your code is diagnosing the opposite of what I'd expect -- it is diagnosing the IntelFPGARegisterAttr
attribute location as being incompatible, but that's not the incompatible attribute -- the attempt to merge in IntelFPGAMaxReplicatesAttr
is.
If you still think the behavior is wrong when using checkAttrMutualExclusion<>
, can you post the exact diagnostic output you're getting from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronBallman, thanks for the feedback.
I think your code is diagnosing the opposite of what I'd expect -- it is diagnosing the IntelFPGARegisterAttr attribute location as being incompatible,
Yes, this is what happening here.
I confused myself with CheckMutualExclusionSYCLLoopAttribute() that the incompatible diagnostic will be on second line where we have IntelFPGARegisterAttr attribute on declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the output from checkAttrMutualExclusion<> with the current patch:
// Merging of incompatible attributes
//expected-error@+2{{'max_replicates' and 'fpga_register' attributes are not compatible}}
//expected-note@+2{{conflicting attribute is here}}
[[intel::max_replicates(12)]] extern const int var_max_replicates_2;
[[intel::fpga_register]] const int var_max_replicates_2 =0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That order looks wrong to me. I'd expect:
[[intel::max_replicates(12)]] extern const int var_max_replicates_2; // expected-note {{conflicting attribute is here}}
[[intel::fpga_register]] const int var_max_replicates_2 =0; // expected-error {{'max_replicates' and 'fpga_register' attributes are not compatible}}
One question I have is: are you sure this behavior isn't coming from checkIntelFPGARegisterAttrCompatibility()
rather than this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That order looks wrong to me. I'd expect:
[[intel::max_replicates(12)]] extern const int var_max_replicates_2; // expected-note {{conflicting attribute is here}} [[intel::fpga_register]] const int var_max_replicates_2 =0; // expected-error {{'max_replicates' and 'fpga_register' attributes are not compatible}}
This is what i had before checkAttrMutualExclusion<>
// attributes are incompatible.
if (const auto *DeclAttr = D->getAttr<IntelFPGARegisterAttr>()) {
Diag(DeclAttr->getLoc(), diag::err_attributes_are_not_compatible)
<< &A << DeclAttr;
Diag(A.getLoc(), diag::note_conflicting_attribute);
return nullptr;
}
checkAttrMutualExclusion<> function changes the order because of this:
template <typename AttrTy>
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
if (const auto *A = D->getAttr<AttrTy>()) {
S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
<< A;
S.Diag(A->getLocation(), diag::note_conflicting_attribute);
return true;
}
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking! I don't want us to get too hung up on this, but something fishy is going on that I'm not quite understanding. Your code looks like it should issue the diagnostics in the wrong order -- you check to see if the declaration has an existing IntelFPGARegisterAttr
attribute and if it does, it issues the diagnostic on that previous attribute (not the one being added). It then notes the one being added as being the conflicting attribute. This is backwards -- the initial attribute is fine (there were no attributes on the declaration for it to conflict with), it's the second attribute location that should be diagnosed as the error (rather than the note).
Are all of the merge*Attr()
functions which call checkAttrMutualExclusion
getting the order wrong? (I suppose that's a possibility I hadn't considered.) Or is it perhaps because we don't have any merge function for IntelFPGARegisterAttr
when we should have one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to some excellent detective work from @smanna12, we figured out that this is a community issue. All of the merge functions currently calling checkAttrMutualExclusion()
have the same backwards diagnostic behavior. Yay for getting to the bottom of the mystery!
I think you should use checkAttrMutualExclusion()
and add a FIXME comment to the test about this behavior not being ideal, but it being an issue that should be solved in community. I don't think we need to rush to get a fix into community because the diagnostic behavior here is sufficient for users to understand what's wrong with their code, even if the diagnostic location isn't ideal (redeclaration merging is a bit of an edge case for attribute handling).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AaronBallman for the comments and the detailed explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added FIXME comments in the test.
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
S.CheckDeprecatedSYCLAttributeSpelling(A); | ||
|
||
S.addIntelSingleArgAttr<IntelFPGAMaxReplicatesAttr>(D, A, A.getArgAsExpr(0)); | ||
Expr *E = A.getArgAsExpr(0); | ||
S.AddIntelFPGAMaxReplicatesAttr(D, A, E); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S.AddIntelFPGAMaxReplicatesAttr(D, A, E); | |
S.AddIntelFPGAMaxReplicatesAttr(D, A, A.getArgAsExpr(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
S.CheckDeprecatedSYCLAttributeSpelling(A); | ||
|
||
S.addIntelSingleArgAttr<IntelFPGAPrivateCopiesAttr>(D, A, A.getArgAsExpr(0)); | ||
Expr *E = A.getArgAsExpr(0); | ||
S.AddIntelFPGAPrivateCopiesAttr(D, A, E); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S.AddIntelFPGAPrivateCopiesAttr(D, A, E); | |
S.AddIntelFPGAPrivateCopiesAttr(D, A, A.getArgAsExpr(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @AaronBallman. |
@premanandrao / @elizabethandrews , can you please review this? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks!
This patch
[[intel::private_copies()] and [[intel::max_replicates()]] to better fit for community standards.
mutually exclusive attributes logic when present on a given declaration.
Signed-off-by: Soumi Manna [email protected]