diff options
author | Rong Xu <xur@google.com> | 2016-02-10 18:24:45 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2016-02-10 18:24:45 +0000 |
commit | 13b01dc8d9ec1fc46e8e75d52bec94e47136d291 (patch) | |
tree | 5a9f47de9317f4088be9cd008e9efce2de8b74c0 /llvm/lib/Transforms/Instrumentation | |
parent | a14364115e1fd07407299bcf633c2fc0344894b8 (diff) | |
download | bcm5719-llvm-13b01dc8d9ec1fc46e8e75d52bec94e47136d291.tar.gz bcm5719-llvm-13b01dc8d9ec1fc46e8e75d52bec94e47136d291.zip |
[PGO] Indirect-call profile annotation in IR level profiling
This patch reads the indirect-call value records in the profile and makes the
annotation in the indirect-call instruction. This is for IR level profile
instrumentation.
Differential Revision: http://reviews.llvm.org/D16935
llvm-svn: 260400
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 89e47774fdf..a8ad7c3fbda 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -25,9 +25,12 @@ // // This file contains two passes: // (1) Pass PGOInstrumentationGen which instruments the IR to generate edge -// count profile, and +// count profile, and generates the instrumentation for indirect call +// profiling. // (2) Pass PGOInstrumentationUse which reads the edge count profile and -// annotates the branch weights. +// annotates the branch weights. It also reads the indirect call value +// profiling records and annotate the indirect call instructions. +// // To get the precise counter information, These two passes need to invoke at // the same compilation point (so they see the same IR). For pass // PGOInstrumentationGen, the real work is done in instrumentOneFunc(). For @@ -84,7 +87,7 @@ STATISTIC(NumOfPGOSplit, "Number of critical edge splits."); STATISTIC(NumOfPGOFunc, "Number of functions having valid profile counts."); STATISTIC(NumOfPGOMismatch, "Number of functions having mismatch profile."); STATISTIC(NumOfPGOMissing, "Number of functions without profile."); -STATISTIC(NumOfPGOICall, "Number of indirect call value instrumentation."); +STATISTIC(NumOfPGOICall, "Number of indirect call value instrumentations."); // Command line option to specify the file to read profile from. This is // mainly used for testing. @@ -95,7 +98,7 @@ static cl::opt<std::string> "mainly for test purpose.")); // Command line options to disable value profiling. The default is false: -// i.e. vaule profiling is enabled by default. This is for debug purpose. +// i.e. value profiling is enabled by default. This is for debug purpose. static cl::opt<bool> DisableValueProfiling("disable-vp", cl::init(false), cl::Hidden, @@ -463,6 +466,9 @@ private: // compilation. uint64_t ProgramMaxCount; + // ProfileRecord for this function. + InstrProfRecord ProfileRecord; + // Find the Instrumented BB and set the value. void setInstrumentedCounts(const std::vector<uint64_t> &CountFromProfile); @@ -502,6 +508,9 @@ public: // Set the branch weights based on the count values. void setBranchWeights(); + + // Annotate the indirect call sites. + void annotateIndirectCallSites(); }; // Visit all the edges and assign the count value for the instrumented @@ -574,7 +583,8 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning)); return false; } - std::vector<uint64_t> &CountFromProfile = Result.get().Counts; + ProfileRecord = std::move(Result.get()); + std::vector<uint64_t> &CountFromProfile = ProfileRecord.Counts; NumOfPGOFunc++; DEBUG(dbgs() << CountFromProfile.size() << " counts\n"); @@ -712,6 +722,36 @@ void PGOUseFunc::setBranchWeights() { dbgs() << "\n";); } } + +// Traverse all the indirect callsites and annotate the instructions. +void PGOUseFunc::annotateIndirectCallSites() { + if (DisableValueProfiling) + return; + + unsigned IndirectCallSiteIndex = 0; + PGOIndirectCallSiteVisitor ICV; + ICV.visit(F); + unsigned NumValueSites= + ProfileRecord.getNumValueSites(IPVK_IndirectCallTarget); + if (NumValueSites != ICV.IndirectCallInsts.size()) { + std::string Msg = + std::string("Inconsistent number of indirect call sites: ") + + F.getName().str(); + auto &Ctx = M->getContext(); + Ctx.diagnose( + DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning)); + return; + } + + for (auto &I : ICV.IndirectCallInsts) { + DEBUG(dbgs() << "Read one indirect call instrumentation: Index=" + << IndirectCallSiteIndex << " out of " + << NumValueSites<< "\n"); + annotateValueSite(*M, *I, ProfileRecord, IPVK_IndirectCallTarget, + IndirectCallSiteIndex); + IndirectCallSiteIndex++; + } +} } // end anonymous namespace // Create a COMDAT variable IR_LEVEL_PROF_VARNAME to make the runtime @@ -751,6 +791,7 @@ static void setPGOCountOnFunc(PGOUseFunc &Func, if (Func.readCounters(PGOReader)) { Func.populateCounters(); Func.setBranchWeights(); + Func.annotateIndirectCallSites(); } } |