diff options
author | Alon Zakai <azakai@google.com> | 2023-05-04 16:44:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 16:44:09 -0700 |
commit | 7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686 (patch) | |
tree | cc0343495b994c67a01b5143e6345d45a1c3587d /src/ir/possible-contents.cpp | |
parent | 09fe432c0d3cb7562767a8e06d4e918beb5990c2 (diff) | |
download | binaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.tar.gz binaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.tar.bz2 binaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.zip |
[NFC] Refactor each of ArrayNewSeg and ArrayInit into subclasses for Data/Elem (#5692)
ArrayNewSeg => ArrayNewSegData, ArrayNewSegElem
ArrayInit => ArrayInitData, ArrayInitElem
Basically we remove the opcode and use the class type to differentiate them.
This adds some code but it makes the representation simpler and more compact in
memory, and it will help with #5690
Diffstat (limited to 'src/ir/possible-contents.cpp')
-rw-r--r-- | src/ir/possible-contents.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index e991a68fd..db2655e8a 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -904,26 +904,24 @@ struct InfoCollector } addRoot(curr, PossibleContents::exactType(curr->type)); } - void visitArrayNewSeg(ArrayNewSeg* curr) { + void visitArrayNewData(ArrayNewData* curr) { if (curr->type == Type::unreachable) { return; } addRoot(curr, PossibleContents::exactType(curr->type)); auto heapType = curr->type.getHeapType(); - switch (curr->op) { - case NewData: { - Type elemType = heapType.getArray().element.type; - addRoot(DataLocation{heapType, 0}, - PossibleContents::fromType(elemType)); - return; - } - case NewElem: { - Type segType = getModule()->getElementSegment(curr->segment)->type; - addRoot(DataLocation{heapType, 0}, PossibleContents::fromType(segType)); - return; - } + Type elemType = heapType.getArray().element.type; + addRoot(DataLocation{heapType, 0}, PossibleContents::fromType(elemType)); + } + void visitArrayNewElem(ArrayNewElem* curr) { + if (curr->type == Type::unreachable) { + return; } - WASM_UNREACHABLE("unexpected op"); + addRoot(curr, PossibleContents::exactType(curr->type)); + auto heapType = curr->type.getHeapType(); + Type segType = getModule()->getElementSegment(curr->segment)->type; + addRoot(DataLocation{heapType, 0}, PossibleContents::fromType(segType)); + return; } void visitArrayNewFixed(ArrayNewFixed* curr) { if (curr->type == Type::unreachable) { @@ -1012,7 +1010,7 @@ struct InfoCollector auto* set = builder.makeArraySet(curr->ref, curr->index, curr->value); visitArraySet(set); } - void visitArrayInit(ArrayInit* curr) { + template<typename ArrayInit> void visitArrayInit(ArrayInit* curr) { // Check for both unreachability and a bottom type. In either case we have // no work to do, and would error on an assertion below in finding the array // type. @@ -1033,6 +1031,8 @@ struct InfoCollector auto* set = builder.makeArraySet(curr->ref, curr->index, get); visitArraySet(set); } + void visitArrayInitData(ArrayInitData* curr) { visitArrayInit(curr); } + void visitArrayInitElem(ArrayInitElem* curr) { visitArrayInit(curr); } void visitStringNew(StringNew* curr) { if (curr->type == Type::unreachable) { return; |