summaryrefslogtreecommitdiff
path: root/src/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir')
-rw-r--r--src/ir/global-utils.h6
-rw-r--r--src/ir/properties.h18
2 files changed, 15 insertions, 9 deletions
diff --git a/src/ir/global-utils.h b/src/ir/global-utils.h
index b575d6952..7dc4c6af3 100644
--- a/src/ir/global-utils.h
+++ b/src/ir/global-utils.h
@@ -56,15 +56,13 @@ getGlobalInitializedToImport(Module& wasm, Name module, Name base) {
inline bool canInitializeGlobal(const Expression* curr) {
if (auto* tuple = curr->dynCast<TupleMake>()) {
for (auto* op : tuple->operands) {
- if (!op->is<Const>() && !op->is<RefNull>() &&
- !op->is<RefFunc>() & !op->is<GlobalGet>()) {
+ if (!Properties::isSingleConstantExpression(op) && !op->is<GlobalGet>()) {
return false;
}
}
return true;
}
- return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() ||
- curr->is<GlobalGet>();
+ return Properties::isSingleConstantExpression(curr) || curr->is<GlobalGet>();
}
} // namespace GlobalUtils
diff --git a/src/ir/properties.h b/src/ir/properties.h
index 56723631a..d0495f4a9 100644
--- a/src/ir/properties.h
+++ b/src/ir/properties.h
@@ -79,13 +79,18 @@ inline bool isNamedControlFlow(Expression* curr) {
return false;
}
+inline bool isSingleConstantExpression(const Expression* curr) {
+ return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() ||
+ (curr->is<I31New>() && curr->cast<I31New>()->value->is<Const>());
+}
+
inline bool isConstantExpression(const Expression* curr) {
- if (curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>()) {
+ if (isSingleConstantExpression(curr)) {
return true;
}
if (auto* tuple = curr->dynCast<TupleMake>()) {
for (auto* op : tuple->operands) {
- if (!op->is<Const>() && !op->is<RefNull>() && !op->is<RefFunc>()) {
+ if (!isSingleConstantExpression(op)) {
return false;
}
}
@@ -101,13 +106,16 @@ inline Literal getSingleLiteral(const Expression* curr) {
return Literal(n->type);
} else if (auto* r = curr->dynCast<RefFunc>()) {
return Literal(r->func);
- } else {
- WASM_UNREACHABLE("non-constant expression");
+ } else if (auto* i = curr->dynCast<I31New>()) {
+ if (auto* c = i->value->dynCast<Const>()) {
+ return Literal::makeI31(c->value.geti32());
+ }
}
+ WASM_UNREACHABLE("non-constant expression");
}
inline Literals getLiterals(const Expression* curr) {
- if (curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>()) {
+ if (isSingleConstantExpression(curr)) {
return {getSingleLiteral(curr)};
} else if (auto* tuple = curr->dynCast<TupleMake>()) {
Literals literals;