summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/BlockFrequencyInfo.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-25 18:01:38 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-25 18:01:38 +0000
commit3dbe10503aea12c952045e2f0f27762c70641dea (patch)
tree825437563ee80aa367b521fc56efd1872cc7485d /llvm/lib/Analysis/BlockFrequencyInfo.cpp
parent936aef92387fd46294a4915a3f5dbf2ce93b77f7 (diff)
downloadbcm5719-llvm-3dbe10503aea12c952045e2f0f27762c70641dea.tar.gz
bcm5719-llvm-3dbe10503aea12c952045e2f0f27762c70641dea.zip
blockfreq: Implement Pass::releaseMemory()
Implement Pass::releaseMemory() in BlockFrequencyInfo and MachineBlockFrequencyInfo. Just delete the private implementation when not in use. Switch to a std::unique_ptr to make the logic more clear. <rdar://problem/14292693> llvm-svn: 204741
Diffstat (limited to 'llvm/lib/Analysis/BlockFrequencyInfo.cpp')
-rw-r--r--llvm/lib/Analysis/BlockFrequencyInfo.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index e52a0f8a8ee..63049a56019 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -114,12 +114,9 @@ char BlockFrequencyInfo::ID = 0;
BlockFrequencyInfo::BlockFrequencyInfo() : FunctionPass(ID) {
initializeBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
- BFI = new BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>();
}
-BlockFrequencyInfo::~BlockFrequencyInfo() {
- delete BFI;
-}
+BlockFrequencyInfo::~BlockFrequencyInfo() {}
void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<BranchProbabilityInfo>();
@@ -128,6 +125,8 @@ void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
bool BlockFrequencyInfo::runOnFunction(Function &F) {
BranchProbabilityInfo &BPI = getAnalysis<BranchProbabilityInfo>();
+ if (!BFI)
+ BFI.reset(new ImplType);
BFI->doFunction(&F, &BPI);
#ifndef NDEBUG
if (ViewBlockFreqPropagationDAG != GVDT_None)
@@ -136,12 +135,14 @@ bool BlockFrequencyInfo::runOnFunction(Function &F) {
return false;
}
+void BlockFrequencyInfo::releaseMemory() { BFI.reset(); }
+
void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
if (BFI) BFI->print(O);
}
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
- return BFI->getBlockFreq(BB);
+ return BFI ? BFI->getBlockFreq(BB) : 0;
}
/// Pop up a ghostview window with the current block frequency propagation
@@ -157,20 +158,20 @@ void BlockFrequencyInfo::view() const {
}
const Function *BlockFrequencyInfo::getFunction() const {
- return BFI->Fn;
+ return BFI ? BFI->Fn : nullptr;
}
raw_ostream &BlockFrequencyInfo::
printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const {
- return BFI->printBlockFreq(OS, Freq);
+ return BFI ? BFI->printBlockFreq(OS, Freq) : OS;
}
raw_ostream &
BlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
const BasicBlock *BB) const {
- return BFI->printBlockFreq(OS, BB);
+ return BFI ? BFI->printBlockFreq(OS, BB) : OS;
}
uint64_t BlockFrequencyInfo::getEntryFreq() const {
- return BFI->getEntryFreq();
+ return BFI ? BFI->getEntryFreq() : 0;
}
OpenPOWER on IntegriCloud