MustBeExecutedContextPrinter::runOnModule: Use unique_ptr to simplify/clarify ownership

This commit is contained in:
David Blaikie 2020-04-28 11:30:22 -07:00
parent a077fc20b4
commit 454a8a8a59

View File

@ -357,26 +357,23 @@ ModulePass *llvm::createMustBeExecutedContextPrinter() {
bool MustBeExecutedContextPrinter::runOnModule(Module &M) { bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
// We provide non-PM analysis here because the old PM doesn't like to query // We provide non-PM analysis here because the old PM doesn't like to query
// function passes from a module pass. // function passes from a module pass.
SmallVector<PostDominatorTree *, 8> PDTs; SmallVector<std::unique_ptr<PostDominatorTree>, 8> PDTs;
SmallVector<DominatorTree *, 8> DTs; SmallVector<std::unique_ptr<DominatorTree>, 8> DTs;
SmallVector<LoopInfo *, 8> LIs; SmallVector<std::unique_ptr<LoopInfo>, 8> LIs;
GetterTy<LoopInfo> LIGetter = [&](const Function &F) { GetterTy<LoopInfo> LIGetter = [&](const Function &F) {
DominatorTree *DT = new DominatorTree(const_cast<Function &>(F)); DTs.push_back(std::make_unique<DominatorTree>(const_cast<Function &>(F)));
LoopInfo *LI = new LoopInfo(*DT); LIs.push_back(std::make_unique<LoopInfo>(*DTs.back()));
DTs.push_back(DT); return LIs.back().get();
LIs.push_back(LI);
return LI;
}; };
GetterTy<DominatorTree> DTGetter = [&](const Function &F) { GetterTy<DominatorTree> DTGetter = [&](const Function &F) {
DominatorTree *DT = new DominatorTree(const_cast<Function &>(F)); DTs.push_back(std::make_unique<DominatorTree>(const_cast<Function&>(F)));
DTs.push_back(DT); return DTs.back().get();
return DT;
}; };
GetterTy<PostDominatorTree> PDTGetter = [&](const Function &F) { GetterTy<PostDominatorTree> PDTGetter = [&](const Function &F) {
PostDominatorTree *PDT = new PostDominatorTree(const_cast<Function &>(F)); PDTs.push_back(
PDTs.push_back(PDT); std::make_unique<PostDominatorTree>(const_cast<Function &>(F)));
return PDT; return PDTs.back().get();
}; };
MustBeExecutedContextExplorer Explorer( MustBeExecutedContextExplorer Explorer(
/* ExploreInterBlock */ true, /* ExploreInterBlock */ true,
@ -392,9 +389,6 @@ bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
} }
} }
DeleteContainerPointers(PDTs);
DeleteContainerPointers(LIs);
DeleteContainerPointers(DTs);
return false; return false;
} }