summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-29 21:26:08 +0000
committerChris Lattner <sabre@nondot.org>2002-04-29 21:26:08 +0000
commit0dbfc05a2aed61cdb1f83f74474749eb66e0856f (patch)
treee6b91ab1196113a9e3152df47e9cba6067bc524a /lib/Transforms/Scalar
parentf737121054875a71c4abad158bab455bb1637397 (diff)
downloadexternal_llvm-0dbfc05a2aed61cdb1f83f74474749eb66e0856f.zip
external_llvm-0dbfc05a2aed61cdb1f83f74474749eb66e0856f.tar.gz
external_llvm-0dbfc05a2aed61cdb1f83f74474749eb66e0856f.tar.bz2
Significantly clean up SCCP pass. Now the two classes are merged and in
an anonymous namespace where they belong. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2415 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp81
1 files changed, 37 insertions, 44 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 1a3649e..e4e1e7c 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -33,6 +33,7 @@ using std::cerr;
// InstVal class - This class represents the different lattice values that an
// instruction may occupy. It is a simple class with value semantics.
//
+namespace {
class InstVal {
enum {
undefined, // This instruction has no known value
@@ -72,34 +73,37 @@ public:
inline Constant *getConstant() const { return ConstantVal; }
};
+} // end anonymous namespace
//===----------------------------------------------------------------------===//
// SCCP Class
//
// This class does all of the work of Sparse Conditional Constant Propogation.
-// It's public interface consists of a constructor and a doSCCP() function.
//
-class SCCP : public InstVisitor<SCCP> {
- Function *M; // The function that we are working on
-
+namespace {
+class SCCP : public FunctionPass, public InstVisitor<SCCP> {
std::set<BasicBlock*> BBExecutable;// The basic blocks that are executable
std::map<Value*, InstVal> ValueState; // The state each value is in...
std::vector<Instruction*> InstWorkList;// The instruction work list
std::vector<BasicBlock*> BBWorkList; // The BasicBlock work list
+public:
- //===--------------------------------------------------------------------===//
- // The public interface for this class
+ const char *getPassName() const {
+ return "Sparse Conditional Constant Propogation";
+ }
+
+ // runOnFunction - Run the Sparse Conditional Constant Propogation algorithm,
+ // and return true if the function was modified.
//
-public:
+ bool runOnFunction(Function *F);
- // SCCP Ctor - Save the function to operate on...
- inline SCCP(Function *f) : M(f) {}
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ // FIXME: SCCP does not preserve the CFG because it folds terminators!
+ //AU.preservesCFG();
+ }
- // doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
- // return true if the function was modified.
- bool doSCCP();
//===--------------------------------------------------------------------===//
// The implementation of this class
@@ -200,18 +204,27 @@ private:
//
void OperandChangedState(User *U);
};
+} // end anonymous namespace
+
+
+// createSCCPPass - This is the public interface to this file...
+//
+Pass *createSCCPPass() {
+ return new SCCP();
+}
+
//===----------------------------------------------------------------------===//
// SCCP Class Implementation
-// doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
-// return true if the function was modified.
+// runOnFunction() - Run the Sparse Conditional Constant Propogation algorithm,
+// and return true if the function was modified.
//
-bool SCCP::doSCCP() {
+bool SCCP::runOnFunction(Function *F) {
// Mark the first block of the function as being executable...
- markExecutable(M->front());
+ markExecutable(F->front());
// Process the work lists until their are empty!
while (!BBWorkList.empty() || !InstWorkList.empty()) {
@@ -252,7 +265,7 @@ bool SCCP::doSCCP() {
}
#if 0
- for (Function::iterator BBI = M->begin(), BBEnd = M->end();
+ for (Function::iterator BBI = F->begin(), BBEnd = F->end();
BBI != BBEnd; ++BBI)
if (!BBExecutable.count(*BBI))
cerr << "BasicBlock Dead:" << *BBI;
@@ -263,8 +276,8 @@ bool SCCP::doSCCP() {
// constants if we have found them to be of constant values.
//
bool MadeChanges = false;
- for (Function::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
- BasicBlock *BB = *MI;
+ for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
+ BasicBlock *BB = *FI;
for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
Instruction *Inst = *BI;
InstVal &IV = ValueState[Inst];
@@ -280,7 +293,7 @@ bool SCCP::doSCCP() {
// The new constant inherits the old name of the operator...
if (Inst->hasName() && !Const->hasName())
- Const->setName(Inst->getName(), M->getSymbolTableSure());
+ Const->setName(Inst->getName(), F->getSymbolTableSure());
// Delete the operator now...
delete Inst;
@@ -295,6 +308,10 @@ bool SCCP::doSCCP() {
}
}
+ // Reset state so that the next invokation will have empty data structures
+ BBExecutable.clear();
+ ValueState.clear();
+
// Merge identical constants last: this is important because we may have just
// introduced constants that already exist, and we don't want to pollute later
// stages with extraneous constants.
@@ -457,27 +474,3 @@ void SCCP::OperandChangedState(User *U) {
visit(I);
}
-
-namespace {
- // SCCPPass - Use Sparse Conditional Constant Propogation
- // to prove whether a value is constant and whether blocks are used.
- //
- struct SCCPPass : public FunctionPass {
- const char *getPassName() const {
- return "Sparse Conditional Constant Propogation";
- }
-
- inline bool runOnFunction(Function *F) {
- SCCP S(F);
- return S.doSCCP();
- }
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- // FIXME: SCCP does not preserve the CFG because it folds terminators!
- //AU.preservesCFG();
- }
- };
-}
-
-Pass *createSCCPPass() {
- return new SCCPPass();
-}