-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[CIR] Add CIR vtable attribute #154415
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
[CIR] Add CIR vtable attribute #154415
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5e0612
[CIR] Add CIR vtable attribute
andykaylor d37efd2
Address review feedback
andykaylor 98c808f
Use range for vtable data verification
andykaylor 32180c9
Add multi-vtable test
andykaylor 1736a32
One more test case
andykaylor 6f96418
Rename vtable_data to data
andykaylor 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -496,6 +496,72 @@ def CIR_GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [ | |
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // VTableAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> { | ||
| let summary = "Represents a C++ vtable"; | ||
| let description = [{ | ||
| Wraps a #cir.const_record containing one or more vtable arrays. | ||
|
|
||
| In most cases, the anonymous record type wrapped by this attribute will | ||
| contain a single array corresponding to the vtable for one class. However, | ||
| in the case of multiple inheritence, the anonymous structure may contain | ||
| multiple arrays, each of which is a vtable. | ||
|
|
||
| Example 1 (single vtable): | ||
| ```mlir | ||
| cir.global linkonce_odr @_ZTV6Mother = | ||
| #cir.vtable<{ | ||
| #cir.const_array<[ | ||
| #cir.ptr<null> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZN6Mother9MotherFooEv> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i> | ||
| ]> : !cir.array<!cir.ptr<!u8i> x 4> | ||
| }> : !rec_anon_struct1 | ||
| ``` | ||
|
|
||
| Example 2 (multiple vtables): | ||
| ```mlir | ||
| cir.global linkonce_odr @_ZTV5Child = | ||
| #cir.vtable<{ | ||
| #cir.const_array<[ | ||
| #cir.ptr<null> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZN5Child9MotherFooEv> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i> | ||
| ]> : !cir.array<!cir.ptr<!u8i> x 4>, | ||
| #cir.const_array<[ | ||
| #cir.ptr<-8 : i64> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>, | ||
| #cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i> | ||
| ]> : !cir.array<!cir.ptr<!u8i> x 3> | ||
| }> : !rec_anon_struct2 | ||
| ``` | ||
| }]; | ||
|
|
||
| // `vtable_data` is a const record with one element, containing an array of | ||
| // vtable information. | ||
| let parameters = (ins | ||
| AttributeSelfTypeParameter<"">:$type, | ||
| "mlir::ArrayAttr":$vtable_data | ||
|
||
| ); | ||
|
|
||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "mlir::Type":$type, | ||
| "mlir::ArrayAttr":$vtable_data), [{ | ||
| return $_get(type.getContext(), type, vtable_data); | ||
| }]> | ||
| ]; | ||
|
|
||
| let genVerifyDecl = 1; | ||
| let assemblyFormat = [{ | ||
| `<` custom<RecordMembers>($vtable_data) `>` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ConstComplexAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
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,19 @@ | ||
| // RUN: cir-opt %s | FileCheck %s | ||
|
|
||
| !rec_Q = !cir.record<struct "Q" {!cir.vptr}> | ||
| !rec_S = !cir.record<struct "S" {!cir.vptr}> | ||
| !rec_S2 = !cir.record<struct "S2" {!rec_Q, !rec_S}> | ||
| !u8i = !cir.int<u, 8> | ||
| !rec_anon_struct = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>}> | ||
| !rec_anon_struct1 = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>, !cir.array<!cir.ptr<!u8i> x 3>}> | ||
| module { | ||
| cir.global external @_ZTV1S = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S3keyEv> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S6nonKeyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 4>}> : !rec_anon_struct {alignment = 8 : i64} | ||
| // CHECK: cir.global external @_ZTV1S = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S3keyEv> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S6nonKeyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 4>}> : !rec_anon_struct {alignment = 8 : i64} | ||
|
|
||
| cir.global external @_ZTV2S2 = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S3keyEv> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S6nonKeyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 4>, #cir.const_array<[#cir.ptr<-8 : i64> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN2S23keyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 3>}> : !rec_anon_struct1 {alignment = 8 : i64} | ||
| // CHECK: cir.global external @_ZTV2S2 = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S3keyEv> : !cir.ptr<!u8i>, #cir.global_view<@_ZN1S6nonKeyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 4>, #cir.const_array<[#cir.ptr<-8 : i64> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN2S23keyEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 3>}> : !rec_anon_struct1 {alignment = 8 : i64} | ||
|
|
||
| cir.func private dso_local @_ZN1S3keyEv(%arg0: !cir.ptr<!rec_S>) | ||
| cir.func private dso_local @_ZN1S6nonKeyEv(%arg0: !cir.ptr<!rec_S>) | ||
| cir.func private dso_local @_ZN2S23keyEv(%arg0: !cir.ptr<!rec_S2>) | ||
| } |
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.
Same here, it is not const_record but ArrayAttr?
Wasn't the intent to say
vtable_datais a single element of vtable const record?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.
As mentioned above, there can be multiple arrays. I'll update this comment to reflect that and add an example with two arrays.