Clean up the lazy initialization of DIBuilder a bit.

llvm-svn: 131956
This commit is contained in:
Cameron Zwarich 2011-05-24 06:00:08 +00:00
parent 3b1d1217f8
commit 46e1ebf367
4 changed files with 8 additions and 13 deletions

View File

@ -123,10 +123,10 @@ class LoadAndStorePromoter {
protected: protected:
SSAUpdater &SSA; SSAUpdater &SSA;
DbgDeclareInst *DDI; DbgDeclareInst *DDI;
DIBuilder *&DIB; DIBuilder *DIB;
public: public:
LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts, LoadAndStorePromoter(const SmallVectorImpl<Instruction*> &Insts,
SSAUpdater &S, DbgDeclareInst *DDI, DIBuilder *&DIB, SSAUpdater &S, DbgDeclareInst *DDI, DIBuilder *DIB,
StringRef Name = StringRef()); StringRef Name = StringRef());
virtual ~LoadAndStorePromoter() {} virtual ~LoadAndStorePromoter() {}

View File

@ -602,13 +602,12 @@ namespace {
SmallPtrSet<Value*, 4> &PointerMustAliases; SmallPtrSet<Value*, 4> &PointerMustAliases;
SmallVectorImpl<BasicBlock*> &LoopExitBlocks; SmallVectorImpl<BasicBlock*> &LoopExitBlocks;
AliasSetTracker &AST; AliasSetTracker &AST;
DIBuilder *DIB; // Only passed to LoadAndStorePromoter.
public: public:
LoopPromoter(Value *SP, LoopPromoter(Value *SP,
const SmallVectorImpl<Instruction*> &Insts, SSAUpdater &S, const SmallVectorImpl<Instruction*> &Insts, SSAUpdater &S,
SmallPtrSet<Value*, 4> &PMA, SmallPtrSet<Value*, 4> &PMA,
SmallVectorImpl<BasicBlock*> &LEB, AliasSetTracker &ast) SmallVectorImpl<BasicBlock*> &LEB, AliasSetTracker &ast)
: LoadAndStorePromoter(Insts, S, 0, DIB), SomePtr(SP), : LoadAndStorePromoter(Insts, S, 0, 0), SomePtr(SP),
PointerMustAliases(PMA), LoopExitBlocks(LEB), AST(ast) {} PointerMustAliases(PMA), LoopExitBlocks(LEB), AST(ast) {}
virtual bool isInstInList(Instruction *I, virtual bool isInstInList(Instruction *I,

View File

@ -1367,6 +1367,8 @@ bool SROA::performPromotion(Function &F) {
Insts.push_back(cast<Instruction>(*UI)); Insts.push_back(cast<Instruction>(*UI));
DbgDeclareInst *DDI = FindAllocaDbgDeclare(AI); DbgDeclareInst *DDI = FindAllocaDbgDeclare(AI);
if (DDI && !DIB)
DIB = new DIBuilder(*AI->getParent()->getParent()->getParent());
AllocaPromoter(Insts, SSA, DDI, DIB).run(AI, Insts); AllocaPromoter(Insts, SSA, DDI, DIB).run(AI, Insts);
Insts.clear(); Insts.clear();
} }

View File

@ -358,7 +358,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, DbgDeclareInst *DD, DIBuilder *DB,
StringRef BaseName) : SSA(S), DDI(DD), DIB(DB) { StringRef BaseName) : SSA(S), DDI(DD), DIB(DB) {
if (Insts.empty()) return; if (Insts.empty()) return;
@ -407,11 +407,8 @@ 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) { if (DDI)
if (!DIB)
DIB = new DIBuilder(*SI->getParent()->getParent()->getParent());
ConvertDebugDeclareToDebugValue(DDI, SI, *DIB); 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.
@ -466,11 +463,8 @@ run(const SmallVectorImpl<Instruction*> &Insts) const {
// 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;
if (DDI) { if (DDI)
if (!DIB)
DIB = new DIBuilder(*SI->getParent()->getParent()->getParent());
ConvertDebugDeclareToDebugValue(DDI, SI, *DIB); 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);