Skip to content

[NFC][InstrProf]Factor out getCanonicalName to compute the canonical name given a pgo name. #81547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

mingmingl-llvm
Copy link
Contributor

@mingmingl-llvm mingmingl-llvm commented Feb 12, 2024

This is a PR into llvm:main branch as it simplifies addFuncWithName.

@mingmingl-llvm mingmingl-llvm marked this pull request as ready for review February 12, 2024 22:51
Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but I have a question about the comment below

// Returns the canonial name of the given PGOName. In a canonical name, all
// suffixes that begins with "." except ".__uniq." are stripped.
// FIXME: Unify this with `FunctionSamples::getCanonicalFnName`. And both
// should probably preserve `.specialized.<NSpecs>` suffix now that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't clear to me why we would want to preserve .specialized, since presumably those specialized copies are created after PGO annotation / matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you are correct. I initially thought stripping .specialized.<NSpecs> from function names gives in-accurate profile matching (maps names corresponding to different functions to one &F), but the specialized copies doesn't exist at profile annotation. I'm not aware of other places where the profiles for specialized copies (if the specialized copies exist in the instrumented or sampled binary) are handled, but I'll remove the comment.

…s doesn't exist in the IR at profile annotation time
@mingmingl-llvm
Copy link
Contributor Author

I read this PR again and made a change to use SmallVector rather than StringSet.

SmallVector<StringRef, 2> Names;
Names.push_back(PGOFuncName);
StringRef CanonicalFuncName = getCanonicalName(PGOFuncName);
if (CanonicalFuncName != PGOFuncName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are doing this check explicitly here, rather than add to a vector and iterating it, suggest putting the handling currently within the loop body into a lambda and simply calling it twice (with the second call guarded by this if).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

if (CanonicalFuncName == PGOFuncName)
return Error::success();

return mapName(CanonicalFuncName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slight preference for doing this guarded by if != and return Error::success in the default case.

but otherwise lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@mingmingl-llvm mingmingl-llvm merged commit 2422e96 into llvm:main Feb 13, 2024
@mingmingl-llvm mingmingl-llvm deleted the getcanonicalname branch February 13, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants