-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Add support for new loop attribute [[clang::code_align()]] (#…
…70762) This patch adds support for new loop attribute: [[clang::code_align(N)]]. This attribute applies to a loop and specifies the byte alignment for a loop. The attribute accepts a positive integer constant initialization expression indicating the number of bytes for the minimum alignment boundary. Its value must be a power of 2, between 1 and 4096 (inclusive).
- Loading branch information
Showing
13 changed files
with
511 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -x c %s %s -o - | FileCheck -check-prefix=CHECK-C %s | ||
// RUN: %clang_cc1 -fsyntax-only -emit-llvm -x c++ -std=c++11 %s -o - | FileCheck %s --check-prefixes CHECK-C,CHECK-CPP | ||
|
||
// CHECK-C: br label %for.cond, !llvm.loop ![[MD_FP:[0-9]+]] | ||
// CHECK-C: br label %while.cond, !llvm.loop ![[MD_FP_1:[0-9]+]] | ||
// CHECK-C: br i1 %cmp3, label %do.body, label %do.end, !llvm.loop ![[MD_FP_2:[0-9]+]] | ||
// CHECK-C: br label %for.cond5, !llvm.loop ![[MD_FP_3:[0-9]+]] | ||
|
||
// CHECK-CPP: br label %for.cond, !llvm.loop ![[MD_FP_4:[0-9]+]] | ||
// CHECK-CPP: br label %for.cond2, !llvm.loop ![[MD_FP_5:[0-9]+]] | ||
|
||
void bar(int); | ||
void code_align() { | ||
int a[10]; | ||
// CHECK-C: ![[MD_FP]] = distinct !{![[MD_FP]], ![[MP:[0-9]+]], ![[MD_code_align:[0-9]+]]} | ||
// CHECK-C-NEXT: ![[MP]] = !{!"llvm.loop.mustprogress"} | ||
// CHECK-C-NEXT: ![[MD_code_align]] = !{!"llvm.loop.align", i32 4} | ||
[[clang::code_align(4)]] | ||
for(int I=0; I<128; ++I) { bar(I); } | ||
|
||
// CHECK-C: ![[MD_FP_1]] = distinct !{![[MD_FP_1]], ![[MP]], ![[MD_code_align_1:[0-9]+]]} | ||
// CHECK-C-NEXT: ![[MD_code_align_1]] = !{!"llvm.loop.align", i32 16} | ||
int i = 0; | ||
[[clang::code_align(16)]] while (i < 60) { | ||
a[i] += 3; | ||
} | ||
|
||
// CHECK-C: ![[MD_FP_2]] = distinct !{![[MD_FP_2]], ![[MP]], ![[MD_code_align_2:[0-9]+]]} | ||
// CHECK-C-NEXT: ![[MD_code_align_2]] = !{!"llvm.loop.align", i32 8} | ||
int b = 10; | ||
[[clang::code_align(8)]] do { | ||
b = b + 1; | ||
} while (b < 20); | ||
|
||
// CHECK-C: ![[MD_FP_3]] = distinct !{![[MD_FP_3]], ![[MP]], ![[MD_code_align_3:[0-9]+]]} | ||
// CHECK-C-NEXT: ![[MD_code_align_3]] = !{!"llvm.loop.align", i32 64} | ||
[[clang::code_align(64)]] | ||
for(int I=0; I<128; ++I) { bar(I); } | ||
} | ||
|
||
#if __cplusplus >= 201103L | ||
template <int A, int B> | ||
void code_align_cpp() { | ||
int a[10]; | ||
// CHECK-CPP: ![[MD_FP_4]] = distinct !{![[MD_FP_4]], ![[MP]], ![[MD_code_align_4:[0-9]+]]} | ||
// CHECK-CPP-NEXT: ![[MD_code_align_4]] = !{!"llvm.loop.align", i32 32} | ||
[[clang::code_align(A)]] for (int i = 0; i != 10; ++i) | ||
a[i] = 0; | ||
|
||
// CHECK-CPP: ![[MD_FP_5]] = distinct !{![[MD_FP_5]], ![[MD_code_align]]} | ||
int c[] = {0, 1, 2, 3, 4, 5}; | ||
[[clang::code_align(B)]] for (int n : c) { n *= 2; } | ||
} | ||
|
||
int main() { | ||
code_align_cpp<32, 4>(); | ||
return 0; | ||
} | ||
#endif |
Oops, something went wrong.
48ff354
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 breaks LLVM buildbots:
https://lab.llvm.org/buildbot/#/builders/245
https://lab.llvm.org/buildbot/#/builders/178
https://lab.llvm.org/buildbot/#/builders/182
https://lab.llvm.org/buildbot/#/builders/186
https://lab.llvm.org/buildbot/#/builders/187
Please fix test code_align.c which seems to be failing across the board on 32bit arm (see log below)
******************** TEST 'Clang :: Sema/code_align.c' FAILED ********************
Exit Code: 1
Command Output (stderr):
RUN: at line 1: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/18/include -nostdsysteminc -fsyntax-only -verify=expected,c-local -x c /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c
error: 'c-local-error' diagnostics expected but not seen:
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c Line 79 (directive at /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c:78): 'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; provided argument was (__int128_t)1311768467294899680ULL << 64
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c Line 89 (directive at /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c:88): 'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; provided argument was -(__int128_t)1311768467294899680ULL << 64
error: 'c-local-error' diagnostics seen but not expected:
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c Line 79: use of undeclared identifier '__int128_t'
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Sema/code_align.c Line 89: use of undeclared identifier '__int128_t'
4 errors generated.
--