From b1d3eaf79f02867e1bb8b44abd05023176ef6e2a Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 2 Dec 2014 22:38:52 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223166 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPGO.cpp | 20 ++++++++++---------- lib/CodeGen/CodeGenPGO.h | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 2f1f211b72..107b29c303 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -36,7 +36,7 @@ void CodeGenPGO::setFuncName(StringRef Name, 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 Name, // 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(""); - PrefixedFuncName->append(":"); - PrefixedFuncName->append(RawFuncName); + PrefixedFuncName = CGM.getCodeGenOpts().MainFileName; + if (PrefixedFuncName.empty()) + PrefixedFuncName.assign(""); + PrefixedFuncName.append(":"); + PrefixedFuncName.append(RawFuncName); } void CodeGenPGO::setFuncName(llvm::Function *Fn) { @@ -991,9 +991,9 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, unsigned Counter) { void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader, bool IsInMainFile) { CGM.getPGOStats().addVisited(IsInMainFile); - RegionCounts.reset(new std::vector); + 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::IndexedInstrProfReader *PGOReader, 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; } diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h index fd1418fb3a..3a2deae31d 100644 --- a/lib/CodeGen/CodeGenPGO.h +++ b/lib/CodeGen/CodeGenPGO.h @@ -31,7 +31,7 @@ class RegionCounter; class CodeGenPGO { private: CodeGenModule &CGM; - std::unique_ptr PrefixedFuncName; + std::string PrefixedFuncName; StringRef RawFuncName; llvm::GlobalValue::LinkageTypes VarLinkage; @@ -40,7 +40,7 @@ private: llvm::GlobalVariable *RegionCounters; std::unique_ptr> RegionCounterMap; std::unique_ptr> StmtCountMap; - std::unique_ptr> RegionCounts; + std::vector 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; -- 2.40.0