r204846 - InstrProf: Use unique_ptr

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Mar 26 12:26:05 PDT 2014


Author: dexonsmith
Date: Wed Mar 26 14:26:05 2014
New Revision: 204846

URL: http://llvm.org/viewvc/llvm-project?rev=204846&view=rev
Log:
InstrProf: Use unique_ptr

Modified:
    cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
    cfe/trunk/lib/CodeGen/CodeGenPGO.h

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=204846&r1=204845&r2=204846&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Wed Mar 26 14:26:05 2014
@@ -162,7 +162,7 @@ void CodeGenPGO::setFuncName(llvm::Funct
     RawFuncName = RawFuncName.substr(1);
 
   if (!Fn->hasLocalLinkage()) {
-    PrefixedFuncName = new std::string(RawFuncName);
+    PrefixedFuncName.reset(new std::string(RawFuncName));
     return;
   }
 
@@ -170,7 +170,7 @@ void CodeGenPGO::setFuncName(llvm::Funct
   // Do not include the full path in the file name since there's no guarantee
   // that it will stay the same, e.g., if the files are checked out from
   // version control in different locations.
-  PrefixedFuncName = new std::string(CGM.getCodeGenOpts().MainFileName);
+  PrefixedFuncName.reset(new std::string(CGM.getCodeGenOpts().MainFileName));
   if (PrefixedFuncName->empty())
     PrefixedFuncName->assign("<unknown>");
   PrefixedFuncName->append(":");
@@ -849,7 +849,7 @@ void CodeGenPGO::assignRegionCounters(co
 }
 
 void CodeGenPGO::mapRegionCounters(const Decl *D) {
-  RegionCounterMap = new llvm::DenseMap<const Stmt*, unsigned>();
+  RegionCounterMap.reset(new llvm::DenseMap<const Stmt *, unsigned>);
   MapRegionCounters Walker(*RegionCounterMap);
   if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
     Walker.VisitFunctionDecl(FD);
@@ -863,7 +863,7 @@ void CodeGenPGO::mapRegionCounters(const
 }
 
 void CodeGenPGO::computeRegionCounts(const Decl *D) {
-  StmtCountMap = new llvm::DenseMap<const Stmt*, uint64_t>();
+  StmtCountMap.reset(new llvm::DenseMap<const Stmt *, uint64_t>);
   ComputeRegionCounts Walker(*StmtCountMap, *this);
   if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
     Walker.VisitFunctionDecl(FD);
@@ -917,22 +917,17 @@ void CodeGenPGO::loadRegionCounts(PGOPro
   // counters does not match. This could be tightened down in the future to
   // ignore counts when the input changes in various ways, e.g., by comparing a
   // hash value based on some characteristics of the input.
-  RegionCounts = new std::vector<uint64_t>();
+  RegionCounts.reset(new std::vector<uint64_t>);
   uint64_t Hash;
   if (PGOData->getFunctionCounts(getFuncName(), Hash, *RegionCounts) ||
-      Hash != FunctionHash || RegionCounts->size() != NumRegionCounters) {
-    delete RegionCounts;
-    RegionCounts = 0;
-  }
+      Hash != FunctionHash || RegionCounts->size() != NumRegionCounters)
+    RegionCounts.reset();
 }
 
 void CodeGenPGO::destroyRegionCounters() {
-  if (RegionCounterMap != 0)
-    delete RegionCounterMap;
-  if (StmtCountMap != 0)
-    delete StmtCountMap;
-  if (RegionCounts != 0)
-    delete RegionCounts;
+  RegionCounterMap.reset();
+  StmtCountMap.reset();
+  RegionCounts.reset();
 }
 
 /// \brief Calculate what to divide by to scale weights.

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.h?rev=204846&r1=204845&r2=204846&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.h Wed Mar 26 14:26:05 2014
@@ -53,26 +53,22 @@ public:
 class CodeGenPGO {
 private:
   CodeGenModule &CGM;
-  std::string *PrefixedFuncName;
+  std::unique_ptr<std::string> PrefixedFuncName;
   StringRef RawFuncName;
   llvm::GlobalValue::LinkageTypes VarLinkage;
 
   unsigned NumRegionCounters;
   uint64_t FunctionHash;
   llvm::GlobalVariable *RegionCounters;
-  llvm::DenseMap<const Stmt*, unsigned> *RegionCounterMap;
-  llvm::DenseMap<const Stmt*, uint64_t> *StmtCountMap;
-  std::vector<uint64_t> *RegionCounts;
+  std::unique_ptr<llvm::DenseMap<const Stmt *, unsigned>> RegionCounterMap;
+  std::unique_ptr<llvm::DenseMap<const Stmt *, uint64_t>> StmtCountMap;
+  std::unique_ptr<std::vector<uint64_t>> RegionCounts;
   uint64_t CurrentRegionCount;
 
 public:
   CodeGenPGO(CodeGenModule &CGM)
-      : CGM(CGM), PrefixedFuncName(0), NumRegionCounters(0), FunctionHash(0),
-        RegionCounters(0), RegionCounterMap(0), StmtCountMap(0),
-        RegionCounts(0), CurrentRegionCount(0) {}
-  ~CodeGenPGO() {
-    if (PrefixedFuncName) delete PrefixedFuncName;
-  }
+      : CGM(CGM), NumRegionCounters(0), FunctionHash(0), RegionCounters(0),
+        CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is
   /// false both when we have no data at all and when our data has been





More information about the cfe-commits mailing list