diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-18 01:32:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-18 01:32:34 +0000 |
commit | 5680ee6b28974c9cf6cab9f603d30e6eda2715bc (patch) | |
tree | df79e5aa71c1c74139b2bd5f98f43abef2398403 /lib/Transforms/Scalar/DCE.cpp | |
parent | 989305bb239abd4e2617af935e40afd80a122c22 (diff) | |
download | external_llvm-5680ee6b28974c9cf6cab9f603d30e6eda2715bc.zip external_llvm-5680ee6b28974c9cf6cab9f603d30e6eda2715bc.tar.gz external_llvm-5680ee6b28974c9cf6cab9f603d30e6eda2715bc.tar.bz2 |
Convert optimizations to the pass infrastructure
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@873 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/DCE.cpp')
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 10dcf1e..e089525 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -26,6 +26,7 @@ #include "llvm/Optimizations/DCE.h" #include "llvm/Support/STLExtras.h" #include "llvm/Module.h" +#include "llvm/GlobalVariable.h" #include "llvm/Method.h" #include "llvm/BasicBlock.h" #include "llvm/iTerminators.h" @@ -293,28 +294,40 @@ static bool DoDCEPass(Method *M) { // It is possible that we may require multiple passes over the code to fully // eliminate dead code. Iterate until we are done. // -bool opt::DoDeadCodeElimination(Method *M) { +bool opt::DeadCodeElimination::doDCE(Method *M) { bool Changed = false; while (DoDCEPass(M)) Changed = true; return Changed; } -bool opt::DoDeadCodeElimination(Module *Mod) { +bool opt::DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) { bool Changed = false; for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) { Method *Meth = *MI; - if (!Meth->isExternal()) { // DCE normal methods - Changed |= DoDeadCodeElimination(Meth); - ++MI; // Next method please - } else if (Meth->use_size() == 0) { // No references to prototype? + if (Meth->isExternal() && Meth->use_size() == 0) { + // No references to prototype? //cerr << "Removing method proto: " << Meth->getName() << endl; delete Mod->getMethodList().remove(MI); // Remove prototype // Remove moves iterator to point to the next one automatically + Changed = true; } else { ++MI; // Skip prototype in use. } } + for (Module::giterator GI = Mod->gbegin(); GI != Mod->gend(); ) { + GlobalVariable *GV = *GI; + if (!GV->hasInitializer() && GV->use_size() == 0) { + // No references to uninitialized global variable? + //cerr << "Removing global var: " << GV->getName() << endl; + delete Mod->getGlobalList().remove(GI); + // Remove moves iterator to point to the next one automatically + Changed = true; + } else { + ++GI; + } + } + return Changed; } |