]> granicus.if.org Git - llvm/commitdiff
Use call target count to derive the call instruction weight
authorDehao Chen <dehao@google.com>
Mon, 19 Sep 2016 16:06:37 +0000 (16:06 +0000)
committerDehao Chen <dehao@google.com>
Mon, 19 Sep 2016 16:06:37 +0000 (16:06 +0000)
Summary: The call target count profile is directly derived from LBR branch->target data. This is more reliable than instruction frequency profiles that could be moved across basic block boundaries. This patches uses call target count profile to annotate call instructions.

Reviewers: davidxl, dnovillo

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D24410

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281911 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/SampleProf.h
lib/Transforms/IPO/SampleProfile.cpp
test/Transforms/SampleProfile/Inputs/inline-coverage.prof

index 9fefefa627b1d58c4c5253430ece5ab00170b1b7..a96f83620f8b5a72bbc9256ca0f09fb1ce2d9eee 100644 (file)
@@ -222,6 +222,21 @@ public:
       return ret->second.getSamples();
   }
 
+  /// Return the total number of call target samples collected at a given
+  /// location. Each location is specified by \p LineOffset and
+  /// \p Discriminator. If the location is not found in profile, return error.
+  ErrorOr<uint64_t> findCallSamplesAt(uint32_t LineOffset,
+                                      uint32_t Discriminator) const {
+    const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
+    if (ret == BodySamples.end())
+      return std::error_code();
+    uint64_t T = 0;
+    for (const auto &t_c : ret->second.getCallTargets()) {
+      T += t_c.second;
+    }
+    return T;
+  }
+
   /// Return the function samples at the given callsite location.
   FunctionSamples &functionSamplesAt(const LineLocation &Loc) {
     return CallsiteSamples[Loc];
index 9c4a40c44ca7720b91499ceae2df40b4f07bfa83..500686529ad1b1b553bbfec63eeb8c6eed9ddd6f 100644 (file)
@@ -480,7 +480,9 @@ SampleProfileLoader::getInstWeight(const Instruction &Inst) const {
 
   uint32_t LineOffset = getOffset(Lineno, HeaderLineno);
   uint32_t Discriminator = DIL->getDiscriminator();
-  ErrorOr<uint64_t> R = FS->findSamplesAt(LineOffset, Discriminator);
+  ErrorOr<uint64_t> R = IsCall
+                            ? FS->findCallSamplesAt(LineOffset, Discriminator)
+                            : FS->findSamplesAt(LineOffset, Discriminator);
   if (R) {
     bool FirstMark =
         CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.get());
@@ -1272,10 +1274,10 @@ bool SampleProfileLoader::emitAnnotations(Function &F) {
 
 char SampleProfileLoaderLegacyPass::ID = 0;
 INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass, "sample-profile",
-                "Sample Profile loader", false, false)
+                      "Sample Profile loader", false, false)
 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
 INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass, "sample-profile",
-                "Sample Profile loader", false, false)
+                    "Sample Profile loader", false, false)
 
 bool SampleProfileLoader::doInitialization(Module &M) {
   auto &Ctx = M.getContext();
index 3d792733149ad18db72a9a93c790a3a37c6a0ea2..6f38a1ca8c78536326aaad9ba67b559ec0b86bc4 100644 (file)
@@ -4,4 +4,4 @@ main:501438:0
  4: 0
  0: 0
  3: _Z3fool:172746
-  1: 31878
+  1: 31878 rand:31878