-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang][LoongArch] Support target attribute for function #140700
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3195,6 +3195,17 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) { | |
| } | ||
| } | ||
|
|
||
| if (Context.getTargetInfo().getTriple().isLoongArch()) { | ||
| for (const auto &Feature : ParsedAttrs.Features) { | ||
| StringRef CurFeature = Feature; | ||
| if (CurFeature.starts_with("!arch=")) { | ||
|
||
| StringRef ArchValue = CurFeature.split("=").second.trim(); | ||
| return Diag(LiteralLoc, diag::err_attribute_unsupported) | ||
| << "target(arch=..)" << ArchValue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (ParsedAttrs.Duplicate != "") | ||
| return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) | ||
| << Duplicate << None << ParsedAttrs.Duplicate << Target; | ||
|
|
||
This file contains hidden or 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,92 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 5 | ||
| // RUN: %clang --target=loongarch64-linux-gnu %s -S -emit-llvm -o - \ | ||
| // RUN: | FileCheck %s | ||
|
|
||
| __attribute__((target("div32"))) | ||
| // CHECK-LABEL: define dso_local void @testdiv32( | ||
| // CHECK-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testdiv32() {} | ||
|
|
||
| __attribute__((target("arch=loongarch64"))) | ||
| // CHECK-LABEL: define dso_local void @testLoongarch64( | ||
| // CHECK-SAME: ) #[[ATTR1:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testLoongarch64() {} | ||
|
|
||
| __attribute__((target("arch=la64v1.0"))) | ||
| // CHECK-LABEL: define dso_local void @testLa64v10( | ||
| // CHECK-SAME: ) #[[ATTR1]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testLa64v10() {} | ||
|
|
||
| __attribute__((target("arch=la64v1.1"))) | ||
| // CHECK-LABEL: define dso_local void @testLa64v11( | ||
| // CHECK-SAME: ) #[[ATTR2:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testLa64v11() {} | ||
|
|
||
| __attribute__((target("arch=la464"))) | ||
| // CHECK-LABEL: define dso_local void @testLa464( | ||
| // CHECK-SAME: ) #[[ATTR3:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testLa464() {} | ||
|
|
||
| __attribute__((target("arch=la664"))) | ||
| // CHECK-LABEL: define dso_local void @testLa664( | ||
| // CHECK-SAME: ) #[[ATTR4:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void testLa664() {} | ||
|
|
||
| __attribute__((target("arch=la664, no-div32"))) | ||
| // CHECK-LABEL: define dso_local void @la664Nodiv32( | ||
| // CHECK-SAME: ) #[[ATTR5:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void la664Nodiv32() {} | ||
|
|
||
| __attribute__((target("tune=la464"))) | ||
| // CHECK-LABEL: define dso_local void @tuneLa464( | ||
| // CHECK-SAME: ) #[[ATTR6:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void tuneLa464() {} | ||
|
|
||
| __attribute__((target("arch=la464, tune=la664"))) | ||
| // CHECK-LABEL: define dso_local void @archLa464tuneLa664( | ||
| // CHECK-SAME: ) #[[ATTR7:[0-9]+]] { | ||
| // CHECK-NEXT: [[ENTRY:.*:]] | ||
| // CHECK-NEXT: ret void | ||
| // | ||
| void archLa464tuneLa664() {} | ||
|
|
||
| //. | ||
| // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+div32,+f,+lsx,+ual" } | ||
| // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+f,+lsx,+ual" } | ||
| // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+ld-seq-sa,+lsx,+scq,+ual" } | ||
| // CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" } | ||
| // CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual" } | ||
| // CHECK: attributes #[[ATTR5]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+64bit,+d,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual,-div32" } | ||
| // CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+f,+lsx,+ual" "tune-cpu"="la464" } | ||
| // CHECK: attributes #[[ATTR7]] = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" "tune-cpu"="la664" } | ||
| //. | ||
| // CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} | ||
| // CHECK: [[META1:![0-9]+]] = !{i32 8, !"PIC Level", i32 2} | ||
| // CHECK: [[META2:![0-9]+]] = !{i32 7, !"PIE Level", i32 2} | ||
| // CHECK: [[META3:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2} | ||
| // CHECK: [[META4:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} | ||
| //. |
This file contains hidden or 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,25 @@ | ||
| // RUN: %clang_cc1 -triple loongarch64-linux-gnu -fsyntax-only -verify %s | ||
|
|
||
| // expected-error@+1 {{function multiversioning is not supported on the current target}} | ||
| void __attribute__((target("default"))) bar(void) {} | ||
|
|
||
| // expected-error@+1 {{target(arch=..) attribute is not supported on targets missing invalid; specify an appropriate -march= or -mcpu=}} | ||
| void __attribute__((target("arch=invalid"))) foo(void) {} | ||
|
|
||
| // expected-warning@+1 {{unsupported '+div32' in the 'target' attribute string; 'target' attribute ignored}} | ||
| void __attribute__((target("+div32"))) plusfeature(void) {} | ||
|
|
||
| // expected-warning@+1 {{unsupported '-div32' in the 'target' attribute string; 'target' attribute ignored}} | ||
| void __attribute__((target("-div32"))) minusfeature(void) {} | ||
|
|
||
| // expected-warning@+1 {{unsupported 'aaa' in the 'target' attribute string; 'target' attribute ignored}} | ||
| int __attribute__((target("aaa"))) test_feature(void) { return 4; } | ||
|
|
||
| // expected-warning@+1 {{unsupported 'aaa' in the 'target' attribute string; 'target' attribute ignored}} | ||
| int __attribute__((target("no-aaa"))) test_nofeature(void) { return 4; } | ||
|
|
||
| // expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}} | ||
| int __attribute__((target("arch=la464,arch=la664"))) test_duplarch(void) { return 4; } | ||
|
|
||
| // expected-warning@+1 {{unknown tune CPU 'la64v1.0' in the 'target' attribute string; 'target' attribute ignored}} | ||
| int __attribute__((target("tune=la64v1.0"))) test_tune(void) { return 4; } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The default return may cause us to miss the check for invalid strings. (like this: "+lasx", here will be two plus signs in the generated IR) . Perhaps we can perform the check inside
isValidFeature()?"Uh oh!
There was an error while loading. Please reload this page.
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.
Appreciate the review suggestion. The validation will be handled in
isValidFeatureName(), with corresponding test cases added.Thanks!