-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Add GlobalOp ctor and dtor regions #160779
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // RUN: cir-opt --verify-roundtrip %s -o - | FileCheck %s | ||
|
|
||
| !u8i = !cir.int<u, 8> | ||
|
|
||
| !rec_NeedsCtor = !cir.record<struct "NeedsCtor" padded {!u8i}> | ||
| !rec_NeedsDtor = !cir.record<struct "NeedsDtor" padded {!u8i}> | ||
| !rec_NeedsCtorDtor = !cir.record<struct "NeedsCtorDtor" padded {!u8i}> | ||
|
|
||
| module attributes {cir.triple = "x86_64-unknown-linux-gnu"} { | ||
| cir.func private @_ZN9NeedsCtorC1Ev(!cir.ptr<!rec_NeedsCtor>) | ||
| cir.global external @needsCtor = ctor : !rec_NeedsCtor { | ||
| %0 = cir.get_global @needsCtor : !cir.ptr<!rec_NeedsCtor> | ||
| cir.call @_ZN9NeedsCtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtor>) -> () | ||
| } | ||
| // CHECK: cir.global external @needsCtor = ctor : !rec_NeedsCtor { | ||
| // CHECK: %0 = cir.get_global @needsCtor : !cir.ptr<!rec_NeedsCtor> | ||
| // CHECK: cir.call @_ZN9NeedsCtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtor>) -> () | ||
| // CHECK: } | ||
|
|
||
| cir.func private @_ZN9NeedsDtorD1Ev(!cir.ptr<!rec_NeedsDtor>) | ||
| cir.global external dso_local @needsDtor = #cir.zero : !rec_NeedsDtor dtor { | ||
| %0 = cir.get_global @needsDtor : !cir.ptr<!rec_NeedsDtor> | ||
| cir.call @_ZN9NeedsDtorD1Ev(%0) : (!cir.ptr<!rec_NeedsDtor>) -> () | ||
| } | ||
| // CHECK: cir.global external dso_local @needsDtor = #cir.zero : !rec_NeedsDtor dtor { | ||
| // CHECK: %0 = cir.get_global @needsDtor : !cir.ptr<!rec_NeedsDtor> | ||
| // CHECK: cir.call @_ZN9NeedsDtorD1Ev(%0) : (!cir.ptr<!rec_NeedsDtor>) -> () | ||
| // CHECK: } | ||
|
|
||
| cir.func private @_ZN13NeedsCtorDtorC1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| cir.func private @_ZN13NeedsCtorDtorD1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| cir.global external dso_local @needsCtorDtor = ctor : !rec_NeedsCtorDtor { | ||
| %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| cir.call @_ZN13NeedsCtorDtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| } dtor { | ||
| %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| cir.call @_ZN13NeedsCtorDtorD1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| } | ||
| // CHECK: cir.func private @_ZN13NeedsCtorDtorC1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| // CHECK: cir.func private @_ZN13NeedsCtorDtorD1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| // CHECK: cir.global external dso_local @needsCtorDtor = ctor : !rec_NeedsCtorDtor { | ||
| // CHECK: %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| // CHECK: cir.call @_ZN13NeedsCtorDtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| // CHECK: } dtor { | ||
| // CHECK: %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| // CHECK: cir.call @_ZN13NeedsCtorDtorD1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| // CHECK: } | ||
| } |
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,51 @@ | ||
| // RUN: cir-opt %s -verify-diagnostics -split-input-file | ||
|
|
||
| !u8i = !cir.int<u, 8> | ||
| !rec_NeedsCtor = !cir.record<struct "NeedsCtor" padded {!u8i}> | ||
|
|
||
| module { | ||
| cir.global external @needsCtor = ctor : !rec_NeedsCtor { | ||
| } | ||
| // expected-error@+1 {{custom op 'cir.global' ctor region must have exactly one block}} | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| !u8i = !cir.int<u, 8> | ||
| !rec_NeedsCtor = !cir.record<struct "NeedsCtor" padded {!u8i}> | ||
|
|
||
| module { | ||
| cir.func private @_ZN9NeedsCtorC1Ev(!cir.ptr<!rec_NeedsCtor>) | ||
| cir.global external @needsCtor = ctor : !rec_NeedsCtor { | ||
| ^bb1: | ||
| } | ||
| // expected-error@+1 {{custom op 'cir.global' ctor region shall not be empty}} | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| !u8i = !cir.int<u, 8> | ||
| !rec_NeedsCtorDtor = !cir.record<struct "NeedsCtorDtor" padded {!u8i}> | ||
| module { | ||
| cir.func private @_ZN13NeedsCtorDtorC1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| cir.global external dso_local @needsCtorDtor = ctor : !rec_NeedsCtorDtor { | ||
| %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| cir.call @_ZN13NeedsCtorDtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| } dtor {} | ||
| // expected-error@+1 {{custom op 'cir.global' dtor region must have exactly one block}} | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| !u8i = !cir.int<u, 8> | ||
| !rec_NeedsCtorDtor = !cir.record<struct "NeedsCtorDtor" padded {!u8i}> | ||
| module { | ||
| cir.func private @_ZN13NeedsCtorDtorC1Ev(!cir.ptr<!rec_NeedsCtorDtor>) | ||
| cir.global external dso_local @needsCtorDtor = ctor : !rec_NeedsCtorDtor { | ||
| %0 = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> | ||
| cir.call @_ZN13NeedsCtorDtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () | ||
| } dtor { | ||
| ^bb1: | ||
| } | ||
| // expected-error@+1 {{custom op 'cir.global' dtor region shall not be empty}} | ||
| } | ||
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.
This error is actually emitted by the parser. If we don't report this error, the parser will implicitly create a block with a yield statement for this case. which would be acceptable to the verifier. I'm not sure we actually need to reject this as ill-formed CIR.
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.
I think you are right, there's no good reason.
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.
The same reasoning applies to the "shall not be empty" checks. So I think I can remove this entire test and the changes to GlobalOp::verify(). Because the parser implicitly creates a yield instruction, it won't be possible to test the case of an empty region.
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.
Agreed, sounds good!