[llvm-commits] CVS: llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp PredicateSimplifier.cpp Reassociate.cpp

Bill Wendling isanbard at gmail.com
Thu Dec 7 12:05:11 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

CorrelatedExprs.cpp updated: 1.39 -> 1.40
PredicateSimplifier.cpp updated: 1.37 -> 1.38
Reassociate.cpp updated: 1.67 -> 1.68
---
Log message:

Removing even more <iostream> includes.


---
Diffs of the changes:  (+60 -71)

 CorrelatedExprs.cpp     |   35 ++++++++++++---------------
 PredicateSimplifier.cpp |   62 ++++++++++++++++++++++--------------------------
 Reassociate.cpp         |   34 +++++++++++---------------
 3 files changed, 60 insertions(+), 71 deletions(-)


Index: llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp
diff -u llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.39 llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.40
--- llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.39	Wed Dec  6 11:46:32 2006
+++ llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp	Thu Dec  7 14:04:42 2006
@@ -42,7 +42,6 @@
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include <algorithm>
-#include <iostream>
 using namespace llvm;
 
 namespace {
@@ -336,7 +335,7 @@
   ComputeReplacements(RI);
 
   // If debugging, print computed region information...
-  DEBUG(RI.print(std::cerr));
+  DEBUG(RI.print(*cerr.stream()));
 
   // Simplify the contents of this block...
   bool Changed = SimplifyBasicBlock(*BB, RI);
@@ -517,11 +516,10 @@
   BasicBlock *OldSucc = TI->getSuccessor(SuccNo);
   BasicBlock *BB = TI->getParent();
 
-  DEBUG(std::cerr << "Forwarding branch in basic block %" << BB->getName()
-        << " from block %" << OldSucc->getName() << " to block %"
-        << Dest->getName() << "\n");
-
-  DEBUG(std::cerr << "Before forwarding: " << *BB->getParent());
+  DOUT << "Forwarding branch in basic block %" << BB->getName()
+       << " from block %" << OldSucc->getName() << " to block %"
+       << Dest->getName() << "\n"
+       << "Before forwarding: " << *BB->getParent();
 
   // Because we know that there cannot be critical edges in the flow graph, and
   // that OldSucc has multiple outgoing edges, this means that Dest cannot have
@@ -628,7 +626,7 @@
   // FIXME: This is much worse than it really should be!
   //EF->recalculate();
 
-  DEBUG(std::cerr << "After forwarding: " << *BB->getParent());
+  DOUT << "After forwarding: " << *BB->getParent();
 }
 
 /// ReplaceUsesOfValueInRegion - This method replaces all uses of Orig with uses
@@ -921,9 +919,9 @@
   //
   if (Op1R.contradicts(Opcode, VI)) {
     Op1R.contradicts(Opcode, VI);
-    std::cerr << "Contradiction found for opcode: "
-              << Instruction::getOpcodeName(Opcode) << "\n";
-    Op1R.print(std::cerr);
+    cerr << "Contradiction found for opcode: "
+         << Instruction::getOpcodeName(Opcode) << "\n";
+    Op1R.print(*cerr.stream());
     return;
   }
 
@@ -1033,8 +1031,7 @@
       // Try to simplify a setcc instruction based on inherited information
       Relation::KnownResult Result = getSetCCResult(SCI, RI);
       if (Result != Relation::Unknown) {
-        DEBUG(std::cerr << "Replacing setcc with " << Result
-                        << " constant: " << *SCI);
+        DOUT << "Replacing setcc with " << Result << " constant: " << *SCI;
 
         SCI->replaceAllUsesWith(ConstantBool::get((bool)Result));
         // The instruction is now dead, remove it from the program.
@@ -1061,8 +1058,8 @@
       if (Value *Repl = VI->getReplacement()) {
         // If we know if a replacement with lower rank than Op0, make the
         // replacement now.
-        DEBUG(std::cerr << "In Inst: " << *I << "  Replacing operand #" << i
-                        << " with " << *Repl << "\n");
+        DOUT << "In Inst: " << *I << "  Replacing operand #" << i
+             << " with " << *Repl << "\n";
         I->setOperand(i, Repl);
         Changed = true;
         ++NumOperandsCann;
@@ -1090,7 +1087,7 @@
     if (isa<Constant>(Op1)) {
       if (Constant *Result = ConstantFoldInstruction(SCI)) {
         // Wow, this is easy, directly eliminate the SetCondInst.
-        DEBUG(std::cerr << "Replacing setcc with constant fold: " << *SCI);
+        DOUT << "Replacing setcc with constant fold: " << *SCI;
         return cast<ConstantBool>(Result)->getValue()
           ? Relation::KnownTrue : Relation::KnownFalse;
       }
@@ -1313,6 +1310,6 @@
 }
 
 // Don't inline these methods or else we won't be able to call them from GDB!
-void Relation::dump() const { print(std::cerr); }
-void ValueInfo::dump() const { print(std::cerr, 0); }
-void RegionInfo::dump() const { print(std::cerr); }
+void Relation::dump() const { print(*cerr.stream()); }
+void ValueInfo::dump() const { print(*cerr.stream(), 0); }
+void RegionInfo::dump() const { print(*cerr.stream()); }


Index: llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp
diff -u llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.37 llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.38
--- llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.37	Wed Dec  6 12:13:12 2006
+++ llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp	Thu Dec  7 14:04:42 2006
@@ -88,7 +88,6 @@
 #include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
 #include <deque>
-#include <iostream>
 #include <sstream>
 #include <map>
 using namespace llvm;
@@ -272,7 +271,7 @@
     }
 
     Node *newNode(Value *V) {
-      //DEBUG(std::cerr << "new node: " << *V << "\n");
+      //DOUT << "new node: " << *V << "\n";
       materialize();
       Node *&N = Nodes[V];
       assert(N == 0 && "Node already exists for value.");
@@ -561,7 +560,7 @@
     }
 
     void addToWorklist(Instruction *I) {
-      //DEBUG(std::cerr << "addToWorklist: " << *I << "\n");
+      //DOUT << "addToWorklist: " << *I << "\n";
 
       if (!isa<BinaryOperator>(I) && !isa<SelectInst>(I)) return;
 
@@ -574,7 +573,7 @@
     }
 
     void addRecursive(Value *V) {
-      //DEBUG(std::cerr << "addRecursive: " << *V << "\n");
+      //DOUT << "addRecursive: " << *V << "\n";
 
       Instruction *I = dyn_cast<Instruction>(V);
       if (I)
@@ -582,7 +581,7 @@
       else if (!isa<Argument>(V))
         return;
 
-      //DEBUG(std::cerr << "addRecursive uses...\n");
+      //DOUT << "addRecursive uses...\n";
       for (Value::use_iterator UI = V->use_begin(), UE = V->use_end();
            UI != UE; ++UI) {
         // Use must be either be dominated by Top, or dominate Top.
@@ -594,14 +593,14 @@
       }
 
       if (I) {
-        //DEBUG(std::cerr << "addRecursive ops...\n");
+        //DOUT << "addRecursive ops...\n";
         for (User::op_iterator OI = I->op_begin(), OE = I->op_end();
              OI != OE; ++OI) {
           if (Instruction *Inst = dyn_cast<Instruction>(*OI))
             addToWorklist(Inst);
         }
       }
-      //DEBUG(std::cerr << "exit addRecursive (" << *V << ").\n");
+      //DOUT << "exit addRecursive (" << *V << ").\n";
     }
 
   public:
@@ -660,8 +659,7 @@
     // you may no longer perform any queries on the InequalityGraph.
 
     bool addEqual(Value *V1, Value *V2) {
-      //DEBUG(std::cerr << "addEqual(" << *V1 << ", "
-      //                               << *V2 << ")\n");
+      //DOUT << "addEqual(" << *V1 << ", " << *V2 << ")\n";
       if (isEqual(V1, V2)) return true;
 
       const Node *cN1 = cIG.getNode(V1), *cN2 = cIG.getNode(V2);
@@ -694,8 +692,8 @@
           if (Top != Node_I2 && Node_I2->DominatedBy(Top)) {
             Value *V = V1;
             if (cN1 && compare(V1, cN1->getValue())) V = cN1->getValue();
-            //DEBUG(std::cerr << "Simply removing " << *I2
-            //                << ", replacing with " << *V << "\n");
+            //DOUT << "Simply removing " << *I2
+            //     << ", replacing with " << *V << "\n";
             I2->replaceAllUsesWith(V);
             // leave it dead; it'll get erased later.
             ++NumSimple;
@@ -772,8 +770,7 @@
     }
 
     bool addNotEqual(Value *V1, Value *V2) {
-      //DEBUG(std::cerr << "addNotEqual(" << *V1 << ", "
-      //                                  << *V2 << ")\n");
+      //DOUT << "addNotEqual(" << *V1 << ", " << *V2 << ")\n");
       if (isNotEqual(V1, V2)) return true;
 
       // Never permit %x NE true/false.
@@ -837,9 +834,9 @@
     }
 
     void solve() {
-      DEBUG(std::cerr << "WorkList entry, size: " << WorkList.size() << "\n");
+      DOUT << "WorkList entry, size: " << WorkList.size() << "\n";
       while (!WorkList.empty()) {
-        DEBUG(std::cerr << "WorkList size: " << WorkList.size() << "\n");
+        DOUT << "WorkList size: " << WorkList.size() << "\n";
 
         Instruction *I = WorkList.front();
         WorkList.pop_front();
@@ -847,8 +844,8 @@
         Value *Canonical = cIG.canonicalize(I);
         const Type *Ty = I->getType();
 
-        //DEBUG(std::cerr << "solving: " << *I << "\n");
-        //DEBUG(IG.debug(std::cerr));
+        //DOUT << "solving: " << *I << "\n";
+        //DEBUG(IG.debug(*cerr.stream()));
 
         if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
           Value *Op0 = cIG.canonicalize(BO->getOperand(0)),
@@ -1135,17 +1132,17 @@
 
     // Visits each instruction in the basic block.
     void visitBasicBlock(BasicBlock *BB, InequalityGraph &IG) {
-     DEBUG(std::cerr << "Entering Basic Block: " << BB->getName() << "\n");
-     for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
-       visitInstruction(I++, IG);
+      DOUT << "Entering Basic Block: " << BB->getName() << "\n";
+      for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
+        visitInstruction(I++, IG);
       }
     }
 
     // Tries to simplify each Instruction and add new properties to
     // the PropertySet.
     void visitInstruction(Instruction *I, InequalityGraph &IG) {
-      DEBUG(std::cerr << "Considering instruction " << *I << "\n");
-      DEBUG(IG.debug(std::cerr));
+      DOUT << "Considering instruction " << *I << "\n";
+      DEBUG(IG.debug(*cerr.stream()));
 
       // Sometimes instructions are made dead due to earlier analysis.
       if (isInstructionTriviallyDead(I)) {
@@ -1158,8 +1155,7 @@
       if (V != I) {
         modified = true;
         ++NumInstruction;
-        DEBUG(std::cerr << "Removing " << *I << ", replacing with "
-                        << *V << "\n");
+        DOUT << "Removing " << *I << ", replacing with " << *V << "\n";
         IG.remove(I);
         I->replaceAllUsesWith(V);
         I->eraseFromParent();
@@ -1173,16 +1169,16 @@
         if (V != Oper) {
           modified = true;
           ++NumVarsReplaced;
-          DEBUG(std::cerr << "Resolving " << *I);
+          DOUT << "Resolving " << *I;
           I->setOperand(i, V);
-          DEBUG(std::cerr << " into " << *I);
+          DOUT << " into " << *I;
         }
       }
 
-      //DEBUG(std::cerr << "push (%" << I->getParent()->getName() << ")\n");
+      //DOUT << "push (%" << I->getParent()->getName() << ")\n";
       Forwards visit(this, IG);
       visit.visit(*I);
-      //DEBUG(std::cerr << "pop (%" << I->getParent()->getName() << ")\n");
+      //DOUT << "pop (%" << I->getParent()->getName() << ")\n";
     }
   };
 
@@ -1190,7 +1186,7 @@
     DT = &getAnalysis<DominatorTree>();
     Forest = &getAnalysis<ETForest>();
 
-    DEBUG(std::cerr << "Entering Function: " << F.getName() << "\n");
+    DOUT << "Entering Function: " << F.getName() << "\n";
 
     modified = false;
     WorkList.push_back(State(DT->getRoot(), new InequalityGraph()));
@@ -1236,15 +1232,15 @@
       VRPSolver Solver(*DestProperties, PS->Forest, Dest);
 
       if (Dest == TrueDest) {
-        DEBUG(std::cerr << "(" << BB->getName() << ") true set:\n");
+        DOUT << "(" << BB->getName() << ") true set:\n";
         if (!Solver.addEqual(ConstantBool::getTrue(), Condition)) continue;
         Solver.solve();
-        DEBUG(DestProperties->debug(std::cerr));
+        DEBUG(DestProperties->debug(*cerr.stream()));
       } else if (Dest == FalseDest) {
-        DEBUG(std::cerr << "(" << BB->getName() << ") false set:\n");
+        DOUT << "(" << BB->getName() << ") false set:\n";
         if (!Solver.addEqual(ConstantBool::getFalse(), Condition)) continue;
         Solver.solve();
-        DEBUG(DestProperties->debug(std::cerr));
+        DEBUG(DestProperties->debug(*cerr.stream()));
       }
 
       PS->proceedToSuccessor(DestProperties, Dest);


Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.67 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.68
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.67	Wed Dec  6 11:46:33 2006
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp	Thu Dec  7 14:04:42 2006
@@ -33,7 +33,6 @@
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include <algorithm>
-#include <iostream>
 using namespace llvm;
 
 namespace {
@@ -57,10 +56,10 @@
 ///
 static void PrintOps(Instruction *I, const std::vector<ValueEntry> &Ops) {
   Module *M = I->getParent()->getParent()->getParent();
-  std::cerr << Instruction::getOpcodeName(I->getOpcode()) << " "
+  cerr << Instruction::getOpcodeName(I->getOpcode()) << " "
   << *Ops[0].Op->getType();
   for (unsigned i = 0, e = Ops.size(); i != e; ++i)
-    WriteAsOperand(std::cerr << " ", Ops[i].Op, false, M)
+    WriteAsOperand(*cerr.stream() << " ", Ops[i].Op, false, M)
       << "," << Ops[i].Rank;
 }
   
@@ -169,8 +168,8 @@
       (!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(I)))
     ++Rank;
 
-  //DEBUG(std::cerr << "Calculated Rank[" << V->getName() << "] = "
-  //<< Rank << "\n");
+  //DOUT << "Calculated Rank[" << V->getName() << "] = "
+  //     << Rank << "\n";
 
   return CachedRank = Rank;
 }
@@ -212,7 +211,7 @@
          isReassociableOp(RHS, I->getOpcode()) &&
          "Not an expression that needs linearization?");
 
-  DEBUG(std::cerr << "Linear" << *LHS << *RHS << *I);
+  DOUT << "Linear" << *LHS << *RHS << *I;
 
   // Move the RHS instruction to live immediately before I, avoiding breaking
   // dominator properties.
@@ -225,7 +224,7 @@
 
   ++NumLinear;
   MadeChange = true;
-  DEBUG(std::cerr << "Linearized: " << *I);
+  DOUT << "Linearized: " << *I;
 
   // If D is part of this expression tree, tail recurse.
   if (isReassociableOp(I->getOperand(1), I->getOpcode()))
@@ -320,10 +319,10 @@
     if (I->getOperand(0) != Ops[i].Op ||
         I->getOperand(1) != Ops[i+1].Op) {
       Value *OldLHS = I->getOperand(0);
-      DEBUG(std::cerr << "RA: " << *I);
+      DOUT << "RA: " << *I;
       I->setOperand(0, Ops[i].Op);
       I->setOperand(1, Ops[i+1].Op);
-      DEBUG(std::cerr << "TO: " << *I);
+      DOUT << "TO: " << *I;
       MadeChange = true;
       ++NumChanged;
       
@@ -336,9 +335,9 @@
   assert(i+2 < Ops.size() && "Ops index out of range!");
 
   if (I->getOperand(1) != Ops[i].Op) {
-    DEBUG(std::cerr << "RA: " << *I);
+    DOUT << "RA: " << *I;
     I->setOperand(1, Ops[i].Op);
-    DEBUG(std::cerr << "TO: " << *I);
+    DOUT << "TO: " << *I;
     MadeChange = true;
     ++NumChanged;
   }
@@ -419,7 +418,7 @@
   Sub->replaceAllUsesWith(New);
   Sub->eraseFromParent();
 
-  DEBUG(std::cerr << "Negated: " << *New);
+  DOUT << "Negated: " << *New;
   return New;
 }
 
@@ -693,8 +692,7 @@
 
     // If any factor occurred more than one time, we can pull it out.
     if (MaxOcc > 1) {
-      DEBUG(std::cerr << "\nFACTORING [" << MaxOcc << "]: "
-                      << *MaxOccVal << "\n");
+      DOUT << "\nFACTORING [" << MaxOcc << "]: " << *MaxOccVal << "\n";
       
       // Create a new instruction that uses the MaxOccVal twice.  If we don't do
       // this, we could otherwise run into situations where removing a factor
@@ -807,8 +805,7 @@
   std::vector<ValueEntry> Ops;
   LinearizeExprTree(I, Ops);
   
-  DEBUG(std::cerr << "RAIn:\t"; PrintOps(I, Ops);
-        std::cerr << "\n");
+  DOUT << "RAIn:\t"; DEBUG(PrintOps(I, Ops)); DOUT << "\n";
   
   // Now that we have linearized the tree to a list and have gathered all of
   // the operands and their ranks, sort the operands by their rank.  Use a
@@ -823,7 +820,7 @@
   if (Value *V = OptimizeExpression(I, Ops)) {
     // This expression tree simplified to something that isn't a tree,
     // eliminate it.
-    DEBUG(std::cerr << "Reassoc to scalar: " << *V << "\n");
+    DOUT << "Reassoc to scalar: " << *V << "\n";
     I->replaceAllUsesWith(V);
     RemoveDeadBinaryOp(I);
     return;
@@ -841,8 +838,7 @@
     Ops.pop_back();
   }
   
-  DEBUG(std::cerr << "RAOut:\t"; PrintOps(I, Ops);
-        std::cerr << "\n");
+  DOUT << "RAOut:\t"; DEBUG(PrintOps(I, Ops)); DOUT << "\n";
   
   if (Ops.size() == 1) {
     // This expression tree simplified to something that isn't a tree,






More information about the llvm-commits mailing list