[PATCH] D24410: Use call target count to derive the call instruction weight
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 10:44:20 PDT 2016
danielcdh created this revision.
danielcdh added reviewers: dnovillo, davidxl.
danielcdh added a subscriber: llvm-commits.
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.
https://reviews.llvm.org/D24410
Files:
include/llvm/ProfileData/SampleProf.h
lib/Transforms/IPO/SampleProfile.cpp
test/Transforms/SampleProfile/Inputs/inline-coverage.prof
Index: test/Transforms/SampleProfile/Inputs/inline-coverage.prof
===================================================================
--- test/Transforms/SampleProfile/Inputs/inline-coverage.prof
+++ test/Transforms/SampleProfile/Inputs/inline-coverage.prof
@@ -4,4 +4,4 @@
4: 0
0: 0
3: _Z3fool:172746
- 1: 31878
+ 1: 31878 rand:31878
Index: lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- lib/Transforms/IPO/SampleProfile.cpp
+++ lib/Transforms/IPO/SampleProfile.cpp
@@ -479,7 +479,8 @@
uint32_t LineOffset = getOffset(Lineno, HeaderLineno);
uint32_t Discriminator = DIL->getDiscriminator();
- ErrorOr<uint64_t> R = FS->findSamplesAt(LineOffset, Discriminator);
+ ErrorOr<uint64_t> R = CI ? FS->findCallSamplesAt(LineOffset, Discriminator):
+ FS->findSamplesAt(LineOffset, Discriminator);
if (R) {
bool FirstMark =
CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.get());
Index: include/llvm/ProfileData/SampleProf.h
===================================================================
--- include/llvm/ProfileData/SampleProf.h
+++ include/llvm/ProfileData/SampleProf.h
@@ -222,6 +222,21 @@
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];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24410.70862.patch
Type: text/x-patch
Size: 2078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160909/f9d18b1e/attachment.bin>
More information about the llvm-commits
mailing list