This is an archive of the discontinued LLVM Phabricator instance.

[llvm][NFC] Refactor code to use ProfDataUtils
ClosedPublic

Authored by paulkirth on Jun 29 2022, 2:59 PM.

Details

Summary

In this patch we replace common code patterns with the use of utility
functions for dealing with profiling metadata. There should be no change
in functionality, as the existing checks should be preserved in all
cases.

Diff Detail

Event Timeline

paulkirth created this revision.Jun 29 2022, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 2:59 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
paulkirth updated this revision to Diff 447024.Jul 22 2022, 7:28 PM

fixups after rebase in stack

paulkirth updated this revision to Diff 447034.Jul 22 2022, 8:13 PM

Fix wrong literal in expression

paulkirth published this revision for review.Jul 22 2022, 8:40 PM
paulkirth added reviewers: tejohnson, phosek, bogner.
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 8:41 PM
bogner added inline comments.Jul 25 2022, 3:04 PM
llvm/include/llvm/IR/Instruction.h
356

There's an argument for removing this entirely and updating the users to just use extractBranchWeights directly (possibly with a specialization of that function that makes the True/False case convenient). I'm not sure how strongly I feel about it, but all of the branch weight stuff being in one place seems kind of nice. WDYT?

361

Is this used anywhere? We can probably omit it until it is.

paulkirth added inline comments.Jul 26 2022, 12:12 PM
llvm/include/llvm/IR/Instruction.h
356

I think putting all the branch weights utilities in one place is a good idea. Replacing these users was something I was also thinking about, so maybe that's the way we should do it here.

I'll take a look at the users and see if there's a straightforward way to migrate them or if a specialization makes more sense.

361

Yeah, I was hesitant about adding the interface, but wanted to provide an option for switch statements. Since there's currently no users I'll remove the interface. Like you said once someone wants/needs it, It's really easy to add back.

paulkirth added inline comments.Jul 26 2022, 1:53 PM
llvm/lib/IR/Metadata.cpp
1521

This should either be removed, or also check for switch stmts. Well, anything branch weights may be attached to

davidxl added inline comments.
llvm/lib/IR/Metadata.cpp
1509–1510

missing space.

paulkirth updated this revision to Diff 447864.Jul 26 2022, 3:59 PM

Respond to comments

  • Update Interfaces in LLVM for to use extracBranchWeight instead of extractProfMetadata
  • Fix typo
  • remove unused API

I've left the extractProfMetadata interface to Instruction, since I'm unsure if we want to force downstream users to update their code. We could alternatively just leave the interface as is, and back out the places where we've update usage.

I'm waffling on that one, and whether those updates should be a separate change, or just done here. There's value in leaving the public interface to Instruction alone. We've already moved the logic into a central place, so I'm less convinced that the rest of the refactor is the best approach.

Since there are other types of prof meta data other than branch weights, I think we should get rid of the extractProfMetaData interface (in the current form) and replace them with extractBranchWeights (as Justin suggested).

Let's go ahead and remove extractProfMetadata. Even if downstream users are depending on it the update is trivial, and we can always put it back temporarily if it turns out to be a bigger issue somehow.

bogner accepted this revision.Jul 27 2022, 11:44 AM
This revision is now accepted and ready to land.Jul 27 2022, 11:44 AM
paulkirth updated this revision to Diff 448150.Jul 27 2022, 1:43 PM

Remove extractProfMetadata API from Instruction

davidxl accepted this revision.Jul 27 2022, 1:56 PM

lgtm

This revision was landed with ongoing or failed builds.Jul 27 2022, 2:14 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Jul 27 2022, 2:38 PM

Looks like this doesn't build: http://45.33.8.238/linux/82503/step_4.txt

Please take a look, and revert for now if it takes a while to fix.

paulkirth reopened this revision.Jul 27 2022, 2:40 PM

yeah, it looks like we missed something on this. I was already reverting.

This revision is now accepted and ready to land.Jul 27 2022, 2:40 PM

Thanks!

Going forward, please build and run tests locally before committing, or at least wait for the precommit bots to complete.

I had tested locally, but you're right I should have waited for the bots to finish after rebaseing too. I'll be more careful in the future.

paulkirth updated this revision to Diff 448182.Jul 27 2022, 3:15 PM

Fix missing pointer deref

paulkirth updated this revision to Diff 448200.Jul 27 2022, 4:10 PM

Improve documentation strings, since we got a few warnings from buildbot

This revision was landed with ongoing or failed builds.Aug 2 2022, 5:10 PM
This revision was automatically updated to reflect the committed changes.