This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] ProfileReader cleanup - preparation for MD5 refactoring - 3
ClosedPublic

Authored by huangjd on Apr 24 2023, 11:06 PM.

Details

Summary

Cleanup profile reader classes to prepare for complex refactoring as propsed in D147740, continuing D148872
This is patch 3/n. This patch changes the behavior of function offset table.

Previously when reading ExtBinary profile, the funcOffsetTable (map) is always populated, and in addition if the profile is CS, the orderedFuncOffsets (list) is also populated. However when reading the function samples, only one of the container is being used, never both, so it's a huge waste of time to populate both. Added logic to select which one to use, and completely skip reading function offset table if we are in tool mode (all function samples are to be read sequentially regardless)

Diff Detail

Event Timeline

huangjd created this revision.Apr 24 2023, 11:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 11:06 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
huangjd requested review of this revision.Apr 24 2023, 11:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 11:06 PM
davidxl added inline comments.Apr 24 2023, 11:32 PM
llvm/include/llvm/ProfileData/SampleProfReader.h
685

does it need to check the section flag?

780–781

Is this a dead field?

huangjd updated this revision to Diff 516825.Apr 25 2023, 9:27 AM

Added check for orderedFuncOffsets for CS profile back

huangjd marked an inline comment as done.Apr 25 2023, 12:18 PM
huangjd added inline comments.
llvm/include/llvm/ProfileData/SampleProfReader.h
685

I added back the section flag to check if CS profile has ordered function offset table.

780–781

Updated.

huangjd updated this revision to Diff 516982.Apr 25 2023, 4:40 PM
huangjd marked an inline comment as done.

Combined similar code

huangjd updated this revision to Diff 517335.Apr 26 2023, 2:50 PM

Fixed unused variable for release build

hoy added inline comments.Apr 27 2023, 5:53 PM
llvm/include/llvm/ProfileData/SampleProfReader.h
685

Does the function offset table for a remapper profile always come in sorted?

wenlei added inline comments.Apr 27 2023, 8:55 PM
llvm/include/llvm/ProfileData/SampleProfReader.h
672

all prefixes of the matched function can be loaded,

prefix is caller, but it's meant to read in all callees of matches functions.

685

This function now controls whether list or map is used, which is orthogonal to whether it's ordered (still controlled by section flag). So useOrderedFuncOffsets() is more like useFuncOffsetList() (as opposed to map).

useOrderedFuncOffsets and OrderedFuncOffsets need to be renamed to remove "Ordered" because with this change there's no guarantee it's actually ordered.

686

For readability, i'd suggest expand the logic with inline comments for each category. The big chunk of comment above the function is harder to parse and more prone to be out dated. Something like this:

// category and reason
if ....
   return true;

// category and reason
if ...
   return true;

...

// category and reason
return false;
huangjd updated this revision to Diff 519358.May 3 2023, 10:19 PM

Rebase D149124 after compact binary deprecated

huangjd added inline comments.May 3 2023, 10:21 PM
llvm/include/llvm/ProfileData/SampleProfReader.h
643

This function is misleading and only used once. Data>=End does not imply at EOF in ExtBinary, so removing it.

wenlei added inline comments.May 8 2023, 3:53 PM
llvm/lib/ProfileData/SampleProfReader.cpp
730–740

we are using llvm-profdata tool

nit: as library code/comment, make no assumption of the specific tool as user. just say tools as opposed to compiler.

768

all prefixes of the matched function

You meant "all function profile with matching prefix/caller"?

773–776

Do we need a separate entry for this? Or merge it with the return false in the end?

huangjd updated this revision to Diff 520885.May 9 2023, 6:53 PM
huangjd marked an inline comment as done.

Rephrase some comments

huangjd added inline comments.May 10 2023, 11:34 AM
llvm/lib/ProfileData/SampleProfReader.cpp
773–776

I am keeping the logic in this order so that it is consistent with the control flow in readFuncProfiles because it is very complicated.

davidxl added inline comments.May 10 2023, 1:39 PM
llvm/lib/ProfileData/SampleProfReader.cpp
900

Add a comment here to reference to useFunctionOffsetList method to be in sync, or add assert of useFunctionOffsetList() in each branch below.

wenlei added inline comments.May 10 2023, 2:12 PM
llvm/lib/ProfileData/SampleProfReader.cpp
768

This comment is still inaccurate. The idea is to order the profiles so all profile sharing the same context prefix can be loaded together. i.e. If [A:1 @ B] is loaded, then [A:1 @ B:2 @ C], [A:1 @ B:3 @ D], [A:1 @ B:3 @ D:4 @ E] can all be loaded easily.

the profiles of all its prefix contexts (all callers on the call stack) are loaded

It's about loading callee profiles with matching caller context/prefix, rather than loading caller profiles.

773–776

sounds good.

huangjd updated this revision to Diff 521423.May 11 2023, 1:20 PM
  • Added comments and assert
huangjd updated this revision to Diff 521424.May 11 2023, 1:21 PM
  • Added comments and assert
huangjd updated this revision to Diff 521425.May 11 2023, 1:22 PM

Included wrong diff

wenlei accepted this revision.May 11 2023, 1:23 PM

lgtm, thanks.

This revision is now accepted and ready to land.May 11 2023, 1:23 PM
huangjd marked 4 inline comments as done.May 11 2023, 1:23 PM
davidxl accepted this revision.May 11 2023, 1:24 PM

lgtm

This revision was landed with ongoing or failed builds.May 12 2023, 1:46 PM
This revision was automatically updated to reflect the committed changes.