This is an archive of the discontinued LLVM Phabricator instance.

[outliner] Use profile data to avoid outlining hot blocks
Changes PlannedPublic

Authored by ellis on May 16 2022, 9:37 PM.

Details

Summary

If profile data is available then we can use it to avoid outlining hot blocks by using the -machine-outliner-use-profile-data backend flag. If profile data is not available then we fall back to the target defaults.

Diff Detail

Event Timeline

ellis created this revision.May 16 2022, 9:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 9:37 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
ellis edited the summary of this revision. (Show Details)May 16 2022, 9:38 PM
ellis added reviewers: paquette, kyulee, wenlei.
ellis published this revision for review.May 16 2022, 9:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 9:42 PM

Can you add test cases for:

  • hot block + optsize minsize
  • cold block + optsize minsize

?

ellis updated this revision to Diff 430124.May 17 2022, 10:47 AM

Add tests for hot/cold functions with optsize minsize.

kyulee added inline comments.May 17 2022, 11:51 AM
llvm/lib/CodeGen/MachineOutliner.cpp
919

I'm not sure I understand this correctly. When UseProfileData is true, do we ignore the other two conditions?

ellis added inline comments.May 17 2022, 3:16 PM
llvm/lib/CodeGen/MachineOutliner.cpp
919

There are basically three reasons why the machine outliner would run.

  1. If RunOnAllFunctions is true
  2. If shouldOutlineFromFunctionByDefault() is true. a. Currently this only happens when targeting arm64 with minsize.
  3. If we pass -machine-outliner-use-profile-data

On second thought I should also check F.hasProfileData() so that we don't conservatively assume unprofiled functions are always hot.

ellis updated this revision to Diff 430198.May 17 2022, 3:35 PM

Check if profile data is available before trying to use and add a test to make sure we enable outlining for minsize functions without profiles.

ellis edited the summary of this revision. (Show Details)May 17 2022, 3:35 PM
ellis updated this revision to Diff 430745.May 19 2022, 11:11 AM

Remove dependency on isBlockRarelyExecuted() that I created in D124490 and replace with ProfileSummaryInfo API to determine if a block is hot.

I'm also wondering if I should use the isHotBlockNthPercentile() function and add an option to specify the percentile. Maybe something like -machine-outliner-cutoff-prof=99900.

wenlei added inline comments.Jun 8 2022, 12:24 PM
llvm/lib/CodeGen/MachineOutliner.cpp
119

I don't think we do this for other passes. Once the plumbing for BFI/MBFI is done for passes to leverage profile info, we just always do that. Using profile should indeed always be better if heuristic is reasonable. Why you need a flag for this case?

If you need some confidence in profile quality, you can check on profile (PSI->hasInstrumentationProfile()) etc.

374

Why do we require BFI instead of MBFI given this is dealing with MIR.

944

Usually we call higher level API like isHotBlock instead of isHotBlockNthPercentile. You can tweak the global percentile by -profile-summary-cutoff-hot.

ellis updated this revision to Diff 435407.Jun 8 2022, 7:11 PM
ellis marked 2 inline comments as done.

Remove -machine-outliner-use-profile-data.

ellis planned changes to this revision.Jun 8 2022, 7:12 PM

I'm planning changes to this for now, see the TODO comments.

llvm/lib/CodeGen/MachineOutliner.cpp
374

I would have liked to use LazyMachineBlockFrequencyInfoPass instead, but it seems that does not work here because this is a ModulePass instead of a MachineFunctionPass.