This is an archive of the discontinued LLVM Phabricator instance.

[BOLT][NFC] Add hash computation for basic blocks
ClosedPublic

Authored by spupyrev on Feb 17 2023, 4:12 PM.

Details

Summary

Extending yaml profile format with block hashes, which are used for stale
profile matching. To avoid duplication of the code, created a new class with a
collection of utilities for computing hashes.

Diff Detail

Event Timeline

spupyrev created this revision.Feb 17 2023, 4:12 PM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
spupyrev requested review of this revision.Feb 17 2023, 4:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 4:12 PM
spupyrev updated this revision to Diff 499497.Feb 22 2023, 7:10 AM

fixed assertion

spupyrev edited the summary of this revision. (Show Details)Feb 22 2023, 7:11 AM
spupyrev updated this revision to Diff 499611.Feb 22 2023, 11:51 AM

Added a test and adjusted logging

wlei added a subscriber: wlei.Feb 27 2023, 3:38 PM
spupyrev updated this revision to Diff 510067.Mar 31 2023, 9:37 AM

Rebasing...

This diff doesn't change existing behavior and used only to facilitate diffs down the stack. Hence, not adding tests here but please let me know if you prefer some.

Amir added a comment.Apr 26 2023, 12:49 PM

Looks good in general with a couple of nits. Testing with a full battery of tests.

bolt/lib/Core/BinaryFunction.cpp
3607–3619
bolt/lib/Profile/YAMLProfileWriter.cpp
123–128
127–129
Amir added a comment.Apr 26 2023, 12:50 PM

Please retitle as "[BOLT][NFC] Add hash computation for basic blocks"

Amir added inline comments.Apr 26 2023, 12:54 PM
bolt/lib/Core/HashUtilities.cpp
128–130

Please use MIB->getShortBranchOpcode interface here

135–139

As a note: I want to switch to using instruction mnemonic instead of opcode value. It shouldn'

Amir added inline comments.Apr 26 2023, 12:55 PM
bolt/lib/Core/HashUtilities.cpp
135–139

It shouldn't affect the matching, but will make hash stable wrt opcode value changes.

Amir added inline comments.Apr 26 2023, 7:58 PM
bolt/include/bolt/Profile/ProfileYAMLMapping.h
129

Does it have to be a required field? This change breaks internal tests utilizing yaml profile which obviously don't have this field. I tried using an Optional instead and everything worked.

LLVM has hash helpers under llvm/include/llvm/ADT/Hashing.h. Can we use them?

spupyrev updated this revision to Diff 517703.Apr 27 2023, 1:49 PM

Addressing comments:

  • block's hash is optional in yaml
  • using MIB->getShortBranchOpcode

I agree that not relying on specific opcodes is a good idea. Maybe that could be a follow-up diff?

Regarding LLVM's Hashing.h, I dropped one method from the diff, as it is already implemented. Anything else you have in mind regarding the helpers?

spupyrev retitled this revision from [BOLT] adding hash computation for basic blocks to [BOLT][NFC] Add hash computation for basic blocks.Apr 27 2023, 1:50 PM
Amir added a comment.Apr 27 2023, 2:56 PM

The current state looks good to me. I think @maksfb is suggesting the use of ADT/Hashing helpers instead of rolling up our own hashing primitives but that could be in a follow-up diff IMHO.

I agree that not relying on specific opcodes is a good idea. Maybe that could be a follow-up diff?

I'll work on that as a follow-up.

Looks good to me. Please address format nits by Amir. Thanks!

Amir accepted this revision.Apr 30 2023, 9:37 PM
This revision is now accepted and ready to land.Apr 30 2023, 9:37 PM
This revision was landed with ongoing or failed builds.May 2 2023, 2:04 PM
This revision was automatically updated to reflect the committed changes.