- Somehow I forgot about one / une.
[oota-llvm.git] / lib / Transforms / Scalar / JumpThreading.cpp
index 991b11110b41eec883c6c2b550bf0437f1fa456d..2f91c07c94e20e40d1d99d7e0210c561fcaaf74b 100644 (file)
@@ -52,7 +52,7 @@ namespace {
   class VISIBILITY_HIDDEN JumpThreading : public FunctionPass {
   public:
     static char ID; // Pass identification
-    JumpThreading() : FunctionPass((intptr_t)&ID) {}
+    JumpThreading() : FunctionPass(&ID) {}
 
     bool runOnFunction(Function &F);
     bool ThreadBlock(BasicBlock *BB);
@@ -63,10 +63,12 @@ namespace {
     bool ProcessBranchOnLogical(Value *V, BasicBlock *BB, bool isAnd);
     bool ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB);
   };
-  char JumpThreading::ID = 0;
-  RegisterPass<JumpThreading> X("jump-threading", "Jump Threading");
 }
 
+char JumpThreading::ID = 0;
+static RegisterPass<JumpThreading>
+X("jump-threading", "Jump Threading");
+
 // Public interface to the Jump Threading pass
 FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
 
@@ -114,9 +116,8 @@ BasicBlock *JumpThreading::FactorCommonPHIPreds(PHINode *PN, Constant *CstVal) {
 /// getJumpThreadDuplicationCost - Return the cost of duplicating this block to
 /// thread across it.
 static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
-  BasicBlock::const_iterator I = BB->begin();
   /// Ignore PHI nodes, these will be flattened when duplication happens.
-  while (isa<PHINode>(*I)) ++I;
+  BasicBlock::const_iterator I = BB->getFirstNonPHI();
 
   // Sum up the cost of each instruction until we get to the terminator.  Don't
   // include the terminator because the copy won't include it.
@@ -156,7 +157,7 @@ static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
 /// ThreadBlock - If there are any predecessors whose control can be threaded
 /// through to a successor, transform them now.
 bool JumpThreading::ThreadBlock(BasicBlock *BB) {
-  // See if this block ends with a branch of switch.  If so, see if the
+  // See if this block ends with a branch or switch.  If so, see if the
   // condition is a phi node.  If so, and if an entry of the phi node is a
   // constant, we can thread the block.
   Value *Condition;
@@ -281,8 +282,8 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB,
   // If this is a binary operator tree of the same AND/OR opcode, check the
   // LHS/RHS.
   if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V))
-    if (isAnd && BO->getOpcode() == Instruction::And ||
-        !isAnd && BO->getOpcode() == Instruction::Or) {
+    if ((isAnd && BO->getOpcode() == Instruction::And) ||
+        (!isAnd && BO->getOpcode() == Instruction::Or)) {
       if (ProcessBranchOnLogical(BO->getOperand(0), BB, isAnd))
         return true;
       if (ProcessBranchOnLogical(BO->getOperand(1), BB, isAnd))
@@ -439,20 +440,7 @@ void JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
     
     // We found a use of I outside of BB.  Create a new stack slot to
     // break this inter-block usage pattern.
-    if (!isa<StructType>(I->getType())) {
-      DemoteRegToStack(*I);
-      continue;
-    }
-    
-    // Alternatively, I must be a call or invoke that returns multiple retvals.
-    // We can't use 'DemoteRegToStack' because that will create loads and
-    // stores of aggregates which is not valid yet.  If I is a call, we can just
-    // pull all the getresult instructions up to this block.  If I is an invoke,
-    // we are out of luck.
-    BasicBlock::iterator IP = I; ++IP;
-    for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
-         UI != E; ++UI)
-      cast<GetResultInst>(UI)->moveBefore(IP);
+    DemoteRegToStack(*I);
   }
  
   // We are going to have to map operands from the original BB block to the new