This is an archive of the discontinued LLVM Phabricator instance.

Expose -mllvm -accurate-sample-profile to clang.
ClosedPublic

Authored by danielcdh on Aug 23 2017, 6:52 PM.

Details

Summary

With accurate sample profile, we can do more aggressive size optimization. For some size-critical application, this can reduce the text size by 20%

Event Timeline

danielcdh created this revision.Aug 23 2017, 6:52 PM
davidxl edited edge metadata.Aug 23 2017, 7:00 PM

Documentation needs to be added to clang/docs/ClangCommandLineReference.rst .

There probably also needs some kind of testing for the option processing: see clang_f_opts.c

danielcdh updated this revision to Diff 112496.Aug 23 2017, 7:52 PM

add document and test

davidxl added inline comments.Aug 23 2017, 8:17 PM
docs/ClangCommandLineReference.rst
176 ↗(On Diff #112496)

If the sample profile is accurate, callsites without profile samples are marked as cold. Otherwise, ...,
This option can be used to enable more aggressive size optimization based on profiles.

include/clang/Driver/Options.td
593

un-sampled callsites --> callsites without profile samples

danielcdh updated this revision to Diff 112574.Aug 24 2017, 9:26 AM
danielcdh marked 2 inline comments as done.

updated the patch to put it into function attribute so that it works with ThinLTO

Looks fine to me, but please wait for Richard's comment.

rsmith added inline comments.Aug 24 2017, 11:57 AM
docs/ClangCommandLineReference.rst
173–180 ↗(On Diff #112574)

This is a generated file; please don't modify it by hand.

include/clang/Driver/Options.td
590

We generally try to group similar options together under a common prefix. Would -fprofile-sample-accurate work here?

592–594

HelpText should be a very brief string that can be included in a one-line description of the flag for --help. Longer text for inclusion in the option reference should be in a DocBrief<{blah blah blah.}>.

Also, it seems to me that this help text doesn't actually say what the option does. Does this request that accurate sample profiles be generated, or specify that an accurate sample profile was provided, or what? Suggestion:

HelpText<"Specifies that the sample profile is accurate">,
DocBrief<{Specifies that the sample profile is accurate. If the sample profile is accurate, callsites without profile samples are marked as cold. [...same as current reference documentation text...]}>
danielcdh updated this revision to Diff 112597.Aug 24 2017, 1:09 PM
danielcdh marked 3 inline comments as done.

update

rsmith accepted this revision.Aug 24 2017, 1:15 PM

Please add a test that the attribute is emitted into IR. Other than that, this looks good to me.

include/clang/Driver/Options.td
645

Consistently use passive voice here: "treat callsites without profile samples" -> "callsites without profile samples are treated"

646

Add a trailing period.

This revision is now accepted and ready to land.Aug 24 2017, 1:15 PM
danielcdh updated this revision to Diff 112601.Aug 24 2017, 1:19 PM

Add an end-to-end test.

rsmith added inline comments.Aug 24 2017, 1:25 PM
test/CodeGen/thinlto-profile-sample-accurate.c
2–4 ↗(On Diff #112601)

test/CodeGen tests should generally not run the optimizer; these tests are intended to check that the correct IR is produced by CodeGen prior to any optimization.

So: we should have a unit test that the IR produced by Clang contains the attribute in the right place (prior to any LLVM passes running), here in test/CodeGen. It seems fine to me to have an end-to-end integration test in addition to that (but not instead of it); we haven't yet established a systematic organization for those tests, but putting it in test/Integration for now will make it easier to find in the future when we work that out.

danielcdh updated this revision to Diff 112604.Aug 24 2017, 1:34 PM
danielcdh marked an inline comment as done.

update

Thanks, looks great.

davidxl accepted this revision.Aug 24 2017, 1:49 PM

lgtm

danielcdh closed this revision.Aug 24 2017, 2:38 PM