-
Notifications
You must be signed in to change notification settings - Fork 841
[multibyte] Add multibyte array store instructions. #8059
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
0847ada
528beea
6727c79
c6e675c
e65a5be
4237ddb
6f4b1c7
087191f
8e53770
32ed9df
3168b36
bed10a2
8e02608
18cc62d
324e152
8b69572
ddf7a10
9ffd9e7
220bc36
a5c00c1
c6c927f
c148eaf
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 |
|---|---|---|
|
|
@@ -1102,6 +1102,13 @@ struct InfoCollector | |
| addChildParentLink(curr->ref, curr); | ||
| addChildParentLink(curr->value, curr); | ||
| } | ||
| void visitArrayStore(ArrayStore* curr) { | ||
| if (curr->ref->type == Type::unreachable) { | ||
| return; | ||
| } | ||
| addChildParentLink(curr->ref, curr); | ||
| addChildParentLink(curr->value, curr); | ||
| } | ||
|
|
||
| void visitArrayLen(ArrayLen* curr) { | ||
| // TODO: optimize when possible (perhaps we can infer a Literal for the | ||
|
|
@@ -1742,6 +1749,7 @@ void TNHOracle::scan(Function* func, | |
| } | ||
| void visitArrayGet(ArrayGet* curr) { notePossibleTrap(curr->ref); } | ||
| void visitArraySet(ArraySet* curr) { notePossibleTrap(curr->ref); } | ||
| void visitArrayStore(ArrayStore* curr) { notePossibleTrap(curr->ref); } | ||
| void visitArrayLen(ArrayLen* curr) { notePossibleTrap(curr->ref); } | ||
| void visitArrayCopy(ArrayCopy* curr) { | ||
| notePossibleTrap(curr->srcRef); | ||
|
|
@@ -2239,7 +2247,7 @@ struct Flower { | |
| Expression* read); | ||
|
|
||
| // Similar to readFromData, but does a write for a struct.set or array.set. | ||
| void writeToData(Expression* ref, Expression* value, Index fieldIndex); | ||
| void writeToData(Expression* ref, Expression* value, Index fieldIndex, bool multibyte = false); | ||
|
|
||
| // We will need subtypes during the flow, so compute them once ahead of time. | ||
| std::unique_ptr<SubTypes> subTypes; | ||
|
|
@@ -2576,7 +2584,7 @@ Flower::Flower(Module& wasm, const PassOptions& options) | |
| for (const auto& [location, value] : roots) { | ||
| #if defined(POSSIBLE_CONTENTS_DEBUG) && POSSIBLE_CONTENTS_DEBUG >= 2 | ||
| std::cout << " init root\n"; | ||
| dump(location); | ||
| dump(getLocation(location)); | ||
| value.dump(std::cout, &wasm); | ||
| std::cout << '\n'; | ||
| #endif | ||
|
|
@@ -2743,6 +2751,11 @@ bool Flower::updateContents(LocationIndex locationIndex, | |
| } else if (auto* globalLoc = std::get_if<GlobalLocation>(&location)) { | ||
| filterGlobalContents(contents, *globalLoc); | ||
| filtered = true; | ||
| } else if (auto* dataLoc = std::get_if<DataLocation>(&location)) { | ||
| // Multibyte array stores with differing widths can merge to Many, so | ||
| // filter again afterwards to fall back to the declared type limit. | ||
| filterDataContents(contents, *dataLoc); | ||
| filtered = true; | ||
| } | ||
|
|
||
| // Check if anything changed after filtering, if we did so. | ||
|
|
@@ -2829,6 +2842,9 @@ void Flower::flowAfterUpdate(LocationIndex locationIndex) { | |
| } else if (auto* set = parent->dynCast<ArraySet>()) { | ||
| assert(set->ref == child || set->value == child); | ||
| writeToData(set->ref, set->value, 0); | ||
| } else if (auto* store = parent->dynCast<ArrayStore>()) { | ||
| assert(store->ref == child || store->value == child); | ||
| writeToData(store->ref, store->value, 0, /*multibyte*/ true); | ||
| } else if (auto* get = parent->dynCast<RefGetDesc>()) { | ||
| // Similar to struct.get. | ||
| assert(get->ref == child); | ||
|
|
@@ -3006,6 +3022,11 @@ void Flower::filterDataContents(PossibleContents& contents, | |
| contents = PossibleContents::none(); | ||
| return; | ||
| } | ||
| if (contents.isMany()) { | ||
| // An unknown state (e.g. from combining writes of different types like in | ||
| // multibyte array stores) translates into the most generic bounded type. | ||
| contents = PossibleContents::fromType(field->type); | ||
| } | ||
|
|
||
| if (field->isPacked()) { | ||
| // We must handle packed fields carefully. | ||
|
|
@@ -3188,7 +3209,7 @@ void Flower::readFromData(Type declaredType, | |
| connectDuringFlow(coneReadLocation, ExpressionLocation{read, 0}); | ||
| } | ||
|
|
||
| void Flower::writeToData(Expression* ref, Expression* value, Index fieldIndex) { | ||
| void Flower::writeToData(Expression* ref, Expression* value, Index fieldIndex, bool multibyte) { | ||
| #if defined(POSSIBLE_CONTENTS_DEBUG) && POSSIBLE_CONTENTS_DEBUG >= 2 | ||
| std::cout << " add special writes\n"; | ||
| #endif | ||
|
|
@@ -3236,6 +3257,9 @@ void Flower::writeToData(Expression* ref, Expression* value, Index fieldIndex) { | |
| // As in readFromData, normalize to the proper cone. | ||
| auto cone = refContents.getCone(); | ||
| auto normalizedDepth = getNormalizedConeDepth(cone.type, cone.depth); | ||
| if (multibyte) { | ||
|
Collaborator
Author
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. @kripken Here's where I'm having issues. (module
(type $0 (func))
(type $1 (array (mut i8)))
(global $global$0 (ref $1) (array.new_default $1
(i32.const 4)
))
(func $0
(f64.store (type $1)
(global.get $global$0)
(i32.const 1)
(f64.const 2)
)
)
)with
Member
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. I am guessing that Updating
Collaborator
Author
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. Alright here's what I came up with in c148eaf . I'll let it cook on the fuzzer for a bit. |
||
| valueContents = PossibleContents::fromType(value->type); | ||
| } | ||
|
|
||
| subTypes->iterSubTypes( | ||
| cone.type.getHeapType(), normalizedDepth, [&](HeapType type, Index depth) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.