Skip to content
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

[clang] Add support for new loop attribute [[clang::code_align()]] #70762

Merged
merged 43 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
93d46d4
[clang] Add support for new loop attribute [[clang::code_align()]]
smanna12 Oct 31, 2023
d049dc9
Address review comments
smanna12 Nov 2, 2023
6c44cc1
Fix clang format errors
smanna12 Nov 2, 2023
f35c4be
Fix Lit test failure
smanna12 Nov 2, 2023
4c40ce2
Address review comments
smanna12 Nov 6, 2023
9144e44
Fix clang format errors
smanna12 Nov 6, 2023
22f66bd
Address review comments
smanna12 Nov 6, 2023
66f6269
Fix lit test failure
smanna12 Nov 7, 2023
3ac064b
Fix DuplicateCodeAlignAttrs check
smanna12 Nov 7, 2023
172e238
Fix Clang format errors
smanna12 Nov 7, 2023
c8d5270
Remove wrong function
smanna12 Nov 7, 2023
d16a0f9
Merge remote-tracking branch 'my_remote/main' into AddCodeAlignAttr
smanna12 Nov 7, 2023
b4b3c10
Merge remote-tracking branch 'my_remote/main' into AddCodeAlignAttr
smanna12 Nov 10, 2023
2e6ee33
Update diagnostic message and test
smanna12 Nov 13, 2023
82c2e70
Merge remote-tracking branch 'my_remote/main' into AddCodeAlignAttr
smanna12 Nov 13, 2023
8474860
Update min and max aligment check
smanna12 Nov 13, 2023
aa85ed1
Add additional members as static-constexpr
smanna12 Nov 13, 2023
0887674
Address review comments
smanna12 Nov 14, 2023
48e00f1
Fix test
smanna12 Nov 14, 2023
8fb7d22
Fix lit test failures
smanna12 Nov 14, 2023
8bec3c4
Fix bug for alignment value with ((__int128_t)0x1234567890abcde0ULL <…
smanna12 Nov 15, 2023
5c4ce9e
Fix clang format errors
smanna12 Nov 15, 2023
974ebf2
update patch
smanna12 Nov 15, 2023
06eadd9
Fix return nullptr check
smanna12 Nov 15, 2023
5ebb42f
Update patch with trySExtValue() and add test case for big negative
smanna12 Nov 15, 2023
ebcefed
Check an expression resulting in a negative that takes more than 64 bits
smanna12 Nov 15, 2023
72a1a69
Fix lit test
smanna12 Nov 15, 2023
845b687
Fix assertion and remove duplicate codes
smanna12 Nov 15, 2023
fca4436
Fix Clang format errors
smanna12 Nov 15, 2023
a8b13eb
Use Simple algorithm to handle duplicate attribute values.
smanna12 Nov 16, 2023
488b810
Fix clang format errors
smanna12 Nov 16, 2023
09b00c7
Fix Duplicate Attribute Values diagnostic using find_if()
smanna12 Nov 16, 2023
5fadd6a
Apply review comments
smanna12 Nov 16, 2023
87bb3f2
Fix clang format errors
smanna12 Nov 16, 2023
8ad4686
Diagnose non-identical duplicates as a 'conflicting' loop attr and
smanna12 Nov 17, 2023
e8ce33e
Merge remote-tracking branch 'my_remote/main' into AddCodeAlignAttr
smanna12 Nov 17, 2023
ac63c62
Address review comments
smanna12 Nov 17, 2023
8fd7bc1
Fix clang format errors
smanna12 Nov 17, 2023
6a986a1
Fix crash and add dependence tests
smanna12 Nov 17, 2023
f32df3f
Address review comments
smanna12 Nov 17, 2023
d5ee5c1
Fix clang format errors
smanna12 Nov 17, 2023
6778154
Fix diagnostic issues with conflicting attributes for template cases
smanna12 Nov 20, 2023
886c03a
Fix clang format errors
smanna12 Nov 20, 2023
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
Prev Previous commit
Next Next commit
Address review comments
  • Loading branch information
smanna12 committed Nov 6, 2023
commit 22f66bd0199300a92ea2aefc66a2640e79b734a4
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10030,7 +10030,7 @@ def err_loop_attr_duplication : Error<
"duplicate loop attribute %0">;
def err_attribute_power_of_two_in_range : Error<
"%0 attribute requires an integer argument which is a constant power of two "
"between %1 and %2 inclusive - got %3">;
"between %1 and %2 inclusive; got %3">;
smanna12 marked this conversation as resolved.
Show resolved Hide resolved

def warn_def_missing_case : Warning<"%plural{"
"1:enumeration value %1 not explicitly handled in switch|"
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/CodeGen/CGLoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,10 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
// Identify loop attribute 'code_align' from Attrs.
// For attribute code_align:
// n - 'llvm.loop.align i32 n' metadata will be emitted.
for (const auto *A : Attrs) {
if (const auto *CodeAlign = dyn_cast<CodeAlignAttr>(A)) {
const auto *CE = cast<ConstantExpr>(CodeAlign->getAlignment());
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
setCodeAlign(ArgVal.getSExtValue());
}
if (const auto *CodeAlign = getSpecificAttr<const CodeAlignAttr>(Attrs)) {
const auto *CE = cast<ConstantExpr>(CodeAlign->getAlignment());
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
setCodeAlign(ArgVal.getSExtValue());
}

setMustProgress(MustProgress);
Expand Down
10 changes: 2 additions & 8 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,11 @@ CodeAlignAttr *Sema::BuildCodeAlignAttr(const AttributeCommonInfo &CI,
return nullptr;
E = Res.get();

// This attribute requires a strictly positive value.
if (ArgVal <= 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< CI << /*positive*/ 0;
return nullptr;
}

// This attribute requires an integer argument which is a constant power of
// two between 1 and 4096 inclusive.
int AlignValue = ArgVal.getSExtValue();
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
if (AlignValue > CodeAlignAttr::getMaxValue() || !ArgVal.isPowerOf2()) {
if (AlignValue < CodeAlignAttr::getMinValue() ||
AlignValue > CodeAlignAttr::getMaxValue() || !ArgVal.isPowerOf2()) {
Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
<< CI << CodeAlignAttr::getMinValue() << CodeAlignAttr::getMaxValue()
<< AlignValue;
Expand Down
10 changes: 5 additions & 5 deletions clang/test/Sema/code_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ void bar(int);
// cpp-local-note@+1 {{declared here}}
void foo1(int A)
{
// expected-error@+1 {{'code_align' attribute requires a positive integral compile time constant expression}}
// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got 0}}
[[clang::code_align(0)]]
for(int I=0; I<128; ++I) { bar(I); }

// expected-error@+1 {{'code_align' attribute requires a positive integral compile time constant expression}}
// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got -4}}
[[clang::code_align(-4)]]
for(int I=0; I<128; ++I) { bar(I); }

Expand Down Expand Up @@ -58,11 +58,11 @@ void foo1(int A)
[[clang::code_align(64)]] // expected-error {{duplicate loop attribute 'code_align'}}
for(int I=0; I<128; ++I) { bar(I); }

// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive - got 7}}
// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got 7}}
[[clang::code_align(7)]]
for(int I=0; I<128; ++I) { bar(I); }

// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive - got 5000}}
// expected-error@+1 {{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got 5000}}
[[clang::code_align(5000)]]
for(int I=0; I<128; ++I) { bar(I); }

Expand Down Expand Up @@ -103,7 +103,7 @@ void code_align_dependent() {
[[clang::code_align(B)]] // cpp-local-error {{duplicate loop attribute 'code_align'}}
for(int I=0; I<128; ++I) { bar(I); }

// cpp-local-error@+2{{'code_align' attribute requires a positive integral compile time constant expression}}
// cpp-local-error@+2{{'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got -10}}
// cpp-local-note@#neg-instantiation {{in instantiation of function template specialization}}
[[clang::code_align(D)]]
for(int I=0; I<128; ++I) { bar(I); }
Expand Down