diff options
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 |