summaryrefslogtreecommitdiff
path: root/src/passes/SimplifyGlobals.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-12-30 17:55:20 -0800
committerGitHub <noreply@github.com>2019-12-30 17:55:20 -0800
commitbcc76146fed433cbc8ba01a9f568d979c145110b (patch)
treeab70ad24afc257b73513c3e62f3aab9938d05944 /src/passes/SimplifyGlobals.cpp
parenta30f1df5696ccb3490e2eaa3a9ed5e7e487c7b0e (diff)
downloadbinaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.tar.gz
binaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.tar.bz2
binaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.zip
Add support for reference types proposal (#2451)
This adds support for the reference type proposal. This includes support for all reference types (`anyref`, `funcref`(=`anyfunc`), and `nullref`) and four new instructions: `ref.null`, `ref.is_null`, `ref.func`, and new typed `select`. This also adds subtype relationship support between reference types. This does not include table instructions yet. This also does not include wasm2js support. Fixes #2444 and fixes #2447.
Diffstat (limited to 'src/passes/SimplifyGlobals.cpp')
-rw-r--r--src/passes/SimplifyGlobals.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp
index 88f27f8be..b18f726ed 100644
--- a/src/passes/SimplifyGlobals.cpp
+++ b/src/passes/SimplifyGlobals.cpp
@@ -37,6 +37,7 @@
#include <atomic>
#include "ir/effects.h"
+#include "ir/properties.h"
#include "ir/utils.h"
#include "pass.h"
#include "wasm-builder.h"
@@ -106,8 +107,9 @@ struct ConstantGlobalApplier
void visitExpression(Expression* curr) {
if (auto* set = curr->dynCast<GlobalSet>()) {
- if (auto* c = set->value->dynCast<Const>()) {
- currConstantGlobals[set->name] = c->value;
+ if (Properties::isConstantExpression(set->value)) {
+ currConstantGlobals[set->name] =
+ getLiteralFromConstExpression(set->value);
} else {
currConstantGlobals.erase(set->name);
}
@@ -116,7 +118,7 @@ struct ConstantGlobalApplier
// Check if the global is known to be constant all the time.
if (constantGlobals->count(get->name)) {
auto* global = getModule()->getGlobal(get->name);
- assert(global->init->is<Const>());
+ assert(Properties::isConstantExpression(global->init));
replaceCurrent(ExpressionManipulator::copy(global->init, *getModule()));
replaced = true;
return;
@@ -125,7 +127,7 @@ struct ConstantGlobalApplier
auto iter = currConstantGlobals.find(get->name);
if (iter != currConstantGlobals.end()) {
Builder builder(*getModule());
- replaceCurrent(builder.makeConst(iter->second));
+ replaceCurrent(builder.makeConstExpression(iter->second));
replaced = true;
}
return;
@@ -249,13 +251,14 @@ struct SimplifyGlobals : public Pass {
std::map<Name, Literal> constantGlobals;
for (auto& global : module->globals) {
if (!global->imported()) {
- if (auto* c = global->init->dynCast<Const>()) {
- constantGlobals[global->name] = c->value;
+ if (Properties::isConstantExpression(global->init)) {
+ constantGlobals[global->name] =
+ getLiteralFromConstExpression(global->init);
} else if (auto* get = global->init->dynCast<GlobalGet>()) {
auto iter = constantGlobals.find(get->name);
if (iter != constantGlobals.end()) {
Builder builder(*module);
- global->init = builder.makeConst(iter->second);
+ global->init = builder.makeConstExpression(iter->second);
}
}
}
@@ -268,7 +271,7 @@ struct SimplifyGlobals : public Pass {
NameSet constantGlobals;
for (auto& global : module->globals) {
if (!global->mutable_ && !global->imported() &&
- global->init->is<Const>()) {
+ Properties::isConstantExpression(global->init)) {
constantGlobals.insert(global->name);
}
}