This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Change call count output for ICF
ClosedPublic

Authored by maksfb on Feb 25 2023, 9:39 PM.

Details

Summary

ICF optimization runs multiple passes and the order in which functions
are folded could be dependent on the order they are being processed.
This order is indeterministic as functions are intermediately stored in
std::unordered_map<>. Note that this order is mostly stable, but is not
guaranteed to be and can change e.g. after switching to a different C++
library implementation.

Because the processing (and folding) order is indeterministic, the
previous way of calculating merged function call count could produce
different results.

Change the way we calculate the ICF call count to make it independent of
the function folding/processing order.

Mostly NFC as the output binary should remain the same, the change
affects only the console output.

Diff Detail

Event Timeline

maksfb created this revision.Feb 25 2023, 9:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2023, 9:39 PM
maksfb requested review of this revision.Feb 25 2023, 9:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2023, 9:39 PM
yota9 added inline comments.Feb 27 2023, 6:42 AM
bolt/lib/Core/BinaryContext.cpp
1349

Just curious may we just call ChildBF.setFolded(&ParentBF) here? AFAIU it is done only for non-relocation mode since there were no need to mark folded function in rel mode since we're just removing them from the map. If we would still mark function as folded here we may just check isFolded() state in ICF pass.

maksfb added inline comments.Feb 27 2023, 11:28 AM
bolt/lib/Core/BinaryContext.cpp
1349

In relocation mode, ChildBF will be deleted at this point. Are you suggesting to mark ParentBF as folded?

yota9 added inline comments.Feb 27 2023, 11:39 AM
bolt/lib/Core/BinaryContext.cpp
1349

Oh you are right, for some reason I thought it is adress->pointer map.
Maybe we can use another naming then? Maybe like hasFoldedInto or isParentBF IDK. Merged sounds like the function is merged, not something into it)

maksfb updated this revision to Diff 500897.Feb 27 2023, 1:46 PM

Rename isMerged() -> hasFunctionsFoldedInto()

maksfb marked an inline comment as done.Feb 27 2023, 1:46 PM
yota9 accepted this revision.Feb 27 2023, 1:47 PM

LGTM Thank you!

This revision is now accepted and ready to land.Feb 27 2023, 1:47 PM
maksfb marked an inline comment as done.Feb 27 2023, 2:19 PM
This revision was automatically updated to reflect the committed changes.