-
Notifications
You must be signed in to change notification settings - Fork 183
[CIR] Add dedicated CIR op for setjmp #1853
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 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b691563
Add dedicated CIR op for setjmp
badumbatish 25d4a91
Added prepare lowering test, add new docs
badumbatish c372303
Updated description for op, use better getter
badumbatish 8dff477
Update description again. Replace codegen with eh.setjmp
badumbatish 4b1377a
Update _setjmp() codgen and test case
badumbatish faab72c
Fix bug in unit test, address formatting from PR reviews
badumbatish 14a63b2
Resolve PR comments
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
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,28 @@ | ||
| // RUN: cir-opt %s -cir-to-llvm -o %t.ll | ||
| // RUN: FileCheck %s --input-file=%t.ll -check-prefix=MLIR | ||
| !s32i = !cir.int<s, 32> | ||
| !p32 = !cir.ptr<!s32i> | ||
|
|
||
| module { | ||
| // MLIR: module { | ||
| cir.func @test_setjmp(%arg0 : !p32) -> !s32i { | ||
|
|
||
| // MLIR: llvm.func @test_setjmp([[ARG0:%.*]]: !llvm.ptr) -> i32 | ||
| // MLIR-NEXT: [[RET:%.*]] = llvm.call_intrinsic "llvm.eh.sjlj.setjmp"([[ARG0]]) : (!llvm.ptr) -> i32 | ||
| // MLIR-NEXT: llvm.return [[RET:%.*]] : i32 | ||
| // MLIR-NEXT: } | ||
| %0 = cir.eh.setjmp %arg0 : !p32, builtin -> !s32i | ||
| cir.return %0 : !s32i | ||
| } | ||
| cir.func @test_setjmp_2(%arg0 : !p32) -> !s32i { | ||
|
|
||
| // MLIR: llvm.func @test_setjmp_2([[ARG0:%.*]]: !llvm.ptr) -> i32 | ||
| // MLIR-NEXT: [[RET:%.*]] = llvm.call @_setjmp([[ARG0]]) : (!llvm.ptr) -> i32 | ||
| // MLIR-NEXT: llvm.return [[RET:%.*]] : i32 | ||
| // MLIR-NEXT: } | ||
| %0 = cir.eh.setjmp %arg0 : !p32 -> !s32i | ||
| cir.return %0 : !s32i | ||
| } | ||
| // MLIR: } | ||
| } | ||
|
|
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,54 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o - 2>&1 | FileCheck %s -check-prefix=BEFORE-LOWERING-PREPARE | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-lowering-prepare %s -o - 2>&1 | FileCheck %s -check-prefix=AFTER-LOWERING-PREPARE | ||
| void test_setjmp(void *env) { | ||
| // BEFORE-LOWERING-PREPARE-LABEL: test_setjmp | ||
| // BEFORE-LOWERING-PREPARE-SAME: [[ENV:%.*]]: | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[ENV_ALLOCA:%[0-9]+]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, | ||
| // BEFORE-LOWERING-PREPARE-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[ENV_LOAD:%[0-9]+]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[CAST:%[0-9]+]] = cir.cast(bitcast, [[ENV_LOAD]] : !cir.ptr<!void>), !cir.ptr<!cir.ptr<!void>> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[ZERO:%[0-9]+]] = cir.const #cir.int<0> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[FA:%[0-9]+]] = cir.frame_address([[ZERO]]) | ||
| // BEFORE-LOWERING-PREPARE-NEXT: cir.store [[FA]], [[CAST]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[SS:%[0-9]+]] = cir.stack_save | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[TWO:%[0-9]+]] = cir.const #cir.int<2> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[GEP:%[0-9]+]] = cir.ptr_stride([[CAST]] : !cir.ptr<!cir.ptr<!void>>, [[TWO]] : !s32i), | ||
| // BEFORE-LOWERING-PREPARE-NEXT: cir.store [[SS]], [[GEP]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[SJ:%[0-9]+]] = cir.llvm.intrinsic "eh.sjlj.setjmp" [[CAST]] | ||
|
|
||
| // AFTER-LOWERING-PREPARE-LABEL: test_setjmp | ||
| // AFTER-LOWERING-PREPARE-SAME: [[ENV:%.*]]: | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[ENV_ALLOCA:%[0-9]+]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, | ||
| // AFTER-LOWERING-PREPARE-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[ENV_LOAD:%[0-9]+]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[CAST:%[0-9]+]] = cir.cast(bitcast, [[ENV_LOAD]] : !cir.ptr<!void>), !cir.ptr<!cir.ptr<!void>> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[ZERO:%[0-9]+]] = cir.const #cir.int<0> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[FA:%[0-9]+]] = cir.frame_address([[ZERO]]) | ||
| // AFTER-LOWERING-PREPARE-NEXT: cir.store [[FA]], [[CAST]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[SS:%[0-9]+]] = cir.stack_save | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[TWO:%[0-9]+]] = cir.const #cir.int<2> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[GEP:%[0-9]+]] = cir.ptr_stride([[CAST]] : !cir.ptr<!cir.ptr<!void>>, [[TWO]] : !s32i), | ||
| // AFTER-LOWERING-PREPARE-NEXT: cir.store [[SS]], [[GEP]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[SJ:%[0-9]+]] = cir.llvm.intrinsic "eh.sjlj.setjmp" [[CAST]] | ||
| __builtin_setjmp(env); | ||
| } | ||
|
|
||
| extern int _setjmp(void *env); | ||
| void test_setjmp2(void *env) { | ||
| // BEFORE-LOWERING-PREPARE-LABEL: test_setjmp2 | ||
| // BEFORE-LOWERING-PREPARE-SAME: [[ENV:%.*]]: !cir.ptr<!void> | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[ENV_ALLOCA:%.*]] = cir.alloca | ||
| // BEFORE-LOWERING-PREPARE-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[DEAD_GET_GLOBAL:%.*]] = cir.get_global @_setjmp | ||
| // BEFORE-LOWERING-PREPARE-NEXT: [[ENV_LOAD:%.*]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // BEFORE-LOWERING-PREPARE-NEXT: cir.call @_setjmp([[ENV_LOAD]]) | ||
|
|
||
| // AFTER-LOWERING-PREPARE-LABEL: test_setjmp2 | ||
| // AFTER-LOWERING-PREPARE-SAME: [[ENV:%.*]]: !cir.ptr<!void> | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[ENV_ALLOCA:%.*]] = cir.alloca | ||
| // AFTER-LOWERING-PREPARE-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]] | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[DEAD_GET_GLOBAL:%.*]] = cir.get_global @_setjmp | ||
| // AFTER-LOWERING-PREPARE-NEXT: [[ENV_LOAD:%.*]] = cir.load align(8) [[ENV_ALLOCA]] | ||
| // AFTER-LOWERING-PREPARE-NEXT: cir.call @_setjmp([[ENV_LOAD]]) | ||
| _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.