-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BPF] introduce __attribute__((bpf_fastcall))
#101228
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
6 commits
Select commit
Hold shift + click to select a range
6a3b5c7
[BPF] introduce __attribute__((bpf_fastcall))
eddyz87 94f8b89
styling fix: remove goto in collectBPFFastCalls
eddyz87 b89fa14
test fix: use [[names]] for attributes in bpf-attr-bpf-fastcall-1
eddyz87 8f06f5b
use `Clang` syntax instead of `GCC` for bpf_fastcall
eddyz87 4bf4616
adjust Sema test case to show that bpf_fastcall is not a type attr
eddyz87 da18a35
mark bpf_fastcall as COnly attribute
eddyz87 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
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,24 @@ | ||
// REQUIRES: bpf-registered-target | ||
// RUN: %clang_cc1 -triple bpf -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s | ||
|
||
#define __bpf_fastcall __attribute__((bpf_fastcall)) | ||
|
||
void test(void) __bpf_fastcall; | ||
void (*ptr)(void) __bpf_fastcall; | ||
|
||
void foo(void) { | ||
test(); | ||
(*ptr)(); | ||
} | ||
|
||
// CHECK: @ptr = global ptr null | ||
// CHECK: define {{.*}} void @foo() | ||
// CHECK: entry: | ||
// CHECK: call void @test() #[[call_attr:[0-9]+]] | ||
// CHECK: %[[ptr:.*]] = load ptr, ptr @ptr, align 8 | ||
// CHECK: call void %[[ptr]]() #[[call_attr]] | ||
// CHECK: ret void | ||
|
||
// CHECK: declare void @test() #[[func_attr:[0-9]+]] | ||
// CHECK: attributes #[[func_attr]] = { {{.*}}"bpf_fastcall"{{.*}} } | ||
// CHECK: attributes #[[call_attr]] = { "bpf_fastcall" } |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// REQUIRES: bpf-registered-target | ||
// RUN: %clang_cc1 %s -triple bpf -verify | ||
|
||
__attribute__((bpf_fastcall)) int var; // expected-warning {{'bpf_fastcall' attribute only applies to functions and function pointers}} | ||
|
||
__attribute__((bpf_fastcall)) void func(); | ||
__attribute__((bpf_fastcall(1))) void func_invalid(); // expected-error {{'bpf_fastcall' attribute takes no arguments}} | ||
eddyz87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void (*ptr1)(void) __attribute__((bpf_fastcall)); | ||
void (*ptr2)(void); | ||
void foo(void) { | ||
ptr2 = ptr1; // not an error | ||
ptr1 = ptr2; // not an error | ||
} |
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
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
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,46 @@ | ||
; RUN: llc -O2 --march=bpfel %s -o - | FileCheck %s | ||
|
||
; Generated from the following C code: | ||
; | ||
; #define __bpf_fastcall __attribute__((bpf_fastcall)) | ||
; | ||
; void bar(void) __bpf_fastcall; | ||
; void buz(long i, long j, long k); | ||
; | ||
; void foo(long i, long j, long k) { | ||
; bar(); | ||
; buz(i, j, k); | ||
; } | ||
; | ||
; Using the following command: | ||
; | ||
; clang --target=bpf -emit-llvm -O2 -S -o - t.c | ||
; | ||
; (unnecessary attrs removed maually) | ||
|
||
; Check that function marked with bpf_fastcall does not clobber R1-R5. | ||
|
||
define dso_local void @foo(i64 noundef %i, i64 noundef %j, i64 noundef %k) { | ||
entry: | ||
tail call void @bar() #1 | ||
tail call void @buz(i64 noundef %i, i64 noundef %j, i64 noundef %k) | ||
ret void | ||
} | ||
|
||
; CHECK: foo: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: *(u64 *)(r10 - 8) = r1 | ||
; CHECK-NEXT: *(u64 *)(r10 - 16) = r2 | ||
; CHECK-NEXT: *(u64 *)(r10 - 24) = r3 | ||
; CHECK-NEXT: call bar | ||
; CHECK-NEXT: r3 = *(u64 *)(r10 - 24) | ||
; CHECK-NEXT: r2 = *(u64 *)(r10 - 16) | ||
; CHECK-NEXT: r1 = *(u64 *)(r10 - 8) | ||
; CHECK-NEXT: call buz | ||
; CHECK-NEXT: exit | ||
|
||
declare dso_local void @bar() #0 | ||
declare dso_local void @buz(i64 noundef, i64 noundef, i64 noundef) | ||
|
||
attributes #0 = { "bpf_fastcall" } | ||
attributes #1 = { nounwind "bpf_fastcall" } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.