[llvm] r204741 - blockfreq: Implement Pass::releaseMemory()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue Mar 25 11:01:38 PDT 2014
Author: dexonsmith
Date: Tue Mar 25 13:01:38 2014
New Revision: 204741
URL: http://llvm.org/viewvc/llvm-project?rev=204741&view=rev
Log:
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>
Modified:
llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h
llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h?rev=204741&r1=204740&r2=204741&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h Tue Mar 25 13:01:38 2014
@@ -27,8 +27,9 @@ class BlockFrequencyImpl;
/// BlockFrequencyInfo pass uses BlockFrequencyImpl implementation to estimate
/// IR basic block frequencies.
class BlockFrequencyInfo : public FunctionPass {
-
- BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo> *BFI;
+ typedef BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>
+ ImplType;
+ std::unique_ptr<ImplType> BFI;
public:
static char ID;
@@ -40,6 +41,7 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
+ void releaseMemory() override;
void print(raw_ostream &O, const Module *M) const override;
const Function *getFunction() const;
void view() const;
Modified: llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h?rev=204741&r1=204740&r2=204741&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h Tue Mar 25 13:01:38 2014
@@ -28,9 +28,9 @@ class BlockFrequencyImpl;
/// MachineBlockFrequencyInfo pass uses BlockFrequencyImpl implementation to estimate
/// machine basic block frequencies.
class MachineBlockFrequencyInfo : public MachineFunctionPass {
-
- BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
- MachineBranchProbabilityInfo> *MBFI;
+ typedef BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
+ MachineBranchProbabilityInfo> ImplType;
+ std::unique_ptr<ImplType> MBFI;
public:
static char ID;
@@ -43,6 +43,8 @@ public:
bool runOnMachineFunction(MachineFunction &F) override;
+ void releaseMemory() override;
+
/// getblockFreq - Return block frequency. Return 0 if we don't have the
/// information. Please note that initial frequency is equal to 1024. It means
/// that we should not rely on the value itself, but only on the comparison to
Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=204741&r1=204740&r2=204741&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Tue Mar 25 13:01:38 2014
@@ -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::getAnalysisUsag
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(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;
}
Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=204741&r1=204740&r2=204741&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Tue Mar 25 13:01:38 2014
@@ -121,13 +121,9 @@ char MachineBlockFrequencyInfo::ID = 0;
MachineBlockFrequencyInfo::
MachineBlockFrequencyInfo() :MachineFunctionPass(ID) {
initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
- MBFI = new BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
- MachineBranchProbabilityInfo>();
}
-MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {
- delete MBFI;
-}
+MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {}
void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineBranchProbabilityInfo>();
@@ -138,6 +134,8 @@ void MachineBlockFrequencyInfo::getAnaly
bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
MachineBranchProbabilityInfo &MBPI =
getAnalysis<MachineBranchProbabilityInfo>();
+ if (!MBFI)
+ MBFI.reset(new ImplType);
MBFI->doFunction(&F, &MBPI);
#ifndef NDEBUG
if (ViewMachineBlockFreqPropagationDAG != GVDT_None) {
@@ -147,6 +145,8 @@ bool MachineBlockFrequencyInfo::runOnMac
return false;
}
+void MachineBlockFrequencyInfo::releaseMemory() { MBFI.reset(); }
+
/// Pop up a ghostview window with the current block frequency propagation
/// rendered using dot.
void MachineBlockFrequencyInfo::view() const {
@@ -162,25 +162,25 @@ void MachineBlockFrequencyInfo::view() c
BlockFrequency MachineBlockFrequencyInfo::
getBlockFreq(const MachineBasicBlock *MBB) const {
- return MBFI->getBlockFreq(MBB);
+ return MBFI ? MBFI->getBlockFreq(MBB) : 0;
}
const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {
- return MBFI->Fn;
+ return MBFI ? MBFI->Fn : nullptr;
}
raw_ostream &
MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
const BlockFrequency Freq) const {
- return MBFI->printBlockFreq(OS, Freq);
+ return MBFI ? MBFI->printBlockFreq(OS, Freq) : OS;
}
raw_ostream &
MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
const MachineBasicBlock *MBB) const {
- return MBFI->printBlockFreq(OS, MBB);
+ return MBFI ? MBFI->printBlockFreq(OS, MBB) : OS;
}
uint64_t MachineBlockFrequencyInfo::getEntryFreq() const {
- return MBFI->getEntryFreq();
+ return MBFI ? MBFI->getEntryFreq() : 0;
}
More information about the llvm-commits
mailing list