From 7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 4 May 2023 16:44:09 -0700 Subject: [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 --- src/ir/possible-contents.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/ir/possible-contents.cpp') 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 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; -- cgit v1.2.3