From f9020a0bdb3912a65f3f051b3b841fad412d2f13 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 7 Aug 2016 10:37:15 -0700 Subject: remove drop-return-values pass --- src/passes/pass.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/passes/pass.cpp') diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index f27eccf6a..cd7e21542 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -64,7 +64,6 @@ void PassRegistry::registerPasses() { registerPass("coalesce-locals", "reduce # of locals by coalescing", createCoalesceLocalsPass); registerPass("coalesce-locals-learning", "reduce # of locals by coalescing and learning", createCoalesceLocalsWithLearningPass); registerPass("dce", "removes unreachable code", createDeadCodeEliminationPass); - registerPass("drop-return-values", "stops relying on return values from set_local and store", createDropReturnValuesPass); registerPass("duplicate-function-elimination", "removes duplicate functions", createDuplicateFunctionEliminationPass); registerPass("lower-if-else", "lowers if-elses into ifs, blocks and branches", createLowerIfElsePass); registerPass("merge-blocks", "merges blocks to their parents", createMergeBlocksPass); -- cgit v1.2.3 From 9507066763db50de86db4d1ffead766f23d63116 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 7 Aug 2016 10:38:04 -0700 Subject: remove lower-if-else, as it's no longer needed --- src/passes/CMakeLists.txt | 1 - src/passes/LowerIfElse.cpp | 67 ------------------------------------------ src/passes/pass.cpp | 1 - test/passes/lower-if-else.txt | 42 -------------------------- test/passes/lower-if-else.wast | 29 ------------------ 5 files changed, 140 deletions(-) delete mode 100644 src/passes/LowerIfElse.cpp delete mode 100644 test/passes/lower-if-else.txt delete mode 100644 test/passes/lower-if-else.wast (limited to 'src/passes/pass.cpp') diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index 0baee7c3a..1b4c65562 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -3,7 +3,6 @@ SET(passes_SOURCES CoalesceLocals.cpp DeadCodeElimination.cpp DuplicateFunctionElimination.cpp - LowerIfElse.cpp MergeBlocks.cpp Metrics.cpp NameManager.cpp diff --git a/src/passes/LowerIfElse.cpp b/src/passes/LowerIfElse.cpp deleted file mode 100644 index b566e8207..000000000 --- a/src/passes/LowerIfElse.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2015 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -// Lowers if (x) y else z into -// -// L: { -// if (x) break (y) L -// z -// } -// -// This is useful for investigating how beneficial if_else is. -// - -#include - -#include -#include - -namespace wasm { - -struct LowerIfElse : public WalkerPass>> { - MixedArena* allocator; - std::unique_ptr namer; - - void prepare(PassRunner* runner, Module *module) override { - allocator = runner->allocator; - namer = make_unique(); - namer->run(runner, module); - } - - void visitIf(If *curr) { - if (curr->ifFalse) { - auto block = allocator->alloc(); - auto name = namer->getUnique("L"); // TODO: getUniqueInFunction - block->name = name; - block->list.push_back(curr); - block->list.push_back(curr->ifFalse); - block->finalize(); - curr->ifFalse = nullptr; - auto break_ = allocator->alloc(); - break_->name = name; - break_->value = curr->ifTrue; - curr->ifTrue = break_; - replaceCurrent(block); - } - } -}; - -Pass *createLowerIfElsePass() { - return new LowerIfElse(); -} - -} // namespace wasm diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index cd7e21542..1e7e85ccb 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -65,7 +65,6 @@ void PassRegistry::registerPasses() { registerPass("coalesce-locals-learning", "reduce # of locals by coalescing and learning", createCoalesceLocalsWithLearningPass); registerPass("dce", "removes unreachable code", createDeadCodeEliminationPass); registerPass("duplicate-function-elimination", "removes duplicate functions", createDuplicateFunctionEliminationPass); - registerPass("lower-if-else", "lowers if-elses into ifs, blocks and branches", createLowerIfElsePass); registerPass("merge-blocks", "merges blocks to their parents", createMergeBlocksPass); registerPass("metrics", "reports metrics", createMetricsPass); registerPass("nm", "name list", createNameListPass); diff --git a/test/passes/lower-if-else.txt b/test/passes/lower-if-else.txt deleted file mode 100644 index 93dd6d916..000000000 --- a/test/passes/lower-if-else.txt +++ /dev/null @@ -1,42 +0,0 @@ -(module - (memory 256 256) - (type $0 (func)) - (func $ifs (type $0) - (block $block0 - (if - (i32.const 0) - (i32.const 1) - ) - (block $L0 - (if - (i32.const 0) - (br $L0 - (i32.const 1) - ) - ) - (i32.const 2) - ) - (block $L1 - (if - (i32.const 4) - (br $L1 - (i32.const 5) - ) - ) - (i32.const 6) - ) - (i32.eq - (block $L2 - (if - (i32.const 4) - (br $L2 - (i32.const 5) - ) - ) - (i32.const 6) - ) - (i32.const 177) - ) - ) - ) -) diff --git a/test/passes/lower-if-else.wast b/test/passes/lower-if-else.wast deleted file mode 100644 index 138a8a206..000000000 --- a/test/passes/lower-if-else.wast +++ /dev/null @@ -1,29 +0,0 @@ -(module - (memory 256 256) - (func $ifs - (block - (if - (i32.const 0) - (i32.const 1) - ) - (if_else - (i32.const 0) - (i32.const 1) - (i32.const 2) - ) - (if_else - (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.eq - (if_else - (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.const 177) - ) - ) - ) -) -- cgit v1.2.3 From 323e32bc1ca73c92d81b7fe28fd54e62c2218801 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Aug 2016 15:05:40 -0700 Subject: autodrop must be run before we optimize in asm2wasm, as otherwise its input is not yet valid then after finalizeCalls, we must autodrop again to drop things that finalizeCalls changed --- src/asm2wasm.h | 7 ++- src/passes/pass.cpp | 3 ++ src/wasm-module-building.h | 6 ++- test/emcc_hello_world.fromasm | 76 ++++++++++++++++++--------------- test/emcc_hello_world.fromasm.imprecise | 76 ++++++++++++++++++--------------- test/unit.fromasm | 13 ++++-- test/unit.fromasm.imprecise | 13 ++++-- 7 files changed, 114 insertions(+), 80 deletions(-) (limited to 'src/passes/pass.cpp') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 10d065400..7cc671597 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -523,7 +523,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { for (unsigned i = 1; i < body->size(); i++) { if (body[i][0] == DEFUN) numFunctions++; } - optimizingBuilder = make_unique(&wasm, numFunctions); + optimizingBuilder = make_unique(&wasm, numFunctions, [&](PassRunner& passRunner) { + // run autodrop first, before optimizations + passRunner.add(); + }); } // first pass - do almost everything, but function imports and indirect calls @@ -786,7 +789,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { }; PassRunner passRunner(&wasm); passRunner.add(this); - passRunner.add(); + passRunner.add(); // FinalizeCalls may cause us to require additional drops if (optimize) passRunner.add("vacuum"); // autodrop can add some garbage passRunner.run(); diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 1e7e85ccb..437b023bc 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -209,6 +209,9 @@ void PassRunner::run() { } void PassRunner::runFunction(Function* func) { + if (debug) { + std::cerr << "[PassRunner] running passes on function " << func->name << std::endl; + } for (auto* pass : passes) { runPassOnFunction(pass, func); } diff --git a/src/wasm-module-building.h b/src/wasm-module-building.h index ead074991..43cc493d1 100644 --- a/src/wasm-module-building.h +++ b/src/wasm-module-building.h @@ -73,6 +73,7 @@ static std::mutex debug; class OptimizingIncrementalModuleBuilder { Module* wasm; uint32_t numFunctions; + std::function addPrePasses; Function* endMarker; std::atomic* list; uint32_t nextFunction; // only used on main thread @@ -86,8 +87,8 @@ class OptimizingIncrementalModuleBuilder { public: // numFunctions must be equal to the number of functions allocated, or higher. Knowing // this bounds helps avoid locking. - OptimizingIncrementalModuleBuilder(Module* wasm, Index numFunctions) - : wasm(wasm), numFunctions(numFunctions), endMarker(nullptr), list(nullptr), nextFunction(0), + OptimizingIncrementalModuleBuilder(Module* wasm, Index numFunctions, std::function addPrePasses) + : wasm(wasm), numFunctions(numFunctions), addPrePasses(addPrePasses), endMarker(nullptr), list(nullptr), nextFunction(0), numWorkers(0), liveWorkers(0), activeWorkers(0), availableFuncs(0), finishedFuncs(0), finishing(false) { if (numFunctions == 0) { @@ -201,6 +202,7 @@ private: void optimizeFunction(Function* func) { PassRunner passRunner(wasm); + addPrePasses(passRunner); passRunner.addDefaultFunctionOptimizationPasses(); passRunner.runFunction(func); } diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index c0b245dd9..ab579533e 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -2729,21 +2729,23 @@ ) ) ) - (call_indirect $FUNCSIG$iiii - (get_local $0) - (i32.sub - (get_local $1) - (get_local $2) - ) - (i32.const 1) - (i32.add - (i32.and - (i32.load offset=40 - (get_local $0) + (drop + (call_indirect $FUNCSIG$iiii + (get_local $0) + (i32.sub + (get_local $1) + (get_local $2) + ) + (i32.const 1) + (i32.add + (i32.and + (i32.load offset=40 + (get_local $0) + ) + (i32.const 7) ) - (i32.const 7) + (i32.const 2) ) - (i32.const 2) ) ) ) @@ -7119,13 +7121,15 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $5) - (i32.sub - (get_local $75) + (drop + (call $___fwritex (get_local $5) + (i32.sub + (get_local $75) + (get_local $5) + ) + (get_local $0) ) - (get_local $0) ) ) (if @@ -7234,17 +7238,19 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $1) - (select - (i32.const 9) - (get_local $15) - (i32.gt_s - (get_local $15) + (drop + (call $___fwritex + (get_local $1) + (select (i32.const 9) + (get_local $15) + (i32.gt_s + (get_local $15) + (i32.const 9) + ) ) + (get_local $0) ) - (get_local $0) ) ) (set_local $1 @@ -7461,17 +7467,19 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $1) - (select - (get_local $8) - (get_local $15) - (i32.gt_s - (get_local $15) + (drop + (call $___fwritex + (get_local $1) + (select (get_local $8) + (get_local $15) + (i32.gt_s + (get_local $15) + (get_local $8) + ) ) + (get_local $0) ) - (get_local $0) ) ) (if diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 07ee8d33f..32e34c0e9 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -2723,21 +2723,23 @@ ) ) ) - (call_indirect $FUNCSIG$iiii - (get_local $0) - (i32.sub - (get_local $1) - (get_local $2) - ) - (i32.const 1) - (i32.add - (i32.and - (i32.load offset=40 - (get_local $0) + (drop + (call_indirect $FUNCSIG$iiii + (get_local $0) + (i32.sub + (get_local $1) + (get_local $2) + ) + (i32.const 1) + (i32.add + (i32.and + (i32.load offset=40 + (get_local $0) + ) + (i32.const 7) ) - (i32.const 7) + (i32.const 2) ) - (i32.const 2) ) ) ) @@ -7113,13 +7115,15 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $5) - (i32.sub - (get_local $75) + (drop + (call $___fwritex (get_local $5) + (i32.sub + (get_local $75) + (get_local $5) + ) + (get_local $0) ) - (get_local $0) ) ) (if @@ -7228,17 +7232,19 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $1) - (select - (i32.const 9) - (get_local $15) - (i32.gt_s - (get_local $15) + (drop + (call $___fwritex + (get_local $1) + (select (i32.const 9) + (get_local $15) + (i32.gt_s + (get_local $15) + (i32.const 9) + ) ) + (get_local $0) ) - (get_local $0) ) ) (set_local $1 @@ -7455,17 +7461,19 @@ ) (i32.const 0) ) - (call $___fwritex - (get_local $1) - (select - (get_local $8) - (get_local $15) - (i32.gt_s - (get_local $15) + (drop + (call $___fwritex + (get_local $1) + (select (get_local $8) + (get_local $15) + (i32.gt_s + (get_local $15) + (get_local $8) + ) ) + (get_local $0) ) - (get_local $0) ) ) (if diff --git a/test/unit.fromasm b/test/unit.fromasm index bc5281ed5..f48dfcdb2 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -491,10 +491,15 @@ ) ) (func $smallIf - (if - (i32.const 2) - (call $lb - (i32.const 3) + (block $do-once$0 + (drop + (if + (i32.const 2) + (call $lb + (i32.const 3) + ) + (br $do-once$0) + ) ) ) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 945d6cc8e..06ab40915 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -473,10 +473,15 @@ ) ) (func $smallIf - (if - (i32.const 2) - (call $lb - (i32.const 3) + (block $do-once$0 + (drop + (if + (i32.const 2) + (call $lb + (i32.const 3) + ) + (br $do-once$0) + ) ) ) ) -- cgit v1.2.3