-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Add builtin_setjmp codegen support #1842
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
83b80ea
Add builtin_setjmp support
badumbatish 160d9f3
Addresses PR reviews
badumbatish b2bf471
Add failing test for systemz setjmp longjmp, rename test case
badumbatish 5f0f4b6
Reuse dedicated ops, address PR reviews
badumbatish 30d6fa7
Update CGOG, add stricter flag check, resolve PR reviews
badumbatish b982e57
Replicate OG behavior, defer to predefinedlib codegen, update test
badumbatish 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -fclangir -emit-llvm %s -o %t.ll | ||
| // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM | ||
badumbatish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -emit-llvm %s -o %t.ll | ||
| // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG | ||
| void test_setjmp(void *env) { | ||
|
|
||
| // CIR-LABEL: test_setjmp | ||
| // CIR-SAME: [[ENV:%.*]]: | ||
| // CIR-NEXT: [[ENV_ALLOCA:%[0-9]+]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, | ||
| // CIR-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // CIR-NEXT: [[ENV_LOAD:%[0-9]+]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // CIR-NEXT: [[CAST:%[0-9]+]] = cir.cast(bitcast, [[ENV_LOAD]] : !cir.ptr<!void>), !cir.ptr<!cir.ptr<!void>> | ||
| // CIR-NEXT: [[ZERO:%[0-9]+]] = cir.const #cir.int<0> | ||
| // CIR-NEXT: [[FA:%[0-9]+]] = cir.frame_address([[ZERO]]) | ||
| // CIR-NEXT: cir.store [[FA]], [[CAST]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // CIR-NEXT: [[SS:%[0-9]+]] = cir.stack_save | ||
| // CIR-NEXT: [[TWO:%[0-9]+]] = cir.const #cir.int<2> | ||
| // CIR-NEXT: [[GEP:%[0-9]+]] = cir.ptr_stride([[CAST]] : !cir.ptr<!cir.ptr<!void>>, [[TWO]] : !s32i), | ||
| // CIR-NEXT: cir.store [[SS]], [[GEP]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // CIR-NEXT: [[SJ:%[0-9]+]] = cir.llvm.intrinsic "eh.sjlj.setjmp" [[CAST]] | ||
|
|
||
|
|
||
| // LLVM-LABEL: test_setjmp | ||
| // LLVM-SAME: (ptr{{.*}}[[ENV:%.*]]) | ||
| // LLVM-NEXT: [[FA:%[0-9]+]] = {{.*}}@llvm.frameaddress.p0(i32 0) | ||
| // LLVM-NEXT: store ptr [[FA]], ptr [[ENV]] | ||
| // LLVM-NEXT: [[SS:%[0-9]+]] = {{.*}}@llvm.stacksave.p0() | ||
| // LLVM-NEXT: [[GEP:%[0-9]+]] = getelementptr i8, ptr [[ENV]], i64 16 | ||
| // LLVM-NEXT: store ptr [[SS]], ptr [[GEP]] | ||
| // LLVM-NEXT: @llvm.eh.sjlj.setjmp(ptr{{.*}}[[ENV]]) | ||
|
|
||
| // OGCG-LABEL: test_setjmp | ||
| // OGCG-SAME: (ptr{{.*}}[[ENV:%.*]]) | ||
| // OGCG: [[FA:%.*]] = {{.*}}@llvm.frameaddress.p0(i32 0) | ||
| // OGCG-NEXT: store ptr [[FA]], ptr [[ENV]] | ||
| // OGCG-NEXT: [[SS:%.*]] = {{.*}}@llvm.stacksave.p0() | ||
| // OGCG-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw i8, ptr [[ENV]], i64 16 | ||
| // OGCG-NEXT: store ptr [[SS]], ptr [[GEP]] | ||
| // OGCG-NEXT: @llvm.eh.sjlj.setjmp(ptr{{.*}}[[ENV]]) | ||
| __builtin_setjmp(env); | ||
| } | ||
|
|
||
| extern int _setjmp(void *env); | ||
| void test_setjmp2(void *env) { | ||
|
|
||
| // CIR-LABEL: test_setjmp2 | ||
| // CIR-SAME: [[ENV:%.*]]: !cir.ptr<!void> | ||
| // CIR-NEXT: [[ENV_ALLOCA:%.*]] = cir.alloca | ||
| // CIR-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] | ||
| // CIR-NEXT: [[DEAD_GET_GLOBAL:%.*]] = cir.get_global @_setjmp | ||
| // CIR-NEXT: [[ENV_LOAD:%.*]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // CIR-NEXT: cir.call @_setjmp([[ENV_LOAD]]) | ||
|
|
||
| // LLVM-LABEL: test_setjmp2 | ||
| // LLVM-SAME: (ptr{{.*}}[[ENV:%.*]]) | ||
| // LLVM-NEXT: call i32 @_setjmp(ptr [[ENV]]) | ||
| // | ||
| // OGCG-LABEL: test_setjmp2 | ||
| // OGCG-SAME: (ptr{{.*}}[[ENV:%.*]]) | ||
| // OGCG: call i32 @_setjmp(ptr noundef [[ENV]]) | ||
| _setjmp (env); | ||
| } | ||
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.