From b68ec5c339903ea05caaac13c37be9a21318239e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 15 Jan 2011 00:12:35 +0000 Subject: Generalize LoadAndStorePromoter a bit and switch LICM to use it. llvm-svn: 123501 --- llvm/lib/Transforms/Utils/SSAUpdater.cpp | 41 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'llvm/lib/Transforms/Utils/SSAUpdater.cpp') diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 2ecae356ff9..0474a7842d1 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -348,23 +348,25 @@ Value *SSAUpdater::GetValueAtEndOfBlockInternal(BasicBlock *BB) { // LoadAndStorePromoter Implementation //===----------------------------------------------------------------------===// -void LoadAndStorePromoter::run(StringRef BaseName, - const SmallVectorImpl &Insts, - SSAUpdater *SSA) { +LoadAndStorePromoter:: +LoadAndStorePromoter(const SmallVectorImpl &Insts, + SSAUpdater &S, StringRef BaseName) : SSA(S) { if (Insts.empty()) return; - // If no SSAUpdater was provided, use a default one. This allows the client - // to capture inserted PHI nodes etc if they want. - SSAUpdater DefaultSSA; - if (SSA == 0) SSA = &DefaultSSA; - - const Type *ValTy; + Value *SomeVal; if (LoadInst *LI = dyn_cast(Insts[0])) - ValTy = LI->getType(); + SomeVal = LI; else - ValTy = cast(Insts[0])->getOperand(0)->getType(); - - SSA->Initialize(ValTy, BaseName); + SomeVal = cast(Insts[0])->getOperand(0); + + if (BaseName.empty()) + BaseName = SomeVal->getName(); + SSA.Initialize(SomeVal->getType(), BaseName); +} + + +void LoadAndStorePromoter:: +run(const SmallVectorImpl &Insts) const { // First step: bucket up uses of the alloca by the block they occur in. // This is important because we have to handle multiple defs/uses in a block @@ -396,7 +398,7 @@ void LoadAndStorePromoter::run(StringRef BaseName, if (BlockUses.size() == 1) { // If it is a store, it is a trivial def of the value in the block. if (StoreInst *SI = dyn_cast(User)) - SSA->AddAvailableValue(BB, SI->getOperand(0)); + SSA.AddAvailableValue(BB, SI->getOperand(0)); else // Otherwise it is a load, queue it to rewrite as a live-in load. LiveInLoads.push_back(cast(User)); @@ -437,6 +439,7 @@ void LoadAndStorePromoter::run(StringRef BaseName, // If we haven't seen a store yet, this is a live in use, otherwise // use the stored value. if (StoredValue) { + replaceLoadWithValue(L, StoredValue); L->replaceAllUsesWith(StoredValue); ReplacedLoads[L] = StoredValue; } else { @@ -456,7 +459,7 @@ void LoadAndStorePromoter::run(StringRef BaseName, // The last stored value that happened is the live-out for the block. assert(StoredValue && "Already checked that there is a store in block"); - SSA->AddAvailableValue(BB, StoredValue); + SSA.AddAvailableValue(BB, StoredValue); BlockUses.clear(); } @@ -464,11 +467,15 @@ void LoadAndStorePromoter::run(StringRef BaseName, // inserting PHI nodes as necessary. for (unsigned i = 0, e = LiveInLoads.size(); i != e; ++i) { LoadInst *ALoad = LiveInLoads[i]; - Value *NewVal = SSA->GetValueInMiddleOfBlock(ALoad->getParent()); + Value *NewVal = SSA.GetValueInMiddleOfBlock(ALoad->getParent()); + replaceLoadWithValue(ALoad, NewVal); ALoad->replaceAllUsesWith(NewVal); ReplacedLoads[ALoad] = NewVal; } + // Allow the client to do stuff before we start nuking things. + doExtraRewritesBeforeFinalDeletion(); + // Now that everything is rewritten, delete the old instructions from the // function. They should all be dead now. for (unsigned i = 0, e = Insts.size(); i != e; ++i) { @@ -491,9 +498,11 @@ void LoadAndStorePromoter::run(StringRef BaseName, RLI = ReplacedLoads.find(NewVal); } + replaceLoadWithValue(cast(User), NewVal); User->replaceAllUsesWith(NewVal); } + instructionDeleted(User); User->eraseFromParent(); } } -- cgit v1.2.3