* We were forgetting to pass varargs arguments through a call
[oota-llvm.git] / lib / Transforms / Scalar / CorrelatedExprs.cpp
index 6ba60675fe99fcb806a1861bab86ef5dee916b2f..8e6a2ae5b84fc0f52bf3c57d7d721442237c66cd 100644 (file)
@@ -1,4 +1,11 @@
 //===- CorrelatedExprs.cpp - Pass to detect and eliminated c.e.'s ---------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // Correlated Expression Elimination propagates information from conditional
 // branches to blocks dominated by destinations of the branch.  It propagates
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/CFG.h"
+#include "Support/Debug.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/Statistic.h"
 #include <algorithm>
 
 namespace {
   Statistic<> NumSetCCRemoved("cee", "Number of setcc instruction eliminated");
-  Statistic<> NumOperandsCann("cee", "Number of operands cannonicalized");
+  Statistic<> NumOperandsCann("cee", "Number of operands canonicalized");
   Statistic<> BranchRevectors("cee", "Number of branches revectored");
 
   class ValueInfo;
@@ -120,7 +128,7 @@ namespace {
     void setReplacement(Value *Repl) { Replacement = Repl; }
 
     // getRelation - return the relationship entry for the specified value.
-    // This can invalidate references to other Relation's, so use it carefully.
+    // This can invalidate references to other Relations, so use it carefully.
     //
     Relation &getRelation(Value *V) {
       // Binary search for V's entry...
@@ -290,7 +298,7 @@ bool CEE::runOnFunction(Function &F) {
   DT = &getAnalysis<DominatorTree>();
   
   std::set<BasicBlock*> VisitedBlocks;
-  bool Changed = TransformRegion(&F.getEntryNode(), VisitedBlocks);
+  bool Changed = TransformRegion(&F.getEntryBlock(), VisitedBlocks);
 
   RegionInfoMap.clear();
   RankMap.clear();
@@ -300,7 +308,7 @@ bool CEE::runOnFunction(Function &F) {
 // TransformRegion - Transform the region starting with BB according to the
 // calculated region information for the block.  Transforming the region
 // involves analyzing any information this block provides to successors,
-// propogating the information to successors, and finally transforming
+// propagating the information to successors, and finally transforming
 // successors.
 //
 // This method processes the function in depth first order, which guarantees
@@ -337,7 +345,7 @@ bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
   DominatorTree::Node *BBN = (*DT)[BB];
   if (!RI.empty())        // Time opt: only propagate if we can change something
     for (unsigned i = 0, e = BBN->getChildren().size(); i != e; ++i) {
-      BasicBlock *Dominated = BBN->getChildren()[i]->getNode();
+      BasicBlock *Dominated = BBN->getChildren()[i]->getBlock();
       assert(RegionInfoMap.find(Dominated) == RegionInfoMap.end() &&
              "RegionInfo should be calculated in dominanace order!");
       getRegionInfo(Dominated) = RI;
@@ -362,7 +370,7 @@ bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
 
   // Now that all of our successors have information, recursively process them.
   for (unsigned i = 0, e = BBN->getChildren().size(); i != e; ++i)
-    Changed |= TransformRegion(BBN->getChildren()[i]->getNode(), VisitedBlocks);
+    Changed |= TransformRegion(BBN->getChildren()[i]->getBlock(),VisitedBlocks);
 
   return Changed;
 }
@@ -378,7 +386,7 @@ static bool isBlockSimpleEnough(BasicBlock *BB) {
   // Check the common case first: empty block, or block with just a setcc.
   if (BB->size() == 1 ||
       (BB->size() == 2 && &BB->front() == BI->getCondition() &&
-       BI->getCondition()->use_size() == 1))
+       BI->getCondition()->hasOneUse()))
     return true;
 
   // Check the more complex case now...
@@ -450,11 +458,11 @@ bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
     
   // Put the newly discovered information into the RegionInfo...
   for (BasicBlock::iterator I = OldSucc->begin(), E = OldSucc->end(); I!=E; ++I)
-    if (PHINode *PN = dyn_cast<PHINode>(&*I)) {
+    if (PHINode *PN = dyn_cast<PHINode>(I)) {
       int OpNum = PN->getBasicBlockIndex(BB);
       assert(OpNum != -1 && "PHI doesn't have incoming edge for predecessor!?");
       PropagateEquality(PN, PN->getIncomingValue(OpNum), NewRI);      
-    } else if (SetCondInst *SCI = dyn_cast<SetCondInst>(&*I)) {
+    } else if (SetCondInst *SCI = dyn_cast<SetCondInst>(I)) {
       Relation::KnownResult Res = getSetCCResult(SCI, NewRI);
       if (Res == Relation::Unknown) return false;
       PropagateEquality(SCI, ConstantBool::get(Res), NewRI);
@@ -542,7 +550,7 @@ void CEE::ForwardSuccessorTo(TerminatorInst *TI, unsigned SuccNo,
         // Create and insert the PHI node into the top of Dest.
         PHINode *NewPN = new PHINode(I->getType(), I->getName()+".fw_merge",
                                      Dest->begin());
-        // There is definately an edge from OldSucc... add the edge now
+        // There is definitely an edge from OldSucc... add the edge now
         NewPN->addIncoming(I, OldSucc);
 
         // There is also an edge from BB now, add the edge with the calculated
@@ -563,7 +571,7 @@ void CEE::ForwardSuccessorTo(TerminatorInst *TI, unsigned SuccNo,
   // node with a new value.
   //
   for (BasicBlock::iterator I = OldSucc->begin();
-       PHINode *PN = dyn_cast<PHINode>(&*I); ) {
+       PHINode *PN = dyn_cast<PHINode>(I); ) {
 
     // Get the value flowing across the old edge and remove the PHI node entry
     // for this edge: we are about to remove the edge!  Don't remove the PHI
@@ -885,7 +893,7 @@ void CEE::PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
     return;
 
   // If we already have information that contradicts the current information we
-  // are propogating, ignore this info.  Something bad must have happened!
+  // are propagating, ignore this info.  Something bad must have happened!
   //
   if (Op1R.contradicts(Opcode, VI)) {
     Op1R.contradicts(Opcode, VI);
@@ -895,7 +903,7 @@ void CEE::PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
     return;
   }
 
-  // If the information propogted is new, then we want process the uses of this
+  // If the information propagated is new, then we want process the uses of this
   // instruction to propagate the information down to them.
   //
   if (Op1R.incorporate(Opcode, VI))
@@ -949,7 +957,7 @@ void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
 // X and a constant C, we can replace all uses of X with C in the region we are
 // interested in.  We generalize this replacement to replace variables with
 // other variables if they are equal and there is a variable with lower rank
-// than the current one.  This offers a cannonicalizing property that exposes
+// than the current one.  This offers a canonicalizing property that exposes
 // more redundancies for later transformations to take advantage of.
 //
 void CEE::ComputeReplacements(RegionInfo &RI) {
@@ -993,7 +1001,7 @@ void CEE::ComputeReplacements(RegionInfo &RI) {
 bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
   bool Changed = false;
   for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ) {
-    Instruction *Inst = &*I++;
+    Instruction *Inst = I++;
 
     // Convert instruction arguments to canonical forms...
     Changed |= SimplifyInstruction(Inst, RI);
@@ -1018,7 +1026,7 @@ bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
 }
 
 // SimplifyInstruction - Inspect the operands of the instruction, converting
-// them to their cannonical form if possible.  This takes care of, for example,
+// them to their canonical form if possible.  This takes care of, for example,
 // replacing a value 'X' with a constant 'C' if the instruction in question is
 // dominated by a true seteq 'X', 'C'.
 //