-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang][CodeGen] Implement code generation for __builtin_infer_alloc_token() #156842
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
Open
melver
wants to merge
2
commits into
users/melver/spr/main.clangcodegen-implement-code-generation-for-__builtin_infer_alloc_token
Choose a base branch
from
users/melver/spr/alloctoken-clang-implement-__builtin_alloc_token_infer-and-llvmalloctokenid
base: users/melver/spr/main.clangcodegen-implement-code-generation-for-__builtin_infer_alloc_token
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−22
Open
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
Some comments aren't visible on the classic Files Changed page.
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
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,77 @@ | ||
// To test IR generation of the builtin without evaluating the LLVM intrinsic, | ||
// we set the mode to a stateful mode, which prohibits constant evaluation. | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -Werror -std=c++20 -emit-llvm -falloc-token-mode=random -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-CODEGEN | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -Werror -std=c++20 -emit-llvm -falloc-token-max=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LOWER | ||
|
||
extern "C" void *my_malloc(unsigned long, unsigned long); | ||
|
||
struct NoPtr { | ||
int x; | ||
long y; | ||
}; | ||
|
||
struct WithPtr { | ||
int a; | ||
char *buf; | ||
}; | ||
|
||
int unevaluated_fn(); | ||
|
||
// CHECK-LABEL: @_Z16test_builtin_intv( | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_INT:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 0 | ||
unsigned long test_builtin_int() { | ||
return __builtin_infer_alloc_token(sizeof(1)); | ||
} | ||
|
||
// CHECK-LABEL: @_Z16test_builtin_ptrv( | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_PTR:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 1 | ||
unsigned long test_builtin_ptr() { | ||
return __builtin_infer_alloc_token(sizeof(int *)); | ||
} | ||
|
||
// CHECK-LABEL: @_Z25test_builtin_struct_noptrv( | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_NOPTR:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 0 | ||
unsigned long test_builtin_struct_noptr() { | ||
return __builtin_infer_alloc_token(sizeof(NoPtr)); | ||
} | ||
|
||
// CHECK-LABEL: @_Z25test_builtin_struct_w_ptrv( | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_WITHPTR:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 1 | ||
unsigned long test_builtin_struct_w_ptr() { | ||
return __builtin_infer_alloc_token(sizeof(WithPtr), 123); | ||
} | ||
|
||
// CHECK-LABEL: @_Z24test_builtin_unevaluatedv( | ||
// CHECK-NOT: call{{.*}}unevaluated_fn | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_INT:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 0 | ||
unsigned long test_builtin_unevaluated() { | ||
return __builtin_infer_alloc_token(sizeof(int) * unevaluated_fn()); | ||
} | ||
|
||
// CHECK-LABEL: @_Z36test_builtin_unsequenced_unevaluatedi( | ||
// CHECK: add nsw | ||
// CHECK-NOT: add nsw | ||
// CHECK-CODEGEN: %[[REG:[0-9]+]] = call i64 @llvm.alloc.token.id.i64(metadata ![[META_UNKNOWN:[0-9]+]]) | ||
// CHECK-CODEGEN: call{{.*}}@my_malloc({{.*}}, i64 noundef %[[REG]]) | ||
// CHECK-LOWER: call{{.*}}@my_malloc({{.*}}, i64 noundef 0) | ||
void test_builtin_unsequenced_unevaluated(int x) { | ||
my_malloc(++x, __builtin_infer_alloc_token(++x)); | ||
} | ||
|
||
// CHECK-LABEL: @_Z20test_builtin_unknownv( | ||
// CHECK-CODEGEN: call i64 @llvm.alloc.token.id.i64(metadata ![[META_UNKNOWN:[0-9]+]]) | ||
// CHECK-LOWER: ret i64 0 | ||
unsigned long test_builtin_unknown() { | ||
return __builtin_infer_alloc_token(4096); | ||
} | ||
|
||
// CHECK-CODEGEN: ![[META_INT]] = !{!"int", i1 false} | ||
// CHECK-CODEGEN: ![[META_PTR]] = !{!"int *", i1 true} | ||
// CHECK-CODEGEN: ![[META_NOPTR]] = !{!"NoPtr", i1 false} | ||
// CHECK-CODEGEN: ![[META_WITHPTR]] = !{!"WithPtr", i1 true} | ||
// CHECK-CODEGEN: ![[META_UNKNOWN]] = !{} |
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.
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.
add tests with templates here too?