This is an archive of the discontinued LLVM Phabricator instance.

[InstrProf] Add the skipprofile attribute
ClosedPublic

Authored by ellis on Jul 29 2022, 4:39 PM.

Details

Summary

As discussed in [0], this diff adds the skipprofile attribute to
prevent the function from being profiled while allowing profiled
functions to be inlined into it. The noprofile attribute remains
unchanged.

The noprofile attribute is used for functions where it is
dangerous to add instrumentation to while the skipprofile attribute is
used to reduce code size or performance overhead.

[0] https://discourse.llvm.org/t/why-does-the-noprofile-attribute-restrict-inlining/64108

Diff Detail

Event Timeline

ellis created this revision.Jul 29 2022, 4:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2022, 4:39 PM
ellis edited the summary of this revision. (Show Details)Jul 29 2022, 4:45 PM
ellis added reviewers: phosek, davidxl.
ellis published this revision for review.Jul 29 2022, 4:53 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 29 2022, 4:53 PM

Do you expect the difference between noprofile and omitprofile to be confusing to users? I can certainly see how users could be confused by what the difference is between noprofile and omitprofile ...

Since what you want to communicate is "never profile"(which noprofile can probably communicate as is) and "never profile this, but allow inlining of profiled functions" (which I'm not sure omitprofile communicates), then maybe there is a more obvious way we could communicate that? Maybe neverprofile and nodirectprofile are more descriptive names? I don't love the idea of changing an existing attribute name, but we can transparently upgrade existing uses for backwards compatibility if we have to. What do you think?

I also think this will need to need to be supported in LLVM's passes, right? So the instrumentation passes in PGOInstrumentation.cpp (I can't remember if 'InstrProfiling.cpp` will need this too), and probably the Inlining passes too, right? I assume those will be follow up patches, but I don't see them in the current stack. Is that an accurate assumption?

BTW I like the direction of these patches, I think adding the ability to differentiate these cases will add a lot of value to the profiling runtimes + coverage. :)

ellis added a comment.Aug 1 2022, 10:10 AM

Do you expect the difference between noprofile and omitprofile to be confusing to users? I can certainly see how users could be confused by what the difference is between noprofile and omitprofile ...

Since what you want to communicate is "never profile"(which noprofile can probably communicate as is) and "never profile this, but allow inlining of profiled functions" (which I'm not sure omitprofile communicates), then maybe there is a more obvious way we could communicate that? Maybe neverprofile and nodirectprofile are more descriptive names? I don't love the idea of changing an existing attribute name, but we can transparently upgrade existing uses for backwards compatibility if we have to. What do you think?

I agree that omitprofile probably doesn't communicate the correct meaning very well. I like nodirectprofile because it hopefully implies that indirect profiles are allowed. I'm wondering if anyone else has suggestions.

Is there any precedent for renaming function attributes? My assumption was that users would add the noprofile attribute to source mostly for correctness concerns and noprofile is easy to remember and already in use, so I'd rather not change it.

I also think this will need to need to be supported in LLVM's passes, right? So the instrumentation passes in PGOInstrumentation.cpp (I can't remember if 'InstrProfiling.cpp` will need this too), and probably the Inlining passes too, right? I assume those will be follow up patches, but I don't see them in the current stack. Is that an accurate assumption?

I actually do have a change in PGOInstrumentation.cpp that skips profiling functions with this new attribute. As far as I know, this stack has all the necessary code changes.

BTW I like the direction of these patches, I think adding the ability to differentiate these cases will add a lot of value to the profiling runtimes + coverage. :)

Thanks for the suggestion and feedback!

I agree that omitprofile probably doesn't communicate the correct meaning very well. I like nodirectprofile because it hopefully implies that indirect profiles are allowed. I'm wondering if anyone else has suggestions.

Is there any precedent for renaming function attributes? My assumption was that users would add the noprofile attribute to source mostly for correctness concerns and noprofile is easy to remember and already in use, so I'd rather not change it.

I agree with you that it's probably best to avoid changing the spelling of noprofile, but since you're making a change in the area, we may as well discuss if 1) that is still the best name, and 2) if we want to keep it.

I don't know if we've ever changed the spelling of a FnAttribute before. IIRC we've dropped them, and changed their format e.g., from being a boolean to taking a value or an enum. At least that's my memory, which seems to correspond to the autoupgrade stuff in BitcodeReader. But I think the project's stance on this(like most things) is that "if there's a good reason, then we should do it." At least if we can maintain our stated compatibility guarantees. This is a place where I think we should get additional feedback before proceeding though.

It might be worth asking about this on discourse. Even if we don't want to make such a change in these patches, it may be good for the project to have a policy (or at least guidelines) about changing attributes.

I actually do have a change in PGOInstrumentation.cpp that skips profiling functions with this new attribute. As far as I know, this stack has all the necessary code changes.

I can't believe I missed that. I looked three times before I commented, and blew right passed it every time. That's what happens when I look at code late on a Friday...

ellis updated this revision to Diff 449463.Aug 2 2022, 3:40 PM

Rename omitprofile => skipprofile since this seems slightly better to me. Of course I'm still open to more suggestions.

Also, fix the profile-function-groups.c test.

ellis retitled this revision from [InstrProf] Add the omitprofile attribute to [InstrProf] Add the skipprofile attribute.Aug 2 2022, 3:41 PM
ellis edited the summary of this revision. (Show Details)
phosek accepted this revision.Aug 3 2022, 12:50 AM

LGTM

This revision is now accepted and ready to land.Aug 3 2022, 12:50 AM
ellis updated this revision to Diff 449995.Aug 4 2022, 8:37 AM

Rebase and update docs

This revision was landed with ongoing or failed builds.Aug 4 2022, 8:45 AM
This revision was automatically updated to reflect the committed changes.