This is an archive of the discontinued LLVM Phabricator instance.

[MLGO] Change MBB Profile Dump from using MBB numbers to MBB IDs
ClosedPublic

Authored by aidengrossman on Mar 31 2023, 6:59 PM.

Details

Summary

Currenty, setting the -mbb-profile-dump dumps a CSV file with blocks
inside an individual function identified by their MBB numbers. This
patch changes the MBBs to be identified by their ID which is set at MBB
creation and not changed afterwards, making it inherently stable
throughout the backend. This alleviates concerns with the MBB IDs
changing between the profile dump and what ends up in the final object
file. The MBBs inside the SHT_LLVM_BB_ADDR_MAP sections are also
identified using their MBB ID rather than number, so if we want to match
them up we need to identify the MBBs here by number.

Diff Detail

Event Timeline

aidengrossman created this revision.Mar 31 2023, 6:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2023, 6:59 PM
aidengrossman requested review of this revision.Mar 31 2023, 6:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2023, 6:59 PM
mtrofin accepted this revision.Mar 31 2023, 7:04 PM

lgtm, but wait for @rahmanl to comment, he's more familiar with these aspects.

This revision is now accepted and ready to land.Mar 31 2023, 7:04 PM

@rahmanl Bumping this for when you have a chance to take a look. Thanks!

Sorry for the delay.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
1939

Currently, these IDs are only generated with -basic-block-sections=labels|list, but IIUC -mbb-profile-dump does not require these flags. We can either have these IDs always generated, or add sanity checks to make sure -mbb-profile-dump is always used with -basic-block-sections.

llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll
6

It's interesting that this works. Maybe just use -basic-block-sections=labels to be safe.

aidengrossman marked 2 inline comments as done.

Address reviewer feedback.

All good on the timing. Thanks for the review!

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
1939

We are requiring -basic-block-sections=labels according to the help string, but we aren't checking if both are enabled at the same time. I've added a check (and test) to ensure that the MachineFunction we're going over has BB labels. The check emits an error otherwise.

rahmanl accepted this revision.Apr 13 2023, 10:12 AM
rahmanl added inline comments.
llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll
39

Remove this redundant line.

This revision was landed with ongoing or failed builds.Apr 14 2023, 12:04 AM
This revision was automatically updated to reflect the committed changes.
aidengrossman marked an inline comment as done.