Page MenuHomePhabricator

Update entry count for cold calls
ClosedPublic

Authored by david2050 on Oct 3 2018, 1:47 PM.

Details

Summary

Profile sample files include the number of times each entry or inlined
call site is sampled. This is translated into the entry count metadta
on functions.

When sample data is being read, if a call site that was inlined
in the sample program is considered cold and not inlined, then
the entry count of the out-of-line functions does not reflect
the current compilation.

In this patch, we note call sites where the function was not inlined
and as a last action of the sample profile loading, we update the
called function's entry count to reflect the calls from these
call sites which are not included in the profile file.

Diff Detail

Event Timeline

david2050 created this revision.Oct 3 2018, 1:47 PM
david2050 updated this revision to Diff 168168.Oct 3 2018, 1:54 PM

remove facebook marker

davidxl edited reviewers, added: wmi; removed: davidxl.Oct 3 2018, 2:01 PM
davidxl added a subscriber: davidxl.
davidxl added inline comments.Oct 3 2018, 2:13 PM
lib/Transforms/IPO/SampleProfile.cpp
770

Probably name it differently. They are calls that are inlined in profiled binary but not in optimized binary. 'Coldness' might be just one of the reasons. At least make the comment clearer.

test/Transforms/SampleProfile/inline-cold.ll
24

Add checking of entry profile meta data here.

david2050 updated this revision to Diff 168174.Oct 3 2018, 2:28 PM

address review comments

davidxl added inline comments.Oct 3 2018, 2:55 PM
test/Transforms/SampleProfile/inline-cold.ll
25

it is better to match the expected profile count here using name reference in filecheck.

david2050 updated this revision to Diff 168187.Oct 3 2018, 3:08 PM

refine test

thanks for the suggestions

test/Transforms/SampleProfile/inline-cold.ll
25

Thanks for the suggestion.

wmi added a comment.Oct 12 2018, 4:51 PM

Sorry for the late reply. I didn't notice the thread.

I admit the problem that the patch describes introduces some impreciseness to the profile annotated, but a problem is that the patch only updates the entry counts of outlined functions, but the profiles inside of those outlined functions are not updated. Ideally if the entry count of a outline function is doubled, maybe the callsite count inside of the function also should be doubled too?

I am not saying it is necessary to keep all the profiles consistent, after all it is about cold place. But I like to know whether the patch is trying to solve a theoretical problem or motivated by a real case.

Thanks,
Wei.

lib/Transforms/IPO/SampleProfile.cpp
866–867

Can be merged into one line.

1603–1609

Maybe merged to:
ECount = Callee->getEntryCount()
Callee->setEntryCount(pair.getSecond() + ECount ? ECount.getCount() : 0);

test/Transforms/SampleProfile/Inputs/inline-cold.prof
2–10

Better to make the function total count equal to the sum of the counts inside of the function because such inconsistency can cause trouble sometimes.

test/Transforms/SampleProfile/inline-cold.ll
31–32

%0, %1... should be renamed in testcase.

Thanks for the review.
This was intended to balance the function updateCalleeCount in InlineFunction.cpp which simply decrements the entry count.

wmi added a comment.Oct 13 2018, 9:42 PM

This was intended to balance the function updateCalleeCount in InlineFunction.cpp which simply decrements the entry count.

Thanks. After inlining a function, updateCalleeCount and updateCallProfile are used to update entry count of callee and meta data for call instructions. Here what the patch is doing looks like to update the profile when outlining an inline instance, which is the opposite of inlining, so should we update the meta data for call instructions inside the callee as well?

david2050 updated this revision to Diff 180834.Jan 9 2019, 6:42 AM

refactor and update

Sorry for the delay.
Refactored the code in InlineFunction for reuse and to update weights uniformly.

wmi added inline comments.Jan 14 2019, 12:12 PM
lib/IR/Function.cpp
1403–1404 ↗(On Diff #180834)

It seems to me a little bit weird to have some structure specific for inliner in the interface of llvm IR. It looks more like a transformation utility and better to stay under lib/Transforms/Utils/. We may create a new file for it if there is nowhere else to put.

And maybe make the name more explicit like updateCalleeProfile.

lib/Transforms/IPO/SampleProfile.cpp
310

I don't find where samples is used?

831

Indirect call is skipped in the current patch, do you think it is better to handle it as well? I don't have strong opionion on this since it is cold.

1470

inlineResult.second is never used. What is the intention to change the interface of inlineHotFunctions?

david2050 marked 2 inline comments as done.Jan 14 2019, 12:57 PM
david2050 added inline comments.
lib/IR/Function.cpp
1403–1404 ↗(On Diff #180834)

I will try putting it back into InlineFunction and exporting it as a static method

lib/Transforms/IPO/SampleProfile.cpp
310

part of a subsequent patch, I will remove from here.

david2050 updated this revision to Diff 181656.Jan 14 2019, 3:00 PM

remove some unneeded changes, refactor location of updateProfileData, now updateProfileCallee

wmi added inline comments.Jan 14 2019, 4:28 PM
lib/Transforms/Utils/InlineFunction.cpp
1486–1494 ↗(On Diff #181656)

Maybe use a lambda here to remove the code duplication?

test/Transforms/SampleProfile/entry_counts_cold.ll
67–68 ↗(On Diff #181656)

Add check for the updated profile of the call instruction inside of bar?

david2050 updated this revision to Diff 181685.Jan 14 2019, 5:49 PM

refactor common code, update test

david2050 marked 3 inline comments as done.Jan 14 2019, 5:50 PM
david2050 added inline comments.
lib/Transforms/Utils/InlineFunction.cpp
1486–1494 ↗(On Diff #181656)

I refactored to pull the common out of the iff and trust unswitching :-)

wmi added inline comments.Jan 15 2019, 10:28 AM
include/llvm/DebugInfo/DIContext.h
101–105 ↗(On Diff #181685)

Are the changes in this file belonging to some other patch?

lib/Transforms/IPO/SampleProfile.cpp
306–307

Can we make the comment more precise? I think NotInlinedProfileInfo is an accumulated information from all the callsites to the same function not being inlined but with inline instance in the profile. It is not a local information for each callsite.

767

Can we change the name to be more self-explain or give it a comment? These are not just calls not being inlined, but also with inline instance in the profile.

test/Transforms/SampleProfile/entry_counts_cold.ll
2 ↗(On Diff #181685)

Please briefly describe what the test is up for so people don't have to search the commit history to find out.

26 ↗(On Diff #181685)

bar is not inlined.

david2050 updated this revision to Diff 181871.Jan 15 2019, 1:26 PM
david2050 marked 2 inline comments as done.

address comments

wmi accepted this revision.Jan 23 2019, 2:07 PM

Sorry it takes me some time to test the change on our major benchmarks. The results are neutral.

LGTM.

This revision is now accepted and ready to land.Jan 23 2019, 2:07 PM
This revision was automatically updated to reflect the committed changes.