-
Notifications
You must be signed in to change notification settings - Fork 792
Update J2CLItableMerging to consider custom descriptors #7729
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -104,20 +104,33 @@ struct J2CLItableMerging : public Pass { | |||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
auto type = heapType.getStruct(); | ||||||||||
if (typeNameInfo.fieldNames.empty() || | ||||||||||
!typeNameInfo.fieldNames[0].equals("vtable")) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
if (typeNameInfo.fieldNames.size() < 1 || | ||||||||||
!typeNameInfo.fieldNames[1].equals("itable")) { | ||||||||||
if (typeNameInfo.fieldNames.empty()) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
auto vtabletype = type.fields[0].type.getHeapType(); | ||||||||||
auto itabletype = type.fields[1].type.getHeapType(); | ||||||||||
// The vtable may either be the first field or the custom descriptor. | ||||||||||
std::optional<HeapType> vtabletype; | ||||||||||
std::optional<HeapType> itabletype; | ||||||||||
auto type = heapType.getStruct(); | ||||||||||
if (auto descriptor = heapType.getDescriptorType()) { | ||||||||||
if (!typeNameInfo.fieldNames[0].equals("itable")) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
vtabletype = descriptor; | ||||||||||
itabletype = type.fields[0].type.getHeapType(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to reserve field 0 in the descriptor. Once we have JS interop, the JS prototype will (almost certainly) have to be stored in field 0. |
||||||||||
} else { | ||||||||||
if (!typeNameInfo.fieldNames[0].equals("vtable")) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
if (!typeNameInfo.fieldNames.count(1) || | ||||||||||
!typeNameInfo.fieldNames[1].equals("itable")) { | ||||||||||
Comment on lines
+125
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we should have a similar check before looking up the name of field 0. Also, we can avoid double lookup by doing this:
Suggested change
|
||||||||||
continue; | ||||||||||
} | ||||||||||
vtabletype = type.fields[0].type.getHeapType(); | ||||||||||
itabletype = type.fields[1].type.getHeapType(); | ||||||||||
} | ||||||||||
|
||||||||||
auto structItableSize = itabletype.getStruct().fields.size(); | ||||||||||
auto structItableSize = itabletype->getStruct().fields.size(); | ||||||||||
|
||||||||||
if (itableSize != 0 && itableSize != structItableSize) { | ||||||||||
Fatal() << "--merge-j2cl-itables needs to be the first pass to run " | ||||||||||
|
@@ -128,11 +141,11 @@ struct J2CLItableMerging : public Pass { | |||||||||
|
||||||||||
// Add a new StructInfo to the list by value so that its memory gets | ||||||||||
// reclaimed automatically on exit. | ||||||||||
structInfos.push_back(StructInfo{heapType, vtabletype, itabletype}); | ||||||||||
structInfos.push_back(StructInfo{heapType, *vtabletype, *itabletype}); | ||||||||||
// Point to the StructInfo just added to the list to be able to look it | ||||||||||
// up by its vtable and itable types. | ||||||||||
structInfoByVtableType[vtabletype] = &structInfos.back(); | ||||||||||
structInfoByITableType[itabletype] = &structInfos.back(); | ||||||||||
structInfoByVtableType[*vtabletype] = &structInfos.back(); | ||||||||||
structInfoByITableType[*itabletype] = &structInfos.back(); | ||||||||||
} | ||||||||||
|
||||||||||
// 2. Collect the globals for vtables and itables. | ||||||||||
|
@@ -275,16 +288,22 @@ struct J2CLItableMerging : public Pass { | |||||||||
} | ||||||||||
|
||||||||||
// This is a struct.get that returns an itable type; | ||||||||||
// Change to return the corresponding vtable type. | ||||||||||
// Change to return the corresponding vtable type. If the vtable is a | ||||||||||
// custom descriptor, change to a ref.get_desc instruction. | ||||||||||
Builder builder(*getModule()); | ||||||||||
replaceCurrent(builder.makeStructGet( | ||||||||||
0, | ||||||||||
curr->ref, | ||||||||||
MemoryOrder::Unordered, | ||||||||||
parent.structInfoByITableType[curr->type.getHeapType()] | ||||||||||
->javaClass.getStruct() | ||||||||||
.fields[0] | ||||||||||
.type)); | ||||||||||
|
||||||||||
HeapType& javaClass = parent.structInfoByITableType[curr->type.getHeapType()]->javaClass; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A HeapType is represented as a single number, so no need to take a reference to it unless you're going to mutate it.
Suggested change
|
||||||||||
if (javaClass.getDescriptorType()) { | ||||||||||
replaceCurrent(builder.makeRefGetDesc(curr->ref)); | ||||||||||
} else { | ||||||||||
replaceCurrent(builder.makeStructGet( | ||||||||||
0, | ||||||||||
curr->ref, | ||||||||||
MemoryOrder::Unordered, | ||||||||||
javaClass.getStruct() | ||||||||||
.fields[0] | ||||||||||
.type)); | ||||||||||
} | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
|
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.
If these would be empty, then we'll just
continue
to the next loop iteration anyway, so I don't see a reason to make them optional.