This is an archive of the discontinued LLVM Phabricator instance.

CodeExtractor : Add ability to preserve profile data.
ClosedPublic

Authored by rriddle on Jul 25 2016, 12:09 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

rriddle updated this revision to Diff 65307.Jul 25 2016, 12:09 AM
rriddle retitled this revision from to CodeExtractor : Add ability to preserve profile data..
rriddle updated this object.
rriddle added reviewers: davide, silvas.
rriddle added a subscriber: llvm-commits.
rriddle updated this revision to Diff 65386.Jul 25 2016, 11:07 AM

Hard exit if an exit frequency is zero.

rriddle updated this revision to Diff 65388.Jul 25 2016, 11:09 AM

Formatting

davidxl added inline comments.Jul 26 2016, 3:19 PM
include/llvm/Analysis/BlockFrequencyInfo.h
67 ↗(On Diff #65388)

nit: perhaps just freqToProfileCount or getProfileCountFromFreq?

include/llvm/Analysis/BlockFrequencyInfoImpl.h
485 ↗(On Diff #65388)

Same here

lib/Transforms/Utils/CodeExtractor.cpp
696 ↗(On Diff #65388)

clang-format? add space

699 ↗(On Diff #65388)

EntryCount --> EntryFreq

756 ↗(On Diff #65388)

nit: OptEntryCount --> EntryCount

758 ↗(On Diff #65388)

When EntryCount does not exist, skip it instead of setting it to 0.

766 ↗(On Diff #65388)

Move this into a helper function

rriddle updated this revision to Diff 65625.Jul 26 2016, 4:15 PM

Updated after Davids comments

silvas edited edge metadata.Jul 26 2016, 10:54 PM

Sorry for the delay on getting to this.

lib/Transforms/IPO/PartialInlining.cpp
149 ↗(On Diff #65625)

Can you add a comment before the false showing the name of the argument? E.g. CodeExtractor(ToExtract, &DT, /*TheArgName*/false, BFI).extractCodeRegion();

lib/Transforms/Utils/CodeExtractor.cpp
690 ↗(On Diff #65625)

Can you explain more how we would get into a situation with a weight of zero and why we need to check it? maybe parts of this should be proper methods on BFI? E.g. below you are directly accessing the impl class so it sounds like something here should maybe be a method on BFI.

also, a nit: can't

742 ↗(On Diff #65625)

Should we change the getBPI method to return non-const? I assume the author made them const for a reason. E.g. BFI might be relying on BPI not changing under it.

808 ↗(On Diff #65625)

nit: no space after the open paren

test/Transforms/CodeExtractor/2016-07-20-MultipleExitBranchProb.ll
30 ↗(On Diff #65625)

Can you do a check with a pattern match and capture a variable, like you do for the other test?

You should be able to do something like test/Transforms/PGOProfile/branch1.ll to check the profile metadata on a particular instruction:

; USE: br i1 %cmp, label %if.then, label %if.end
; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
davidxl added inline comments.Jul 27 2016, 9:54 AM
lib/Transforms/Utils/CodeExtractor.cpp
693 ↗(On Diff #65625)

This check does not look correct. It is possible for the frequency to be zero

805 ↗(On Diff #65625)

The Freq > 0 check can be removed. I don't see how it can be zero (it is not actual count).

808 ↗(On Diff #65625)

The check should be here: if optEntryCount has value (hasValue() returns true, not >0), set it to the newFunction entry. hasValue is false when PGO is not enabled.

rriddle added inline comments.Jul 27 2016, 11:14 AM
lib/Transforms/Utils/CodeExtractor.cpp
693 ↗(On Diff #65625)

Yeah, that was my understanding. Thanks for the sanity check! I need to add the weights without using the current methods given that they do not allow for weights of 0.

rriddle added inline comments.Jul 27 2016, 11:15 AM
lib/Transforms/Utils/CodeExtractor.cpp
808 ↗(On Diff #65625)

Thanks for the clarification, I was unsure if it should just be for the entry count.

lib/Transforms/Utils/CodeExtractor.cpp
693 ↗(On Diff #65625)

Although, can you help clarify on what I should be doing in the case of a 0 frequency? I am unsure on whether the branch weight can be set to a hard 0 or if it needs to be modified to always have a non zero weight?

davidxl added inline comments.Jul 27 2016, 5:02 PM
lib/Transforms/Utils/CodeExtractor.cpp
693 ↗(On Diff #65625)

zero weight is fine -- BFI will always adds 1 to it if it sees it due to some limitation (it is less than ideal -- a better way to is to fix BPI (which will be fixed in the near future).

One the other hand if the total weight is zero, you may want to treat it as invalid.

rriddle added inline comments.Jul 27 2016, 5:17 PM
lib/Transforms/Utils/CodeExtractor.cpp
693 ↗(On Diff #65625)

Awesome. Thanks for the clarification!

rriddle updated this revision to Diff 65873.Jul 27 2016, 10:14 PM
rriddle edited edge metadata.

Updated after Sean and David's comments

davidxl accepted this revision.Jul 28 2016, 12:43 PM
davidxl edited edge metadata.

lgtm with the small issues (in new comments) fixed.

lib/Transforms/Utils/CodeExtractor.cpp
744 ↗(On Diff #65873)

BPI check is not needed.

HasProfileData --> HasBFI because HasProfileData usually means real profile data exists (BFI can be statically computed).

804 ↗(On Diff #65873)

if (OptEntryCount->hasValue())

This revision is now accepted and ready to land.Jul 28 2016, 12:43 PM
rriddle updated this revision to Diff 66085.Jul 29 2016, 12:02 AM
rriddle edited edge metadata.

Updated after David's comments

rriddle updated this revision to Diff 66086.Jul 29 2016, 12:04 AM

Some nits.

lib/Transforms/Utils/CodeExtractor.cpp
701 ↗(On Diff #66086)

Missing '.' at the end of this comment.

742 ↗(On Diff #66086)

should this be "entry frequency" or "entry count" instead of just "entry"?

777 ↗(On Diff #66086)

Add a comment here about what this loop is doing.

800 ↗(On Diff #66086)

The function is newly created, so this should probably say "Calculate and set" instead of "Update".

rriddle updated this revision to Diff 66266.Jul 31 2016, 7:10 PM

Updated to reflect Sean's comments

This revision was automatically updated to reflect the committed changes.

Committed in r277313

silvas reopened this revision.Jul 31 2016, 9:23 PM

I've had to revert this in r277317 due to an LSan failure. Can you take a look?

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/15140/steps/check-llvm%20asan/logs/stdio

This revision is now accepted and ready to land.Jul 31 2016, 9:23 PM
rriddle updated this revision to Diff 66419.Aug 1 2016, 6:54 PM
rriddle removed rL LLVM as the repository for this revision.

Manual computation of BFI and BPI in partial inliner.

This revision was automatically updated to reflect the committed changes.