diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/ReorderGlobals.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm-merge.cpp | 14 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/passes/ReorderGlobals.cpp b/src/passes/ReorderGlobals.cpp index d1c26b2cc..9b5940a21 100644 --- a/src/passes/ReorderGlobals.cpp +++ b/src/passes/ReorderGlobals.cpp @@ -58,7 +58,11 @@ private: struct ReorderGlobals : public Pass { // Whether to always reorder globals, even if there are very few and the - // benefit is minor. That is useful for testing. + // benefit is minor. That is useful for testing, and also internally in passes + // that use us to reorder them so dependencies appear first (that is, if a + // pass ends up with an earlier global reading a later one, the sorting in + // this pass will reorder them properly; we need to take those dependencies + // into account anyhow here). bool always; ReorderGlobals(bool always) : always(always) {} diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 088317eec..0884350cb 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -586,13 +586,17 @@ Note that filenames and modules names are interleaved (which is hopefully less c // module. fuseImportsAndExports(); - // Remove unused things. This is obviously a useful optimization, but it also - // makes using the output easier: if an import was resolved by an export - // during the merge, then that import will have no more uses and it will be - // optimized out (while if we didn't optimize it out then instantiating the - // module would still be forced to provide something for that import). { PassRunner passRunner(&merged); + // We might have made some globals read from others that now appear after + // them (if the one they read was appended from a later module). Sort them + // to fix that. TODO: we could do this only if we actually append globals + passRunner.add("reorder-globals-always"); + // Remove unused things. This is obviously a useful optimization but it also + // makes using the output easier: if an import was resolved by an export + // during the merge, then that import will have no more uses and it will be + // optimized out (while if we didn't optimize it out then instantiating the + // module would still be forced to provide something for that import). passRunner.add("remove-unused-module-elements"); passRunner.run(); } |