diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-25 18:01:38 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-25 18:01:38 +0000 |
commit | 27e1ca8189e0c566092dd165903d0cf3f89f16a3 (patch) | |
tree | 5df62d3b7e607781055049cefae5a5bc6e7b6bf2 /lib/Analysis | |
parent | 8451e1baa9fa3921c7820d7f279fcebd5581b01d (diff) | |
download | llvm-27e1ca8189e0c566092dd165903d0cf3f89f16a3.tar.gz llvm-27e1ca8189e0c566092dd165903d0cf3f89f16a3.tar.bz2 llvm-27e1ca8189e0c566092dd165903d0cf3f89f16a3.tar.xz |
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>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204741 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/BlockFrequencyInfo.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/Analysis/BlockFrequencyInfo.cpp b/lib/Analysis/BlockFrequencyInfo.cpp index e52a0f8a8e..63049a5601 100644 --- a/lib/Analysis/BlockFrequencyInfo.cpp +++ b/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; } |