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/MergeLocals.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/passes/MergeLocals.cpp') diff --git a/src/passes/MergeLocals.cpp b/src/passes/MergeLocals.cpp index 0116753f1..2223594b6 100644 --- a/src/passes/MergeLocals.cpp +++ b/src/passes/MergeLocals.cpp @@ -100,7 +100,8 @@ struct MergeLocals return; } // compute all dependencies - LocalGraph preGraph(getFunction()); + auto* func = getFunction(); + LocalGraph preGraph(func); preGraph.computeInfluences(); // optimize each copy std::unordered_map optimizedToCopy, @@ -119,6 +120,11 @@ struct MergeLocals if (preGraph.getSetses[influencedGet].size() == 1) { // this is ok assert(*preGraph.getSetses[influencedGet].begin() == trivial); + // If local types are different (when one is a subtype of the + // other), don't optimize + if (func->getLocalType(copy->index) != influencedGet->type) { + canOptimizeToCopy = false; + } } else { canOptimizeToCopy = false; break; @@ -152,6 +158,11 @@ struct MergeLocals if (preGraph.getSetses[influencedGet].size() == 1) { // this is ok assert(*preGraph.getSetses[influencedGet].begin() == copy); + // If local types are different (when one is a subtype of the + // other), don't optimize + if (func->getLocalType(trivial->index) != influencedGet->type) { + canOptimizeToTrivial = false; + } } else { canOptimizeToTrivial = false; break; @@ -176,7 +187,7 @@ struct MergeLocals // if one does not work, we need to undo all its siblings (don't extend // the live range unless we are definitely removing a conflict, same // logic as before). - LocalGraph postGraph(getFunction()); + LocalGraph postGraph(func); postGraph.computeInfluences(); for (auto& pair : optimizedToCopy) { auto* copy = pair.first; -- cgit v1.2.3