diff options
author | Sam Clegg <sbc@chromium.org> | 2022-03-19 02:29:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 02:29:35 +0000 |
commit | d2f54b40e736cdee2a0ff9fc15e9323ccb9d7c20 (patch) | |
tree | 3f6c5dafbf558d29e0bf72a33be973d55d6c10ef /src/ir | |
parent | 88c2e4377df7dbe65bc8ef629ea409cd9df6a860 (diff) | |
download | binaryen-d2f54b40e736cdee2a0ff9fc15e9323ccb9d7c20.tar.gz binaryen-d2f54b40e736cdee2a0ff9fc15e9323ccb9d7c20.tar.bz2 binaryen-d2f54b40e736cdee2a0ff9fc15e9323ccb9d7c20.zip |
Add support for extended-const proposal (#4529)
See https://github.com/WebAssembly/extended-const
Diffstat (limited to 'src/ir')
-rw-r--r-- | src/ir/global-utils.h | 10 | ||||
-rw-r--r-- | src/ir/properties.h | 20 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/ir/global-utils.h b/src/ir/global-utils.h index 26aec7790..ca00047a0 100644 --- a/src/ir/global-utils.h +++ b/src/ir/global-utils.h @@ -53,20 +53,18 @@ getGlobalInitializedToImport(Module& wasm, Name module, Name base) { return ret; } -inline bool canInitializeGlobal(Expression* curr) { +inline bool canInitializeGlobal(Expression* curr, FeatureSet features) { if (auto* tuple = curr->dynCast<TupleMake>()) { for (auto* op : tuple->operands) { - if (!canInitializeGlobal(op)) { + if (!canInitializeGlobal(op, features)) { return false; } } return true; } - if (Properties::isSingleConstantExpression(curr) || curr->is<GlobalGet>() || - curr->is<RttCanon>() || curr->is<RttSub>() || curr->is<StructNew>() || - curr->is<ArrayNew>() || curr->is<ArrayInit>() || curr->is<I31New>()) { + if (Properties::isValidInConstantExpression(curr, features)) { for (auto* child : ChildIterator(curr)) { - if (!canInitializeGlobal(child)) { + if (!canInitializeGlobal(child, features)) { return false; } } diff --git a/src/ir/properties.h b/src/ir/properties.h index d2c5affd2..07898169f 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -414,6 +414,26 @@ inline bool canEmitSelectWithArms(Expression* ifTrue, Expression* ifFalse) { // bool isGenerative(Expression* curr, FeatureSet features); +inline bool isValidInConstantExpression(Expression* expr, FeatureSet features) { + if (isSingleConstantExpression(expr) || expr->is<GlobalGet>() || + expr->is<RttCanon>() || expr->is<RttSub>() || expr->is<StructNew>() || + expr->is<ArrayNew>() || expr->is<ArrayInit>() || expr->is<I31New>()) { + return true; + } + + if (features.hasExtendedConst()) { + if (expr->is<Binary>()) { + auto bin = static_cast<Binary*>(expr); + if (bin->op == AddInt64 || bin->op == SubInt64 || bin->op == MulInt64 || + bin->op == AddInt32 || bin->op == SubInt32 || bin->op == MulInt32) { + return true; + } + } + } + + return false; +} + } // namespace wasm::Properties #endif // wasm_ir_properties_h |