diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp | 81 |
1 files changed, 20 insertions, 61 deletions
diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp index 8dffefc..3877433 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CodeGenPGO.cpp @@ -28,58 +28,20 @@ using namespace CodeGen; void CodeGenPGO::setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage) { - StringRef RawFuncName = Name; - - // Function names may be prefixed with a binary '1' to indicate - // that the backend should not modify the symbols due to any platform - // naming convention. Do not include that '1' in the PGO profile name. - if (RawFuncName[0] == '\1') - RawFuncName = RawFuncName.substr(1); - - FuncName = RawFuncName; - if (llvm::GlobalValue::isLocalLinkage(Linkage)) { - // For local symbols, prepend the main file name to distinguish them. - // 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. - if (CGM.getCodeGenOpts().MainFileName.empty()) - FuncName = FuncName.insert(0, "<unknown>:"); - else - FuncName = FuncName.insert(0, CGM.getCodeGenOpts().MainFileName + ":"); - } + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + FuncName = llvm::getPGOFuncName( + Name, Linkage, CGM.getCodeGenOpts().MainFileName, + PGOReader ? PGOReader->getVersion() : llvm::IndexedInstrProf::Version); // If we're generating a profile, create a variable for the name. if (CGM.getCodeGenOpts().ProfileInstrGenerate) - createFuncNameVar(Linkage); + FuncNameVar = llvm::createPGOFuncNameVar(CGM.getModule(), Linkage, FuncName); } void CodeGenPGO::setFuncName(llvm::Function *Fn) { setFuncName(Fn->getName(), Fn->getLinkage()); } -void CodeGenPGO::createFuncNameVar(llvm::GlobalValue::LinkageTypes Linkage) { - // We generally want to match the function's linkage, but available_externally - // and extern_weak both have the wrong semantics, and anything that doesn't - // need to link across compilation units doesn't need to be visible at all. - if (Linkage == llvm::GlobalValue::ExternalWeakLinkage) - Linkage = llvm::GlobalValue::LinkOnceAnyLinkage; - else if (Linkage == llvm::GlobalValue::AvailableExternallyLinkage) - Linkage = llvm::GlobalValue::LinkOnceODRLinkage; - else if (Linkage == llvm::GlobalValue::InternalLinkage || - Linkage == llvm::GlobalValue::ExternalLinkage) - Linkage = llvm::GlobalValue::PrivateLinkage; - - auto *Value = - llvm::ConstantDataArray::getString(CGM.getLLVMContext(), FuncName, false); - FuncNameVar = - new llvm::GlobalVariable(CGM.getModule(), Value->getType(), true, Linkage, - Value, "__llvm_profile_name_" + FuncName); - - // Hide the symbol so that we correctly get a copy for each executable. - if (!llvm::GlobalValue::isLocalLinkage(FuncNameVar->getLinkage())) - FuncNameVar->setVisibility(llvm::GlobalValue::HiddenVisibility); -} - namespace { /// \brief Stable hasher for PGO region counters. /// @@ -604,7 +566,7 @@ struct ComputeRegionCounts : public ConstStmtVisitor<ComputeRegionCounts> { RecordNextStmtCount = true; } }; -} +} // end anonymous namespace void PGOHash::combine(HashType Type) { // Check that we never combine 0 and only have six bits. @@ -643,27 +605,24 @@ uint64_t PGOHash::finalize() { return endian::read<uint64_t, little, unaligned>(Result); } -void CodeGenPGO::checkGlobalDecl(GlobalDecl GD) { - // Make sure we only emit coverage mapping for one constructor/destructor. - // Clang emits several functions for the constructor and the destructor of - // a class. Every function is instrumented, but we only want to provide - // coverage for one of them. Because of that we only emit the coverage mapping - // for the base constructor/destructor. - if ((isa<CXXConstructorDecl>(GD.getDecl()) && - GD.getCtorType() != Ctor_Base) || - (isa<CXXDestructorDecl>(GD.getDecl()) && - GD.getDtorType() != Dtor_Base)) { - SkipCoverageMapping = true; - } -} - -void CodeGenPGO::assignRegionCounters(const Decl *D, llvm::Function *Fn) { +void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) { + const Decl *D = GD.getDecl(); bool InstrumentRegions = CGM.getCodeGenOpts().ProfileInstrGenerate; llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); if (!InstrumentRegions && !PGOReader) return; if (D->isImplicit()) return; + // Constructors and destructors may be represented by several functions in IR. + // If so, instrument only base variant, others are implemented by delegation + // to the base one, it would be counted twice otherwise. + if (CGM.getTarget().getCXXABI().hasConstructorVariants() && + ((isa<CXXConstructorDecl>(GD.getDecl()) && + GD.getCtorType() != Ctor_Base) || + (isa<CXXDestructorDecl>(GD.getDecl()) && + GD.getDtorType() != Dtor_Base))) { + return; + } CGM.ClearUnusedCoverageMapping(D); setFuncName(Fn); @@ -763,7 +722,7 @@ CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader, return; uint64_t MaxFunctionCount = PGOReader->getMaximumFunctionCount(); - uint64_t FunctionCount = getRegionCount(0); + uint64_t FunctionCount = getRegionCount(nullptr); if (FunctionCount >= (uint64_t)(0.3 * (double)MaxFunctionCount)) // Turn on InlineHint attribute for hot functions. // FIXME: 30% is from preliminary tuning on SPEC, it may not be optimal. @@ -779,7 +738,7 @@ CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader, void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, const Stmt *S) { if (!CGM.getCodeGenOpts().ProfileInstrGenerate || !RegionCounterMap) return; - if (!Builder.GetInsertPoint()) + if (!Builder.GetInsertBlock()) return; unsigned Counter = (*RegionCounterMap)[S]; |