Changed llvm_ostream et all to OStream. llvm_cerr, llvm_cout, llvm_null, are
[oota-llvm.git] / lib / Transforms / Scalar / SCCP.cpp
index 44634cd7c3b5873b50da1089767ae027798ca03b..5d928c145dfeac5b3a852a1e309426adfdbdbeee 100644 (file)
@@ -36,7 +36,6 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
 #include <algorithm>
-#include <iostream>
 #include <set>
 using namespace llvm;
 
@@ -134,7 +133,7 @@ public:
   /// MarkBlockExecutable - This method can be used by clients to mark all of
   /// the blocks that are known to be intrinsically live in the processed unit.
   void MarkBlockExecutable(BasicBlock *BB) {
-    DEBUG(std::cerr << "Marking Block Executable: " << BB->getName() << "\n");
+    DOUT << "Marking Block Executable: " << BB->getName() << "\n";
     BBExecutable.insert(BB);   // Basic block is executable!
     BBWorkList.push_back(BB);  // Add the block to the work list!
   }
@@ -204,7 +203,7 @@ private:
   //
   inline void markConstant(LatticeVal &IV, Value *V, Constant *C) {
     if (IV.markConstant(C)) {
-      DEBUG(std::cerr << "markConstant: " << *C << ": " << *V);
+      DOUT << "markConstant: " << *C << ": " << *V;
       InstWorkList.push_back(V);
     }
   }
@@ -218,11 +217,11 @@ private:
 
   inline void markOverdefined(LatticeVal &IV, Value *V) {
     if (IV.markOverdefined()) {
-      DEBUG(std::cerr << "markOverdefined: ";
+      DEBUG(DOUT << "markOverdefined: ";
             if (Function *F = dyn_cast<Function>(V))
-              std::cerr << "Function '" << F->getName() << "'\n";
+              DOUT << "Function '" << F->getName() << "'\n";
             else
-              std::cerr << *V);
+              DOUT << *V);
       // Only instructions go on the work list
       OverdefinedInstWorkList.push_back(V);
     }
@@ -276,8 +275,8 @@ private:
       return;  // This edge is already known to be executable!
 
     if (BBExecutable.count(Dest)) {
-      DEBUG(std::cerr << "Marking Edge Executable: " << Source->getName()
-                      << " -> " << Dest->getName() << "\n");
+      DOUT << "Marking Edge Executable: " << Source->getName()
+           << " -> " << Dest->getName() << "\n";
 
       // The destination is already executable, but we just made an edge
       // feasible that wasn't before.  Revisit the PHI nodes in the block
@@ -351,7 +350,7 @@ private:
 
   void visitInstruction(Instruction &I) {
     // If a new instruction is added to LLVM that we don't handle...
-    std::cerr << "SCCP: Don't know how to handle: " << I;
+    cerr << "SCCP: Don't know how to handle: " << I;
     markOverdefined(&I);   // Just in case
   }
 };
@@ -377,7 +376,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
         Succs[BCValue.getConstant() == ConstantBool::getFalse()] = true;
       }
     }
-  } else if (InvokeInst *II = dyn_cast<InvokeInst>(&TI)) {
+  } else if (isa<InvokeInst>(&TI)) {
     // Invoke instructions successors are always executable.
     Succs[0] = Succs[1] = true;
   } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
@@ -401,7 +400,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
       Succs[0] = true;
     }
   } else {
-    std::cerr << "SCCP: Don't know how to handle: " << TI;
+    cerr << "SCCP: Don't know how to handle: " << TI;
     Succs.assign(TI.getNumSuccessors(), true);
   }
 }
@@ -436,7 +435,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
       }
       return false;
     }
-  } else if (InvokeInst *II = dyn_cast<InvokeInst>(TI)) {
+  } else if (isa<InvokeInst>(TI)) {
     // Invoke instructions successors are always executable.
     return true;
   } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
@@ -460,7 +459,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
     }
     return false;
   } else {
-    std::cerr << "Unknown terminator instruction: " << *TI;
+    cerr << "Unknown terminator instruction: " << *TI;
     abort();
   }
 }
@@ -750,6 +749,11 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
 }
 
 void SCCPSolver::visitExtractElementInst(ExtractElementInst &I) {
+  // FIXME : SCCP does not handle vectors properly.
+  markOverdefined(&I);
+  return;
+
+#if 0
   LatticeVal &ValState = getValueState(I.getOperand(0));
   LatticeVal &IdxState = getValueState(I.getOperand(1));
 
@@ -758,9 +762,14 @@ void SCCPSolver::visitExtractElementInst(ExtractElementInst &I) {
   else if(ValState.isConstant() && IdxState.isConstant())
     markConstant(&I, ConstantExpr::getExtractElement(ValState.getConstant(),
                                                      IdxState.getConstant()));
+#endif
 }
 
 void SCCPSolver::visitInsertElementInst(InsertElementInst &I) {
+  // FIXME : SCCP does not handle vectors properly.
+  markOverdefined(&I);
+  return;
+#if 0
   LatticeVal &ValState = getValueState(I.getOperand(0));
   LatticeVal &EltState = getValueState(I.getOperand(1));
   LatticeVal &IdxState = getValueState(I.getOperand(2));
@@ -774,13 +783,18 @@ void SCCPSolver::visitInsertElementInst(InsertElementInst &I) {
                                                     EltState.getConstant(),
                                                     IdxState.getConstant()));
   else if (ValState.isUndefined() && EltState.isConstant() &&
-           IdxState.isConstant())
+           IdxState.isConstant()) 
     markConstant(&I, ConstantExpr::getInsertElement(UndefValue::get(I.getType()),
                                                     EltState.getConstant(),
                                                     IdxState.getConstant()));
+#endif
 }
 
 void SCCPSolver::visitShuffleVectorInst(ShuffleVectorInst &I) {
+  // FIXME : SCCP does not handle vectors properly.
+  markOverdefined(&I);
+  return;
+#if 0
   LatticeVal &V1State   = getValueState(I.getOperand(0));
   LatticeVal &V2State   = getValueState(I.getOperand(1));
   LatticeVal &MaskState = getValueState(I.getOperand(2));
@@ -802,6 +816,7 @@ void SCCPSolver::visitShuffleVectorInst(ShuffleVectorInst &I) {
       MaskState.getConstant() : UndefValue::get(I.getOperand(2)->getType());
     markConstant(&I, ConstantExpr::getShuffleVector(V1, V2, Mask));
   }
+#endif
 }
 
 // Handle getelementptr instructions... if all operands are constants then we
@@ -971,7 +986,7 @@ void SCCPSolver::Solve() {
       Value *I = OverdefinedInstWorkList.back();
       OverdefinedInstWorkList.pop_back();
 
-      DEBUG(std::cerr << "\nPopped off OI-WL: " << *I);
+      DOUT << "\nPopped off OI-WL: " << *I;
 
       // "I" got into the work list because it either made the transition from
       // bottom to constant
@@ -989,7 +1004,7 @@ void SCCPSolver::Solve() {
       Value *I = InstWorkList.back();
       InstWorkList.pop_back();
 
-      DEBUG(std::cerr << "\nPopped off I-WL: " << *I);
+      DOUT << "\nPopped off I-WL: " << *I;
 
       // "I" got into the work list because it either made the transition from
       // bottom to constant
@@ -1009,7 +1024,7 @@ void SCCPSolver::Solve() {
       BasicBlock *BB = BBWorkList.back();
       BBWorkList.pop_back();
 
-      DEBUG(std::cerr << "\nPopped off BBWL: " << *BB);
+      DOUT << "\nPopped off BBWL: " << *BB;
 
       // Notify all instructions in this basic block that they are newly
       // executable.
@@ -1065,8 +1080,8 @@ bool SCCPSolver::ResolveBranchesIn(Function &F) {
 
 
 namespace {
-  Statistic<> NumInstRemoved("sccp", "Number of instructions removed");
-  Statistic<> NumDeadBlocks ("sccp", "Number of basic blocks unreachable");
+  Statistic NumInstRemoved("sccp", "Number of instructions removed");
+  Statistic NumDeadBlocks ("sccp", "Number of basic blocks unreachable");
 
   //===--------------------------------------------------------------------===//
   //
@@ -1098,7 +1113,7 @@ FunctionPass *llvm::createSCCPPass() {
 // and return true if the function was modified.
 //
 bool SCCP::runOnFunction(Function &F) {
-  DEBUG(std::cerr << "SCCP on function '" << F.getName() << "'\n");
+  DOUT << "SCCP on function '" << F.getName() << "'\n";
   SCCPSolver Solver;
 
   // Mark the first block of the function as being executable.
@@ -1113,7 +1128,7 @@ bool SCCP::runOnFunction(Function &F) {
   bool ResolvedBranches = true;
   while (ResolvedBranches) {
     Solver.Solve();
-    DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
+    DOUT << "RESOLVING UNDEF BRANCHES\n";
     ResolvedBranches = Solver.ResolveBranchesIn(F);
   }
 
@@ -1126,7 +1141,7 @@ bool SCCP::runOnFunction(Function &F) {
   std::set<BasicBlock*> &ExecutableBBs = Solver.getExecutableBlocks();
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     if (!ExecutableBBs.count(BB)) {
-      DEBUG(std::cerr << "  BasicBlock Dead:" << *BB);
+      DOUT << "  BasicBlock Dead:" << *BB;
       ++NumDeadBlocks;
 
       // Delete the instructions backwards, as it has a reduced likelihood of
@@ -1156,7 +1171,7 @@ bool SCCP::runOnFunction(Function &F) {
               !isa<TerminatorInst>(Inst)) {
             Constant *Const = IV.isConstant()
               ? IV.getConstant() : UndefValue::get(Inst->getType());
-            DEBUG(std::cerr << "  Constant: " << *Const << " = " << *Inst);
+            DOUT << "  Constant: " << *Const << " = " << *Inst;
 
             // Replaces all of the uses of a variable with uses of the constant.
             Inst->replaceAllUsesWith(Const);
@@ -1176,11 +1191,11 @@ bool SCCP::runOnFunction(Function &F) {
 }
 
 namespace {
-  Statistic<> IPNumInstRemoved("ipsccp", "Number of instructions removed");
-  Statistic<> IPNumDeadBlocks ("ipsccp", "Number of basic blocks unreachable");
-  Statistic<> IPNumArgsElimed ("ipsccp",
+  Statistic IPNumInstRemoved("ipsccp", "Number of instructions removed");
+  Statistic IPNumDeadBlocks ("ipsccp", "Number of basic blocks unreachable");
+  Statistic IPNumArgsElimed ("ipsccp",
                                "Number of arguments constant propagated");
-  Statistic<> IPNumGlobalConst("ipsccp",
+  Statistic IPNumGlobalConst("ipsccp",
                                "Number of globals found to be constant");
 
   //===--------------------------------------------------------------------===//
@@ -1258,7 +1273,7 @@ bool IPSCCP::runOnModule(Module &M) {
   while (ResolvedBranches) {
     Solver.Solve();
 
-    DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
+    DOUT << "RESOLVING UNDEF BRANCHES\n";
     ResolvedBranches = false;
     for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
       ResolvedBranches |= Solver.ResolveBranchesIn(*F);
@@ -1278,7 +1293,7 @@ bool IPSCCP::runOnModule(Module &M) {
         if (IV.isConstant() || IV.isUndefined()) {
           Constant *CST = IV.isConstant() ?
             IV.getConstant() : UndefValue::get(AI->getType());
-          DEBUG(std::cerr << "***  Arg " << *AI << " = " << *CST <<"\n");
+          DOUT << "***  Arg " << *AI << " = " << *CST <<"\n";
 
           // Replaces all of the uses of a variable with uses of the
           // constant.
@@ -1290,7 +1305,7 @@ bool IPSCCP::runOnModule(Module &M) {
     std::vector<BasicBlock*> BlocksToErase;
     for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
       if (!ExecutableBBs.count(BB)) {
-        DEBUG(std::cerr << "  BasicBlock Dead:" << *BB);
+        DOUT << "  BasicBlock Dead:" << *BB;
         ++IPNumDeadBlocks;
 
         // Delete the instructions backwards, as it has a reduced likelihood of
@@ -1333,7 +1348,7 @@ bool IPSCCP::runOnModule(Module &M) {
                 !isa<TerminatorInst>(Inst)) {
               Constant *Const = IV.isConstant()
                 ? IV.getConstant() : UndefValue::get(Inst->getType());
-              DEBUG(std::cerr << "  Constant: " << *Const << " = " << *Inst);
+              DOUT << "  Constant: " << *Const << " = " << *Inst;
 
               // Replaces all of the uses of a variable with uses of the
               // constant.
@@ -1415,7 +1430,7 @@ bool IPSCCP::runOnModule(Module &M) {
     GlobalVariable *GV = I->first;
     assert(!I->second.isOverdefined() &&
            "Overdefined values should have been taken out of the map!");
-    DEBUG(std::cerr << "Found that GV '" << GV->getName()<< "' is constant!\n");
+    DOUT << "Found that GV '" << GV->getName()<< "' is constant!\n";
     while (!GV->use_empty()) {
       StoreInst *SI = cast<StoreInst>(GV->use_back());
       SI->eraseFromParent();