diff options
author | Justin Bogner <mail@justinbogner.com> | 2014-04-15 21:22:35 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2014-04-15 21:22:35 +0000 |
commit | e2ef2a09ef265fe854f160d127537dc243d1ffc4 (patch) | |
tree | 4b2e76c2775910359017a1e038e77899fb134f08 /clang/lib/CodeGen | |
parent | 3f0c79ce8df08f2cb56f48a3dfe3051305ade54d (diff) | |
download | bcm5719-llvm-e2ef2a09ef265fe854f160d127537dc243d1ffc4.tar.gz bcm5719-llvm-e2ef2a09ef265fe854f160d127537dc243d1ffc4.zip |
CodeGen: Emit warnings for out of date profile data during PGO
This adds a warning that triggers when profile data doesn't match for
the source that's being compiled with -fprofile-instr-use=. This fires
only once per translation unit, as warning on every mismatched
function would be quite noisy.
llvm-svn: 206322
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 14 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenPGO.cpp | 10 |
3 files changed, 25 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6ea60ba1c0d..d4daaa55c79 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -286,6 +286,9 @@ void CodeGenModule::Release() { if (getCodeGenOpts().ProfileInstrGenerate) if (llvm::Function *PGOInit = CodeGenPGO::emitInitialization(*this)) AddGlobalCtor(PGOInit, 0); + if (PGOData && PGOStats.isOutOfDate()) + getDiags().Report(diag::warn_profile_data_out_of_date) + << PGOStats.Visited << PGOStats.Missing << PGOStats.Mismatched; EmitCtorList(GlobalCtors, "llvm.global_ctors"); EmitCtorList(GlobalDtors, "llvm.global_dtors"); EmitGlobalAnnotations(); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 0d13bdcc2fa..f6614dd44bd 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -220,6 +220,15 @@ struct ARCEntrypoints { llvm::Constant *clang_arc_use; }; +/// This class records statistics on instrumentation based profiling. +struct InstrProfStats { + InstrProfStats() : Visited(0), Missing(0), Mismatched(0) {} + bool isOutOfDate() { return Missing || Mismatched; } + uint32_t Visited; + uint32_t Missing; + uint32_t Mismatched; +}; + /// CodeGenModule - This class organizes the cross-function state that is used /// while generating LLVM code. class CodeGenModule : public CodeGenTypeCache { @@ -258,6 +267,7 @@ class CodeGenModule : public CodeGenTypeCache { llvm::MDNode *NoObjCARCExceptionsMetadata; RREntrypoints *RRData; PGOProfileData *PGOData; + InstrProfStats PGOStats; // WeakRefReferences - A set of references that have only been seen via // a weakref so far. This is used to remove the weak of the reference if we @@ -483,6 +493,10 @@ public: return *RRData; } + InstrProfStats &getPGOStats() { + return PGOStats; + } + PGOProfileData *getPGOData() const { return PGOData; } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 55a09e8db52..c451bef57c5 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -908,11 +908,17 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, unsigned Counter) { } void CodeGenPGO::loadRegionCounts(PGOProfileData *PGOData) { + CGM.getPGOStats().Visited++; RegionCounts.reset(new std::vector<uint64_t>); uint64_t Hash; - if (PGOData->getFunctionCounts(getFuncName(), Hash, *RegionCounts) || - Hash != FunctionHash || RegionCounts->size() != NumRegionCounters) + if (PGOData->getFunctionCounts(getFuncName(), Hash, *RegionCounts)) { + CGM.getPGOStats().Missing++; RegionCounts.reset(); + } else if (Hash != FunctionHash || + RegionCounts->size() != NumRegionCounters) { + CGM.getPGOStats().Mismatched++; + RegionCounts.reset(); + } } void CodeGenPGO::destroyRegionCounters() { |