diff options
author | Thomas Lively <tlively@google.com> | 2022-12-19 17:40:44 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 15:40:44 -0800 |
commit | 54079e9458e0d7ee2b4028ea888a74fed31f61d7 (patch) | |
tree | 3c280342569dbfcd58221b0d75eef4e35c991284 /src/passes/pass.cpp | |
parent | 746c66521cae137ae36ef1c349873ec74d613a67 (diff) | |
download | binaryen-54079e9458e0d7ee2b4028ea888a74fed31f61d7.tar.gz binaryen-54079e9458e0d7ee2b4028ea888a74fed31f61d7.tar.bz2 binaryen-54079e9458e0d7ee2b4028ea888a74fed31f61d7.zip |
Remove unused types during type optimizations (#5361)
The type rewriting utility in type-updating.cpp gathers all the used heap types,
then rewrites them to newly built and possibly modified heap types. The problem
is that for the isorecursive type system, the set of "used" heap types was
overly broad because it also included unused heap types that are in a rec group
with used types. In the context of emitting a binary, it is important to treat
these types as used because failing to emit them would change the identity of
the used types, but in the context of type optimizations it is ok to treat them
as truly unused because we are changing type identities anyway.
Update the type rewriting utility to only include truly used types in the set of
output types. This causes all existing type optimizations to implicitly drop
unused types, but only if they find any other optimizations to do and actually
run the rewriter utitility. Their output will also still include unused types
that were used before their optimizations were applied.
To overcome these limitations and better match the optimizing power of nominal
mode, which never includes unused types in the output, add a new type
optimization pass that removes unused types and does nothing else and run it
near the end of the global optimization pipeline.
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 21501c62f..732c2e8e2 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -369,6 +369,9 @@ void PassRegistry::registerPasses() { registerPass("remove-unused-names", "removes names from locations that are never branched to", createRemoveUnusedNamesPass); + registerPass("remove-unused-types", + "remove unused private GC types", + createRemoveUnusedTypesPass); registerPass("reorder-functions", "sorts functions by access frequency", createReorderFunctionsPass); @@ -620,6 +623,7 @@ void PassRunner::addDefaultGlobalOptimizationPrePasses() { } addIfNoDWARFIssues("remove-unused-module-elements"); if (options.closedWorld) { + addIfNoDWARFIssues("remove-unused-types"); addIfNoDWARFIssues("cfp"); addIfNoDWARFIssues("gsi"); } |