From bcc76146fed433cbc8ba01a9f568d979c145110b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 30 Dec 2019 17:55:20 -0800 Subject: 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. --- src/passes/SimplifyGlobals.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/passes/SimplifyGlobals.cpp') 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 #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()) { - if (auto* c = set->value->dynCast()) { - 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()); + 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 constantGlobals; for (auto& global : module->globals) { if (!global->imported()) { - if (auto* c = global->init->dynCast()) { - constantGlobals[global->name] = c->value; + if (Properties::isConstantExpression(global->init)) { + constantGlobals[global->name] = + getLiteralFromConstExpression(global->init); } else if (auto* get = global->init->dynCast()) { 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()) { + Properties::isConstantExpression(global->init)) { constantGlobals.insert(global->name); } } -- cgit v1.2.3