Enhance InsertPHITranslatedPointer to be able to return a list of newly
authorChris Lattner <sabre@nondot.org>
Sat, 28 Nov 2009 15:39:14 +0000 (15:39 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 28 Nov 2009 15:39:14 +0000 (15:39 +0000)
inserted instructions.  No functionality change until someone starts using it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90039 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/MemoryDependenceAnalysis.h
lib/Analysis/MemoryDependenceAnalysis.cpp
lib/Transforms/Scalar/GVN.cpp

index 390ca76b6450daede673cb2f627d11b8d172de53..6b300fd9503e75c81fd2fdd89196494028da4c37 100644 (file)
@@ -261,11 +261,12 @@ namespace llvm {
     
     /// InsertPHITranslatedPointer - Insert a computation of the PHI translated
     /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
-    /// block.
+    /// block.  All newly created instructions are added to the NewInsts list.
     Value *InsertPHITranslatedPointer(Value *V,
                                       BasicBlock *CurBB, BasicBlock *PredBB,
                                       const TargetData *TD,
-                                      const DominatorTree &DT) const;
+                                      const DominatorTree &DT,
+                                 SmallVectorImpl<Instruction*> &NewInsts) const;
     
     /// removeInstruction - Remove an instruction from the dependence analysis,
     /// updating the dependence of instructions that previously depended on it.
index 9644104c490aff10c4d35b08c5ba28829883e443..4cbb62790d896d9cc5928dcf2d7cb2710914bf20 100644 (file)
@@ -879,14 +879,13 @@ GetAvailablePHITranslatedValue(Value *V,
 
 /// InsertPHITranslatedPointer - Insert a computation of the PHI translated
 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
-/// block.
+/// block.  All newly created instructions are added to the NewInsts list.
 ///
-/// This is only called when PHITranslatePointer returns a value that doesn't
-/// dominate the block, so we don't need to handle the trivial cases here.
 Value *MemoryDependenceAnalysis::
 InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
                            BasicBlock *PredBB, const TargetData *TD,
-                           const DominatorTree &DT) const {
+                           const DominatorTree &DT,
+                           SmallVectorImpl<Instruction*> &NewInsts) const {
   // See if we have a version of this value already available and dominating
   // PredBB.  If so, there is no need to insert a new copy.
   if (Value *Res = GetAvailablePHITranslatedValue(InVal, CurBB, PredBB, TD, DT))
@@ -899,13 +898,15 @@ InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
   // Handle bitcast of PHI translatable value.
   if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) {
     Value *OpVal = InsertPHITranslatedPointer(BC->getOperand(0),
-                                              CurBB, PredBB, TD, DT);
+                                              CurBB, PredBB, TD, DT, NewInsts);
     if (OpVal == 0) return 0;
       
     // Otherwise insert a bitcast at the end of PredBB.
-    return new BitCastInst(OpVal, InVal->getType(),
-                           InVal->getName()+".phi.trans.insert",
-                           PredBB->getTerminator());
+    BitCastInst *New = new BitCastInst(OpVal, InVal->getType(),
+                                       InVal->getName()+".phi.trans.insert",
+                                       PredBB->getTerminator());
+    NewInsts.push_back(New);
+    return New;
   }
   
   // Handle getelementptr with at least one PHI operand.
@@ -914,7 +915,7 @@ InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
     BasicBlock *CurBB = GEP->getParent();
     for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) {
       Value *OpVal = InsertPHITranslatedPointer(GEP->getOperand(i),
-                                                CurBB, PredBB, TD, DT);
+                                                CurBB, PredBB, TD, DT, NewInsts);
       if (OpVal == 0) return 0;
       GEPOps.push_back(OpVal);
     }
@@ -924,6 +925,7 @@ InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
                                 InVal->getName()+".phi.trans.insert",
                                 PredBB->getTerminator());
     Result->setIsInBounds(GEP->isInBounds());
+    NewInsts.push_back(Result);
     return Result;
   }
   
@@ -937,7 +939,7 @@ InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
       isa<ConstantInt>(Inst->getOperand(1))) {
     // PHI translate the LHS.
     Value *OpVal = InsertPHITranslatedPointer(Inst->getOperand(0),
-                                              CurBB, PredBB, TD, DT);
+                                              CurBB, PredBB, TD, DT, NewInsts);
     if (OpVal == 0) return 0;
     
     BinaryOperator *Res = BinaryOperator::CreateAdd(OpVal, Inst->getOperand(1),
@@ -945,6 +947,7 @@ InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
                                                     PredBB->getTerminator());
     Res->setHasNoSignedWrap(cast<BinaryOperator>(Inst)->hasNoSignedWrap());
     Res->setHasNoUnsignedWrap(cast<BinaryOperator>(Inst)->hasNoUnsignedWrap());
+    NewInsts.push_back(Res);
     return Res;
   }
 #endif
index cdc3a4efc1ff938b824d4e6f87df69337a577711..6311491c7d3f8ec664aab7f3624ce2fcb9c48735 100644 (file)
@@ -1437,10 +1437,11 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
   //
   // FIXME: This may insert a computation, but we don't tell scalar GVN
   // optimization stuff about it.  How do we do this?
+  SmallVector<Instruction*, 8> NewInsts;
 #if 0
   Value *LoadPtr =
     MD->InsertPHITranslatedPointer(LI->getOperand(0), LoadBB,
-                                   UnavailablePred, TD, *DT);
+                                   UnavailablePred, TD, *DT, NewInsts);
 #else
   Value *LoadPtr =
     MD->GetAvailablePHITranslatedValue(LI->getOperand(0), LoadBB,
@@ -1465,6 +1466,7 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
   // we do not have this case.  Otherwise, check that the load is safe to
   // put anywhere; this can be improved, but should be conservatively safe.
   if (!allSingleSucc &&
+      // FIXME: REEVALUTE THIS.
       !isSafeToLoadUnconditionally(LoadPtr, UnavailablePred->getTerminator()))
     return false;