[llvm] r270195 - [ProfileData] Thread unique_ptr through the summary builder to avoid leaks.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 02:18:38 PDT 2016


Author: d0k
Date: Fri May 20 04:18:37 2016
New Revision: 270195

URL: http://llvm.org/viewvc/llvm-project?rev=270195&view=rev
Log:
[ProfileData] Thread unique_ptr through the summary builder to avoid leaks.

Modified:
    llvm/trunk/include/llvm/ProfileData/ProfileCommon.h
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp
    llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
    llvm/trunk/lib/ProfileData/ProfileSummaryBuilder.cpp
    llvm/trunk/lib/ProfileData/SampleProfReader.cpp
    llvm/trunk/lib/ProfileData/SampleProfWriter.cpp

Modified: llvm/trunk/include/llvm/ProfileData/ProfileCommon.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/ProfileCommon.h (original)
+++ llvm/trunk/include/llvm/ProfileData/ProfileCommon.h Fri May 20 04:18:37 2016
@@ -74,7 +74,7 @@ public:
   InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
       : ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {}
   void addRecord(const InstrProfRecord &);
-  ProfileSummary *getSummary();
+  std::unique_ptr<ProfileSummary> getSummary();
 };
 
 class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
@@ -83,7 +83,7 @@ public:
   void addRecord(const sampleprof::FunctionSamples &FS);
   SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
       : ProfileSummaryBuilder(Cutoffs) {}
-  ProfileSummary *getSummary();
+  std::unique_ptr<ProfileSummary> getSummary();
 };
 
 // This is called when a count is seen in the profile.

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Fri May 20 04:18:37 2016
@@ -617,7 +617,7 @@ IndexedInstrProfReader::readSummary(Inde
     InstrProfSummaryBuilder Builder(ProfileSummaryBuilder::DefaultCutoffs);
     // FIXME: This only computes an empty summary. Need to call addRecord for
     // all InstrProfRecords to get the correct summary.
-    this->Summary.reset(Builder.getSummary());
+    this->Summary = Builder.getSummary();
     return Cur;
   }
 }

Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Fri May 20 04:18:37 2016
@@ -259,7 +259,7 @@ void InstrProfWriter::writeImpl(ProfOStr
       IndexedInstrProf::allocSummary(SummarySize);
   // Compute the Summary and copy the data to the data
   // structure to be serialized out (to disk or buffer).
-  ProfileSummary *PS = ISB.getSummary();
+  std::unique_ptr<ProfileSummary> PS = ISB.getSummary();
   setSummary(TheSummary.get(), *PS);
   InfoObj->SummaryBuilder = 0;
 

Modified: llvm/trunk/lib/ProfileData/ProfileSummaryBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/ProfileSummaryBuilder.cpp?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/ProfileSummaryBuilder.cpp (original)
+++ llvm/trunk/lib/ProfileData/ProfileSummaryBuilder.cpp Fri May 20 04:18:37 2016
@@ -86,18 +86,18 @@ void ProfileSummaryBuilder::computeDetai
   }
 }
 
-ProfileSummary *SampleProfileSummaryBuilder::getSummary() {
+std::unique_ptr<ProfileSummary> SampleProfileSummaryBuilder::getSummary() {
   computeDetailedSummary();
-  return new ProfileSummary(ProfileSummary::PSK_Sample, DetailedSummary,
-                            TotalCount, MaxCount, 0, MaxFunctionCount,
-                            NumCounts, NumFunctions);
+  return llvm::make_unique<ProfileSummary>(
+      ProfileSummary::PSK_Sample, DetailedSummary, TotalCount, MaxCount, 0,
+      MaxFunctionCount, NumCounts, NumFunctions);
 }
 
-ProfileSummary *InstrProfSummaryBuilder::getSummary() {
+std::unique_ptr<ProfileSummary> InstrProfSummaryBuilder::getSummary() {
   computeDetailedSummary();
-  return new ProfileSummary(ProfileSummary::PSK_Instr, DetailedSummary,
-                            TotalCount, MaxCount, MaxInternalBlockCount,
-                            MaxFunctionCount, NumCounts, NumFunctions);
+  return llvm::make_unique<ProfileSummary>(
+      ProfileSummary::PSK_Instr, DetailedSummary, TotalCount, MaxCount,
+      MaxInternalBlockCount, MaxFunctionCount, NumCounts, NumFunctions);
 }
 
 void InstrProfSummaryBuilder::addEntryCount(uint64_t Count) {

Modified: llvm/trunk/lib/ProfileData/SampleProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfReader.cpp Fri May 20 04:18:37 2016
@@ -798,5 +798,5 @@ void SampleProfileReader::computeSummary
     const FunctionSamples &Profile = I.second;
     Builder.addRecord(Profile);
   }
-  Summary.reset(Builder.getSummary());
+  Summary = Builder.getSummary();
 }

Modified: llvm/trunk/lib/ProfileData/SampleProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfWriter.cpp?rev=270195&r1=270194&r2=270195&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfWriter.cpp Fri May 20 04:18:37 2016
@@ -260,5 +260,5 @@ void SampleProfileWriter::computeSummary
     const FunctionSamples &Profile = I.second;
     Builder.addRecord(Profile);
   }
-  Summary.reset(Builder.getSummary());
+  Summary = Builder.getSummary();
 }




More information about the llvm-commits mailing list