This is an archive of the discontinued LLVM Phabricator instance.

[Inline] Add ability to restrict inlining pass to hinted functions only
AbandonedPublic

Authored by Ilod on May 24 2016, 3:33 PM.

Details

Reviewers
chandlerc
eraman
Summary

This adds an OnlyHint parameter to createFunctionInliningPass functions, and a -inline-restrict-to-hint command line parameter.
These allows to restrict the inlining pass to hinted functions only.

Before this, the only way to achieve something similar was to use the -inline-threshold and -inlinehint-threshold command line arguments, while using a negative enough value for -inline-threshold to avoid any inlining (even thoses reducing the size). Moreover, there was no clear interface for this other than the command line arguments.

Adding it will allow a straightforward implementation for /Ob1 in clang-cl.

Diff Detail

Event Timeline

Ilod updated this revision to Diff 58333.May 24 2016, 3:33 PM
Ilod retitled this revision from to [Opt] Add ability to restrict inlining pass to hinted functions only.
Ilod updated this object.
Ilod added a reviewer: chandlerc.
Ilod added a subscriber: llvm-commits.
Ilod added a comment.Jun 7 2016, 4:43 AM

Pinging about this

Ilod added a reviewer: eraman.Jun 7 2016, 9:57 AM
Ilod updated this revision to Diff 61028.Jun 16 2016, 2:09 PM
Ilod retitled this revision from [Opt] Add ability to restrict inlining pass to hinted functions only to [Inline] Add ability to restrict inlining pass to hinted functions only.

Updated to head revision, and pinging on this.

eraman edited edge metadata.Jun 16 2016, 2:28 PM

I'll defer to Chandler on this patch. I have some minor comments and some questions. Is there a practical use case for this or is this more for debugging purposes? Is there a reason why one would want to prevent inlining of, say, a static function with only one callsite that is not marked inline? If it is for debugging/tuning purposes, as you indicate above, using a large negative value for inline-threshold flag will get the job done.

include/llvm/Transforms/IPO.h
104

Nit: restric -> restrict

test/Transforms/Inline/inline-hint.ll
29

I typically specify the checks next to the actual statements (for example, place the above label check next to bar's definition) and I typically see that in all the test cases. I don't know if that is the enforced style, but it does make the test cases more readable.

Ilod updated this revision to Diff 61040.Jun 16 2016, 3:31 PM
Ilod edited edge metadata.

It's an equivalent of /Ob1 on MSVC. We usually use this option on build where we want only optimizations that do not hinder debugging. I want to use this to add support for /Ob1 in clang-cl mode.
It seems I could push -mllvm -inline-threshold=-1000 args or something like this when I get the /Ob1 argument instead of adding an API control in LLVM. It feels a little hackish to me (mainly because of the "arbitrary negative enough threshold" I would need to hardcode in clang), the inlining pass would need to compute the size even if it could be avoided, but it would work just fine. I would rather have an API access than pushing -mllvm command line parameters from clang, but I can live with it if you think it's better to keep it this way.

Fixed the typo, moved the test checks.

Ilod marked 2 inline comments as done.Jun 16 2016, 3:32 PM
davidxl added inline comments.
lib/Transforms/IPO/InlineSimple.cpp
61

RestrictedToHinted = (OnlyHint || RestrictedInlinetoHinted);

In D20603#460461, @Ilod wrote:

It's an equivalent of /Ob1 on MSVC. We usually use this option on build where we want only optimizations that do not hinder debugging. I want to use this to add support for /Ob1 in clang-cl mode.
It seems I could push -mllvm -inline-threshold=-1000 args or something like this when I get the /Ob1 argument instead of adding an API control in LLVM. It feels a little hackish to me (mainly because of the "arbitrary negative enough threshold" I would need to hardcode in clang), the inlining pass would need to compute the size even if it could be avoided, but it would work just fine. I would rather have an API access than pushing -mllvm command line parameters from clang, but I can live with it if you think it's better to keep it this way.

Fixed the typo, moved the test checks.

Ah! I saw the mention of /Ob 1, but ignored it due to my unfamiliarity with MSVC options. Now the patch makes more sense to me. I also see that you have another patch to add inline hints to implicitly defined functions.

lib/Transforms/IPO/InlineSimple.cpp
61

This is not equivalent. The expected behavior when --inline-restrict-to-hint=false is to disable this even when the OnlyHint param is true. This is documented above.

davidxl added inline comments.Jun 16 2016, 4:45 PM
lib/Transforms/IPO/InlineSimple.cpp
61

maybe making the option an enum one to make it clearer?

rnk added a subscriber: rnk.

As mentioned in D20647, I think we can handle this entirely in the frontend.

Ilod abandoned this revision.Jun 22 2016, 8:16 AM