From 5834719fc17d4735fce0102738b87b70255cfd5f Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Fri, 20 Oct 2017 12:17:41 -0400 Subject: Add pass to remove dead variables at the module level. There does not seem to be any pass that remove global variables. I think we could use one. This pass will look specifically for global variables that are not referenced and are not exported. Any decoration associated with the variable will also be removed. However, this could cause types or constants to become unreferenced. They will not be removed. Another pass will have to be called to remove those. --- tools/opt/opt.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 2a187f04..dd44d248 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -153,6 +153,8 @@ Options: call tree functions. --strength-reduction Replaces instructions with equivalent and less expensive ones. + --eliminate-dead-variables + Deletes module scope variables that are not referenced. -O Optimize for performance. Apply a sequence of transformations in an attempt to improve the performance of the generated @@ -353,6 +355,8 @@ OptStatus ParseFlags(int argc, const char** argv, Optimizer* optimizer, optimizer->RegisterPass(CreateCommonUniformElimPass()); } else if (0 == strcmp(cur_arg, "--eliminate-dead-const")) { optimizer->RegisterPass(CreateEliminateDeadConstantPass()); + } else if (0 == strcmp(cur_arg, "--eliminate-dead-variables")) { + optimizer->RegisterPass(CreateDeadVariableEliminationPass()); } else if (0 == strcmp(cur_arg, "--fold-spec-const-op-composite")) { optimizer->RegisterPass(CreateFoldSpecConstantOpAndCompositePass()); } else if (0 == strcmp(cur_arg, "--strength-reduction")) { -- cgit v1.2.3