-
Notifications
You must be signed in to change notification settings - Fork 167
[CIR][WIP] Add BlockAddressOp #1875
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
Andres-Salamanca
wants to merge
12
commits into
llvm:main
Choose a base branch
from
Andres-Salamanca:block-addr
base: main
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
686ca84
[CIR][WIP] Add BlockAddressOp
Andres-Salamanca 784f417
Fix unrealized_conversion, add description and add static variable
Andres-Salamanca 84e5806
Update Goto solver
Andres-Salamanca a729b14
Implement bookkeeping and add more tests
Andres-Salamanca cf9a871
Address some review comments
Andres-Salamanca 29f9f3b
Address some more review comments
Andres-Salamanca 6218a9b
add new line
Andres-Salamanca 7bd5b28
Add verifier for BlockAddressOp and tests
Andres-Salamanca f2efb15
move verifier logic to FuncOp
Andres-Salamanca 68108e6
Add tests for goto-solver
Andres-Salamanca 8c51d1e
Apply reviews
Andres-Salamanca d7e72d3
Format code
Andres-Salamanca 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
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,74 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR | ||
|
||
void A(void) { | ||
void *ptr = &&A; | ||
A: | ||
return; | ||
} | ||
// CIR: cir.func dso_local @A | ||
// CIR: [[PTR:%.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64} | ||
// CIR: [[BLOCK:%.*]] = cir.blockaddress(@A, "A") -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) [[BLOCK]], [[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: cir.br ^bb1 | ||
// CIR: ^bb1: // pred: ^bb0 | ||
// CIR: cir.label "A" | ||
// CIR: cir.return | ||
|
||
void B(void) { | ||
B: | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void *ptr = &&B; | ||
} | ||
|
||
// CIR: cir.func dso_local @B() | ||
// CIR: cir.label "B" | ||
// CIR: [[PTR:%.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64} | ||
// CIR: [[BLOCK:%.*]] = cir.blockaddress(@B, "B") -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) [[BLOCK]], [[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: cir.return | ||
|
||
void C(int x) { | ||
void *ptr = (x == 0) ? &&A : &&B; | ||
A: | ||
return; | ||
B: | ||
return; | ||
} | ||
|
||
// CIR: cir.func dso_local @C | ||
// CIR: [[BLOCK1:%.*]] = cir.blockaddress(@C, "A") -> !cir.ptr<!void> | ||
// CIR: [[BLOCK2:%.*]] = cir.blockaddress(@C, "B") -> !cir.ptr<!void> | ||
// CIR: [[COND:%.*]] = cir.select if [[CMP:%.*]] then [[BLOCK1]] else [[BLOCK2]] : (!cir.bool, !cir.ptr<!void>, !cir.ptr<!void>) -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) [[COND]], [[PTR:%.*]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: cir.br ^bb2 | ||
// CIR: ^bb1: // 2 preds: ^bb2, ^bb3 | ||
// CIR: cir.return | ||
// CIR: ^bb2: // pred: ^bb0 | ||
// CIR: cir.label "A" | ||
// CIR: cir.br ^bb1 | ||
// CIR: ^bb3: // no predecessors | ||
// CIR: cir.label "B" | ||
// CIR: cir.br ^bb1 | ||
|
||
void D(void) { | ||
void *ptr = &&A; | ||
void *ptr2 = &&A; | ||
A: | ||
void *ptr3 = &&A; | ||
return; | ||
} | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CIR: cir.func dso_local @D | ||
// CIR: %[[PTR:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] | ||
// CIR: %[[PTR2:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr2", init] | ||
// CIR: %[[PTR3:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr3", init] | ||
// CIR: %[[BLK1:.*]] = cir.blockaddress(@D, "A") -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) %[[BLK1]], %[[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: %[[BLK2:.*]] = cir.blockaddress(@D, "A") -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) %[[BLK2]], %[[PTR2]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: cir.br ^bb1 | ||
// CIR: ^bb1: // pred: ^bb0 | ||
// CIR: cir.label "A" | ||
// CIR: %[[BLK3:.*]] = cir.blockaddress(@D, "A") -> !cir.ptr<!void> | ||
// CIR: cir.store align(8) %[[BLK3]], %[[PTR3]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CIR: cir.return |
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,34 @@ | ||
// RUN: cir-opt %s | cir-opt | FileCheck %s | ||
|
||
!void = !cir.void | ||
|
||
module { | ||
cir.func @block_address(){ | ||
%0 = cir.blockaddress(@block_address, "label") -> !cir.ptr<!void> | ||
cir.br ^bb1 | ||
^bb1: | ||
cir.label "label" | ||
cir.return | ||
} | ||
// CHECK: cir.func @block_address | ||
// CHECK: %0 = cir.blockaddress(@block_address, "label") -> !cir.ptr<!void> | ||
// CHECK: cir.br ^bb1 | ||
// CHECK: ^bb1: | ||
// CHECK: cir.label "label" | ||
// CHECK: cir.return | ||
|
||
cir.func @block_address_inside_scope() -> () { | ||
cir.scope{ | ||
%0 = cir.blockaddress(@block_address_inside_scope, "label") -> !cir.ptr<!void> | ||
} | ||
cir.br ^bb1 | ||
^bb1: | ||
cir.label "label" | ||
cir.return | ||
} | ||
// CHECK: cir.func @block_address_inside_scope | ||
// CHECK: cir.scope | ||
// CHECK: %0 = cir.blockaddress(@block_address_inside_scope, "label") -> !cir.ptr<!void> | ||
// CHECK: cir.label "label" | ||
// CHECK: cir.return | ||
} |
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,21 @@ | ||
// RUN: cir-opt %s -verify-diagnostics -split-input-file | ||
|
||
!void = !cir.void | ||
|
||
// expected-error@+1 {{expects an existing label target in the referenced function}} | ||
cir.func @bad_block_address() -> () { | ||
%0 = cir.blockaddress(@bad_block_address, "label") -> !cir.ptr<!void> | ||
cir.br ^bb1 | ||
^bb1: | ||
cir.label "wrong_label" | ||
cir.return | ||
} | ||
|
||
// expected-error@+1 {{blockaddress references a different function}} | ||
cir.func @bad_block_func() -> () { | ||
%0 = cir.blockaddress(@mismatch_func, "label") -> !cir.ptr<!void> | ||
cir.br ^bb1 | ||
^bb1: | ||
cir.label "label" | ||
cir.return | ||
} |
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,63 @@ | ||
// RUN: cir-opt %s -cir-goto-solver -o - | FileCheck %s | ||
|
||
!void = !cir.void | ||
|
||
cir.func @a(){ | ||
%0 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64} | ||
%1 = cir.blockaddress(@a, "label1") -> !cir.ptr<!void> | ||
cir.store align(8) %1, %0 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
cir.br ^bb1 | ||
^bb1: | ||
cir.label "label1" | ||
cir.br ^bb2 | ||
^bb2: | ||
// This label is not referenced by any blockaddressOp, so it should be removed | ||
cir.label "label2" | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @a() | ||
// CHECK: %1 = cir.blockaddress(@a, "label1") -> !cir.ptr<!void> | ||
// CHECK: ^bb1: | ||
// CHECK: cir.label "label1" | ||
// CHECK: cir.br ^bb2 | ||
// CHECK: ^bb2: | ||
// CHECK-NOT: cir.label "label2" | ||
|
||
cir.func @b(){ | ||
%0 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64} | ||
%1 = cir.blockaddress(@b, "label1") -> !cir.ptr<!void> | ||
cir.store align(8) %1, %0 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
cir.goto "label2" | ||
^bb1: | ||
cir.label "label1" | ||
cir.br ^bb2 | ||
^bb2: | ||
// This label is not referenced by any blockaddressOp, so it should be removed | ||
cir.label "label2" | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @b() { | ||
// CHECK: %1 = cir.blockaddress(@b, "label1") -> !cir.ptr<!void> | ||
// CHECK: cir.store align(8) %1, {{.*}} : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
// CHECK: cir.br ^bb2 | ||
// CHECK: ^bb1: | ||
// CHECK: cir.label "label1" | ||
// CHECK: cir.br ^bb2 | ||
// CHECK: ^bb2: | ||
// CHECK-NOT: cir.label "label2" | ||
|
||
cir.func @c() { | ||
cir.label "label1" | ||
%0 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64} | ||
%1 = cir.blockaddress(@c, "label1") -> !cir.ptr<!void> | ||
cir.store align(8) %1, %0 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @c | ||
// CHECK: cir.label "label1" | ||
// CHECK: %1 = cir.blockaddress(@c, "label1") -> !cir.ptr<!void> | ||
// CHECK: cir.store align(8) %1, {{.*}} : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> | ||
|
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.