Simplify. Consolidate dbg.declare handling in AllocaPromoter.

llvm-svn: 134538
This commit is contained in:
Devang Patel 2011-07-06 21:09:55 +00:00
parent 9f8c2853ca
commit a3cbf52a57
4 changed files with 27 additions and 29 deletions

View File

@ -122,12 +122,9 @@ private:
class LoadAndStorePromoter { class LoadAndStorePromoter {
protected: protected:
SSAUpdater &SSA; SSAUpdater &SSA;
DbgDeclareInst *DDI;
DIBuilder *DIB;
public: public:
LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts, LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts,
SSAUpdater &S, DbgDeclareInst *DDI, DIBuilder *DIB, SSAUpdater &S, StringRef Name = StringRef());
StringRef Name = StringRef());
virtual ~LoadAndStorePromoter() {} virtual ~LoadAndStorePromoter() {}
/// run - This does the promotion. Insts is a list of loads and stores to /// run - This does the promotion. Insts is a list of loads and stores to
@ -161,6 +158,10 @@ public:
virtual void instructionDeleted(Instruction *I) const { virtual void instructionDeleted(Instruction *I) const {
} }
/// updateDebugInfo - This is called to update debug info associated with the
/// instruction.
virtual void updateDebugInfo(Instruction *I) const {
}
}; };
} // End llvm namespace } // End llvm namespace

View File

@ -613,7 +613,7 @@ namespace {
SmallPtrSet<Value*, 4> &PMA, SmallPtrSet<Value*, 4> &PMA,
SmallVectorImpl<BasicBlock*> &LEB, AliasSetTracker &ast, SmallVectorImpl<BasicBlock*> &LEB, AliasSetTracker &ast,
DebugLoc dl, int alignment) DebugLoc dl, int alignment)
: LoadAndStorePromoter(Insts, S, 0, 0), SomePtr(SP), : LoadAndStorePromoter(Insts, S), SomePtr(SP),
PointerMustAliases(PMA), LoopExitBlocks(LEB), AST(ast), DL(dl), PointerMustAliases(PMA), LoopExitBlocks(LEB), AST(ast), DL(dl),
Alignment(alignment) {} Alignment(alignment) {}

View File

@ -1094,16 +1094,21 @@ bool SROA::runOnFunction(Function &F) {
namespace { namespace {
class AllocaPromoter : public LoadAndStorePromoter { class AllocaPromoter : public LoadAndStorePromoter {
AllocaInst *AI; AllocaInst *AI;
DbgDeclareInst *DDI;
DIBuilder *DIB;
public: public:
AllocaPromoter(const SmallVectorImpl<Instruction*> &Insts, SSAUpdater &S, AllocaPromoter(const SmallVectorImpl<Instruction*> &Insts, SSAUpdater &S,
DbgDeclareInst *DD, DIBuilder *&DB) DIBuilder *DB)
: LoadAndStorePromoter(Insts, S, DD, DB), AI(0) {} : LoadAndStorePromoter(Insts, S), AI(0), DDI(0), DIB(DB) {}
void run(AllocaInst *AI, const SmallVectorImpl<Instruction*> &Insts) { void run(AllocaInst *AI, const SmallVectorImpl<Instruction*> &Insts) {
// Remember which alloca we're promoting (for isInstInList). // Remember which alloca we're promoting (for isInstInList).
this->AI = AI; this->AI = AI;
DDI = FindAllocaDbgDeclare(AI);
LoadAndStorePromoter::run(Insts); LoadAndStorePromoter::run(Insts);
AI->eraseFromParent(); AI->eraseFromParent();
if (DDI)
DDI->eraseFromParent();
} }
virtual bool isInstInList(Instruction *I, virtual bool isInstInList(Instruction *I,
@ -1112,6 +1117,15 @@ public:
return LI->getOperand(0) == AI; return LI->getOperand(0) == AI;
return cast<StoreInst>(I)->getPointerOperand() == AI; return cast<StoreInst>(I)->getPointerOperand() == AI;
} }
virtual void updateDebugInfo(Instruction *I) const {
if (!DDI)
return;
if (StoreInst *SI = dyn_cast<StoreInst>(I))
ConvertDebugDeclareToDebugValue(DDI, SI, *DIB);
else if (LoadInst *LI = dyn_cast<LoadInst>(I))
ConvertDebugDeclareToDebugValue(DDI, LI, *DIB);
}
}; };
} // end anon namespace } // end anon namespace
@ -1381,10 +1395,9 @@ bool SROA::performPromotion(Function &F) {
DT = &getAnalysis<DominatorTree>(); DT = &getAnalysis<DominatorTree>();
BasicBlock &BB = F.getEntryBlock(); // Get the entry node for the function BasicBlock &BB = F.getEntryBlock(); // Get the entry node for the function
DIBuilder DIB(*F.getParent());
bool Changed = false; bool Changed = false;
SmallVector<Instruction*, 64> Insts; SmallVector<Instruction*, 64> Insts;
DIBuilder *DIB = 0;
while (1) { while (1) {
Allocas.clear(); Allocas.clear();
@ -1408,11 +1421,7 @@ bool SROA::performPromotion(Function &F) {
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end();
UI != E; ++UI) UI != E; ++UI)
Insts.push_back(cast<Instruction>(*UI)); Insts.push_back(cast<Instruction>(*UI));
AllocaPromoter(Insts, SSA, &DIB).run(AI, Insts);
DbgDeclareInst *DDI = FindAllocaDbgDeclare(AI);
if (DDI && !DIB)
DIB = new DIBuilder(*AI->getParent()->getParent()->getParent());
AllocaPromoter(Insts, SSA, DDI, DIB).run(AI, Insts);
Insts.clear(); Insts.clear();
} }
} }
@ -1420,10 +1429,6 @@ bool SROA::performPromotion(Function &F) {
Changed = true; Changed = true;
} }
// FIXME: Is there a better way to handle the lazy initialization of DIB
// so that there doesn't need to be an explicit delete?
delete DIB;
return Changed; return Changed;
} }

View File

@ -16,7 +16,6 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/DIBuilder.h"
#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Support/AlignOf.h" #include "llvm/Support/AlignOf.h"
#include "llvm/Support/Allocator.h" #include "llvm/Support/Allocator.h"
@ -358,8 +357,7 @@ Value *SSAUpdater::GetValueAtEndOfBlockInternal(BasicBlock *BB) {
LoadAndStorePromoter:: LoadAndStorePromoter::
LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts, LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts,
SSAUpdater &S, DbgDeclareInst *DD, DIBuilder *DB, SSAUpdater &S, StringRef BaseName) : SSA(S) {
StringRef BaseName) : SSA(S), DDI(DD), DIB(DB) {
if (Insts.empty()) return; if (Insts.empty()) return;
Value *SomeVal; Value *SomeVal;
@ -407,8 +405,7 @@ run(const SmallVectorImpl<Instruction*> &Insts) const {
if (BlockUses.size() == 1) { if (BlockUses.size() == 1) {
// If it is a store, it is a trivial def of the value in the block. // If it is a store, it is a trivial def of the value in the block.
if (StoreInst *SI = dyn_cast<StoreInst>(User)) { if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
if (DDI) updateDebugInfo(SI);
ConvertDebugDeclareToDebugValue(DDI, SI, *DIB);
SSA.AddAvailableValue(BB, SI->getOperand(0)); SSA.AddAvailableValue(BB, SI->getOperand(0));
} else } else
// Otherwise it is a load, queue it to rewrite as a live-in load. // Otherwise it is a load, queue it to rewrite as a live-in load.
@ -462,9 +459,7 @@ run(const SmallVectorImpl<Instruction*> &Insts) const {
if (StoreInst *SI = dyn_cast<StoreInst>(II)) { if (StoreInst *SI = dyn_cast<StoreInst>(II)) {
// If this is a store to an unrelated pointer, ignore it. // If this is a store to an unrelated pointer, ignore it.
if (!isInstInList(SI, Insts)) continue; if (!isInstInList(SI, Insts)) continue;
updateDebugInfo(SI);
if (DDI)
ConvertDebugDeclareToDebugValue(DDI, SI, *DIB);
// Remember that this is the active value in the block. // Remember that this is the active value in the block.
StoredValue = SI->getOperand(0); StoredValue = SI->getOperand(0);
@ -522,7 +517,4 @@ run(const SmallVectorImpl<Instruction*> &Insts) const {
instructionDeleted(User); instructionDeleted(User);
User->eraseFromParent(); User->eraseFromParent();
} }
if (DDI)
DDI->eraseFromParent();
} }