[llvm-commits] [llvm] r90039 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp
Chris Lattner
sabre at nondot.org
Sat Nov 28 07:39:14 PST 2009
Author: lattner
Date: Sat Nov 28 09:39:14 2009
New Revision: 90039
URL: http://llvm.org/viewvc/llvm-project?rev=90039&view=rev
Log:
Enhance InsertPHITranslatedPointer to be able to return a list of newly
inserted instructions. No functionality change until someone starts using it.
Modified:
llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=90039&r1=90038&r2=90039&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Sat Nov 28 09:39:14 2009
@@ -261,11 +261,12 @@
/// 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.
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=90039&r1=90038&r2=90039&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sat Nov 28 09:39:14 2009
@@ -879,14 +879,13 @@
/// 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 @@
// 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 @@
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 @@
InVal->getName()+".phi.trans.insert",
PredBB->getTerminator());
Result->setIsInBounds(GEP->isInBounds());
+ NewInsts.push_back(Result);
return Result;
}
@@ -937,7 +939,7 @@
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 @@
PredBB->getTerminator());
Res->setHasNoSignedWrap(cast<BinaryOperator>(Inst)->hasNoSignedWrap());
Res->setHasNoUnsignedWrap(cast<BinaryOperator>(Inst)->hasNoUnsignedWrap());
+ NewInsts.push_back(Res);
return Res;
}
#endif
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=90039&r1=90038&r2=90039&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sat Nov 28 09:39:14 2009
@@ -1437,10 +1437,11 @@
//
// 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 @@
// 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;
More information about the llvm-commits
mailing list