[PATCH] D17902: Use unique_ptr in BlockFrequencyAnalysis
Easwaran Raman via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 17:37:33 PST 2016
eraman created this revision.
eraman added a reviewer: dblaikie.
eraman added a subscriber: llvm-commits.
http://reviews.llvm.org/D17902
Files:
include/llvm/Analysis/InlineCost.h
lib/Analysis/InlineCost.cpp
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -1577,31 +1577,25 @@
return BBCount;
}
-BlockFrequencyAnalysis::~BlockFrequencyAnalysis() {
- for (auto &Entry : BFM) {
- delete Entry.second;
- }
-}
+BlockFrequencyAnalysis::BlockFrequencyAnalysis() {}
+BlockFrequencyAnalysis::~BlockFrequencyAnalysis() {}
/// \brief Get BlockFrequencyInfo for a function.
BlockFrequencyInfo *BlockFrequencyAnalysis::getBlockFrequencyInfo(Function *F) {
auto Iter = BFM.find(F);
if (Iter != BFM.end())
- return Iter->second;
+ return Iter->second.get();
// We need to create a BlockFrequencyInfo object for F and store it.
DominatorTree DT;
DT.recalculate(*F);
LoopInfo LI(DT);
BranchProbabilityInfo BPI(*F, LI);
BlockFrequencyInfo *BFI = new BlockFrequencyInfo(*F, BPI, LI);
- BFM[F] = BFI;
+ BFM[F].reset(BFI);
return BFI;
}
/// \brief Invalidate BlockFrequencyInfo for a function.
void BlockFrequencyAnalysis::invalidateBlockFrequencyInfo(Function *F) {
- if (BFM.count(F)) {
- delete BFM[F];
- BFM.erase(F);
- }
+ BFM.erase(F);
}
Index: include/llvm/Analysis/InlineCost.h
===================================================================
--- include/llvm/Analysis/InlineCost.h
+++ include/llvm/Analysis/InlineCost.h
@@ -44,9 +44,12 @@
/// info is computed on demand and cached unless they are invalidated.
class BlockFrequencyAnalysis {
private:
- DenseMap<Function *, BlockFrequencyInfo *> BFM;
+ DenseMap<Function *, std::unique_ptr<BlockFrequencyInfo>> BFM;
public:
+ // Make the constructor and destructor out-of-line to avoid including
+ // BlockFrerquencyInfo.h
+ BlockFrequencyAnalysis();
~BlockFrequencyAnalysis();
/// \brief Returns BlockFrequencyInfo for a function.
BlockFrequencyInfo *getBlockFrequencyInfo(Function *);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17902.49865.patch
Type: text/x-patch
Size: 1927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160305/9e070151/attachment.bin>
More information about the llvm-commits
mailing list