RawFuncName = RawFuncName.substr(1);
if (!llvm::GlobalValue::isLocalLinkage(Linkage)) {
- PrefixedFuncName.reset(new std::string(RawFuncName));
+ PrefixedFuncName = RawFuncName;
return;
}
// 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) {
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)
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;
}
class CodeGenPGO {
private:
CodeGenModule &CGM;
- std::unique_ptr<std::string> PrefixedFuncName;
+ std::string PrefixedFuncName;
StringRef RawFuncName;
llvm::GlobalValue::LinkageTypes VarLinkage;
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
/// 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();
}
uint64_t getRegionCount(unsigned Counter) {
if (!haveRegionCounts())
return 0;
- return (*RegionCounts)[Counter];
+ return RegionCounts[Counter];
}
friend class RegionCounter;