r223166 - InstrProf: Remove some pointless indirection (NFC)

Justin Bogner mail at justinbogner.com
Tue Dec 2 14:38:52 PST 2014


Author: bogner
Date: Tue Dec  2 16:38:52 2014
New Revision: 223166

URL: http://llvm.org/viewvc/llvm-project?rev=223166&view=rev
Log:
InstrProf: Remove some pointless indirection (NFC)

It doesn't make much sense to have std::unique_ptrs of std::string and
std::vector. Avoid some useless indirection by using these types
directly.

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=223166&r1=223165&r2=223166&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Tue Dec  2 16:38:52 2014
@@ -36,7 +36,7 @@ void CodeGenPGO::setFuncName(StringRef N
     RawFuncName = RawFuncName.substr(1);
 
   if (!llvm::GlobalValue::isLocalLinkage(Linkage)) {
-    PrefixedFuncName.reset(new std::string(RawFuncName));
+    PrefixedFuncName = RawFuncName;
     return;
   }
 
@@ -44,11 +44,11 @@ void CodeGenPGO::setFuncName(StringRef N
   // 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.reset(new std::string(CGM.getCodeGenOpts().MainFileName));
-  if (PrefixedFuncName->empty())
-    PrefixedFuncName->assign("<unknown>");
-  PrefixedFuncName->append(":");
-  PrefixedFuncName->append(RawFuncName);
+  PrefixedFuncName = CGM.getCodeGenOpts().MainFileName;
+  if (PrefixedFuncName.empty())
+    PrefixedFuncName.assign("<unknown>");
+  PrefixedFuncName.append(":");
+  PrefixedFuncName.append(RawFuncName);
 }
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
@@ -991,9 +991,9 @@ void CodeGenPGO::emitCounterIncrement(CG
 void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
                                   bool IsInMainFile) {
   CGM.getPGOStats().addVisited(IsInMainFile);
-  RegionCounts.reset(new std::vector<uint64_t>);
+  RegionCounts.clear();
   if (std::error_code EC = PGOReader->getFunctionCounts(
-          getFuncName(), FunctionHash, *RegionCounts)) {
+          getFuncName(), FunctionHash, RegionCounts)) {
     if (EC == llvm::instrprof_error::unknown_function)
       CGM.getPGOStats().addMissing(IsInMainFile);
     else if (EC == llvm::instrprof_error::hash_mismatch)
@@ -1001,14 +1001,14 @@ void CodeGenPGO::loadRegionCounts(llvm::
     else if (EC == llvm::instrprof_error::malformed)
       // TODO: Consider a more specific warning for this case.
       CGM.getPGOStats().addMismatched(IsInMainFile);
-    RegionCounts.reset();
+    RegionCounts.clear();
   }
 }
 
 void CodeGenPGO::destroyRegionCounters() {
   RegionCounterMap.reset();
   StmtCountMap.reset();
-  RegionCounts.reset();
+  RegionCounts.clear();
   RegionCounters = nullptr;
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.h?rev=223166&r1=223165&r2=223166&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.h Tue Dec  2 16:38:52 2014
@@ -31,7 +31,7 @@ class RegionCounter;
 class CodeGenPGO {
 private:
   CodeGenModule &CGM;
-  std::unique_ptr<std::string> PrefixedFuncName;
+  std::string PrefixedFuncName;
   StringRef RawFuncName;
   llvm::GlobalValue::LinkageTypes VarLinkage;
 
@@ -40,7 +40,7 @@ private:
   llvm::GlobalVariable *RegionCounters;
   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;
+  std::vector<uint64_t> RegionCounts;
   uint64_t CurrentRegionCount;
   std::string CoverageMapping;
   /// \brief A flag that is set to true when this function doesn't need
@@ -56,11 +56,11 @@ public:
   /// 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
   /// discarded.
-  bool haveRegionCounts() const { return RegionCounts != nullptr; }
+  bool haveRegionCounts() const { return !RegionCounts.empty(); }
 
   /// Get the string used to identify this function in the profile data.
   /// For functions with local linkage, this includes the main file name.
-  StringRef getFuncName() const { return StringRef(*PrefixedFuncName); }
+  StringRef getFuncName() const { return StringRef(PrefixedFuncName); }
   std::string getFuncVarName(StringRef VarName) const {
     return ("__llvm_profile_" + VarName + "_" + RawFuncName).str();
   }
@@ -151,7 +151,7 @@ private:
   uint64_t getRegionCount(unsigned Counter) {
     if (!haveRegionCounts())
       return 0;
-    return (*RegionCounts)[Counter];
+    return RegionCounts[Counter];
   }
 
   friend class RegionCounter;





More information about the cfe-commits mailing list