summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/DCE.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-02-26 21:46:54 +0000
committerChris Lattner <sabre@nondot.org>2002-02-26 21:46:54 +0000
commitbd0ef77cde9c9e82f2b4ad33e4982c46274d6540 (patch)
tree0903b61112c9e6d336c8b623e235ede2f937f13c /lib/Transforms/Scalar/DCE.cpp
parent3b2541424f771ae11c30675ce06da7b380780028 (diff)
downloadllvm-bd0ef77cde9c9e82f2b4ad33e4982c46274d6540.tar.gz
llvm-bd0ef77cde9c9e82f2b4ad33e4982c46274d6540.tar.bz2
llvm-bd0ef77cde9c9e82f2b4ad33e4982c46274d6540.tar.xz
Change over to use new style pass mechanism, now passes only expose small
creation functions in their public header file, unless they can help it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/DCE.cpp')
-rw-r--r--lib/Transforms/Scalar/DCE.cpp58
1 files changed, 43 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp
index 8f351a1431..491c957fb2 100644
--- a/lib/Transforms/Scalar/DCE.cpp
+++ b/lib/Transforms/Scalar/DCE.cpp
@@ -32,6 +32,7 @@
#include "llvm/iPHINode.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Pass.h"
#include "Support/STLExtras.h"
#include <algorithm>
@@ -40,8 +41,8 @@
// to point to the instruction that immediately succeeded the original
// instruction.
//
-bool DeadCodeElimination::dceInstruction(BasicBlock::InstListType &BBIL,
- BasicBlock::iterator &BBI) {
+bool dceInstruction(BasicBlock::InstListType &BBIL,
+ BasicBlock::iterator &BBI) {
// Look for un"used" definitions...
if ((*BBI)->use_empty() && !(*BBI)->hasSideEffects() &&
!isa<TerminatorInst>(*BBI)) {
@@ -55,15 +56,21 @@ static inline bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) {
bool Changed = false;
for (BasicBlock::InstListType::iterator DI = Vals.begin();
DI != Vals.end(); )
- if (DeadCodeElimination::dceInstruction(Vals, DI))
+ if (dceInstruction(Vals, DI))
Changed = true;
else
++DI;
return Changed;
}
-bool DeadInstElimination::runOnBasicBlock(BasicBlock *BB) {
- return RemoveUnusedDefs(BB->getInstList());
+struct DeadInstElimination : public BasicBlockPass {
+ virtual bool runOnBasicBlock(BasicBlock *BB) {
+ return RemoveUnusedDefs(BB->getInstList());
+ }
+};
+
+Pass *createDeadInstEliminationPass() {
+ return new DeadInstElimination();
}
// RemoveSingularPHIs - This removes PHI nodes from basic blocks that have only
@@ -297,17 +304,11 @@ static bool DoDCEPass(Method *M) {
return Changed;
}
-
-// It is possible that we may require multiple passes over the code to fully
-// eliminate dead code. Iterate until we are done.
+// Remove unused global values - This removes unused global values of no
+// possible value. This currently includes unused method prototypes and
+// unitialized global variables.
//
-bool DeadCodeElimination::doDCE(Method *M) {
- bool Changed = false;
- while (DoDCEPass(M)) Changed = true;
- return Changed;
-}
-
-bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) {
+static bool RemoveUnusedGlobalValues(Module *Mod) {
bool Changed = false;
for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) {
@@ -338,3 +339,30 @@ bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) {
return Changed;
}
+
+namespace {
+ struct DeadCodeElimination : public MethodPass {
+
+ // Pass Interface...
+ virtual bool doInitialization(Module *M) {
+ return RemoveUnusedGlobalValues(M);
+ }
+
+ // It is possible that we may require multiple passes over the code to fully
+ // eliminate dead code. Iterate until we are done.
+ //
+ virtual bool runOnMethod(Method *M) {
+ bool Changed = false;
+ while (DoDCEPass(M)) Changed = true;
+ return Changed;
+ }
+
+ virtual bool doFinalization(Module *M) {
+ return RemoveUnusedGlobalValues(M);
+ }
+ };
+}
+
+Pass *createDeadCodeEliminationPass() {
+ return new DeadCodeElimination();
+}