Convert optimizations to the pass infrastructure
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@873 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index c135f65..ef92b2d 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -246,7 +246,7 @@
return false;
}
-bool opt::DoMethodInlining(Method *M) {
+bool opt::MethodInlining::doMethodInlining(Method *M) {
bool Changed = false;
// Loop through now and inline instructions a basic block at a time...
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index 18c851b..14a1811 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/lib/Transforms/Scalar/ADCE.cpp
@@ -293,9 +293,9 @@
-// DoADCE - Execute the Agressive Dead Code Elimination Algorithm
+// doADCE - Execute the Agressive Dead Code Elimination Algorithm
//
-bool opt::DoADCE(Method *M) {
+bool opt::AgressiveDCE::doADCE(Method *M) {
if (M->isExternal()) return false;
ADCE DCE(M);
return DCE.doADCE();
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 61c026a..6ab9780 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -199,7 +199,7 @@
// returns true on failure, false on success...
//
-bool opt::DoConstantPropogation(Method *M) {
+bool opt::ConstantPropogation::doConstantPropogation(Method *M) {
bool Modified = false;
// Fold constants until we make no progress...
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 @@
// 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;
}
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index f91b786..101e892 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -507,7 +507,7 @@
// DoSparseConditionalConstantProp - Use Sparse Conditional Constant Propogation
// to prove whether a value is constant and whether blocks are used.
//
-bool opt::DoSCCP(Method *M) {
+bool opt::SCCPPass::doSCCP(Method *M) {
if (M->isExternal()) return false;
SCCP S(M);
return S.doSCCP();
diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp
index 6104b62..06cf025 100644
--- a/lib/Transforms/Scalar/SymbolStripping.cpp
+++ b/lib/Transforms/Scalar/SymbolStripping.cpp
@@ -44,16 +44,16 @@
// DoSymbolStripping - Remove all symbolic information from a method
//
-bool opt::DoSymbolStripping(Method *M) {
+bool opt::SymbolStripping::doSymbolStripping(Method *M) {
return StripSymbolTable(M->getSymbolTable());
}
-// DoFullSymbolStripping - Remove all symbolic information from all methods
+// doStripGlobalSymbols - Remove all symbolic information from all methods
// in a module, and all module level symbols. (method names, etc...)
//
-bool opt::DoFullSymbolStripping(Module *M) {
+bool opt::FullSymbolStripping::doStripGlobalSymbols(Module *M) {
// Remove all symbols from methods in this module... and then strip all of the
// symbols in this module...
//
- return DoSymbolStripping(M) | StripSymbolTable(M->getSymbolTable());
+ return StripSymbolTable(M->getSymbolTable());
}