diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-09-19 15:50:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 15:50:30 -0700 |
commit | fe88b47749115009da0447e340cbdc86edf30984 (patch) | |
tree | 7dfd9aba7086c8aa6dff4877ac1ee3b9d78bc5ce /src/passes/Inlining.cpp | |
parent | a53356ab155a7d8c2f334dc9a3c1432bacbc78fe (diff) | |
download | binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.gz binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.bz2 binaryen-fe88b47749115009da0447e340cbdc86edf30984.zip |
Unify imported and non-imported things (#1678)
Fixes #1649
This moves us to a single object for functions, which can be imported or nor, and likewise for globals (as a result, GetGlobals do not need to check if the global is imported or not, etc.). All imported things now inherit from Importable, which has the module and base of the import, and if they are set then it is an import.
For convenient iteration, there are a few helpers like
ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) {
.. use global ..
});
as often iteration only cares about imported or defined (non-imported) things.
Diffstat (limited to 'src/passes/Inlining.cpp')
-rw-r--r-- | src/passes/Inlining.cpp | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index a507e5fc8..ebc33bf97 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -32,13 +32,14 @@ #include <atomic> -#include <wasm.h> -#include <pass.h> -#include <wasm-builder.h> -#include <ir/utils.h> -#include <ir/literal-utils.h> -#include <parsing.h> -#include <passes/opt-utils.h> +#include "wasm.h" +#include "pass.h" +#include "wasm-builder.h" +#include "ir/literal-utils.h" +#include "ir/module-utils.h" +#include "ir/utils.h" +#include "parsing.h" +#include "passes/opt-utils.h" namespace wasm { @@ -117,11 +118,6 @@ struct FunctionInfoScanner : public WalkerPass<PostWalker<FunctionInfoScanner>> (*infos)[getFunction()->name].lightweight = false; } - void visitCallImport(CallImport* curr) { - // having a call is not lightweight - (*infos)[getFunction()->name].lightweight = false; - } - void visitFunction(Function* curr) { (*infos)[curr->name].size = Measurer::measure(curr->body); } @@ -279,9 +275,7 @@ struct Inlining : public Pass { } for (auto& segment : module->table.segments) { for (auto name : segment.data) { - if (module->getFunctionOrNull(name)) { - infos[name].usedGlobally = true; - } + infos[name].usedGlobally = true; } } } @@ -289,12 +283,11 @@ struct Inlining : public Pass { bool iteration(PassRunner* runner, Module* module) { // decide which to inline InliningState state; - for (auto& func : module->functions) { - // on the first iteration, allow multiple inlinings per function + ModuleUtils::iterDefinedFunctions(*module, [&](Function* func) { if (infos[func->name].worthInlining(runner->options)) { state.worthInlining.insert(func->name); } - } + }); if (state.worthInlining.size() == 0) return false; // fill in actionsForFunction, as we operate on it in parallel (each function to its own entry) for (auto& func : module->functions) { |