This is an archive of the discontinued LLVM Phabricator instance.

[Analysis] Introduce getStaticBonusApplied (NFC)
ClosedPublic

Authored by kazu on Sep 21 2022, 10:11 AM.

Details

Summary

InlineCostCallAnalyzer encourages inlining of the last call to the
static function by subtracting LastCallToStaticBonus from Cost.

This patch introduces getStaticBonusApplied to make available the
amount of LastCallToStaticBonus applied.

The intent is to allow the module inliner to determine whether
inlining a given call site is expected to reduce the caller size with
an expression like:

IC.getCost() + IC.getStaticBonusApplied() < 0

This patch does not add a use of getStaticBonus yet.

Diff Detail

Event Timeline

kazu created this revision.Sep 21 2022, 10:11 AM
kazu requested review of this revision.Sep 21 2022, 10:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 10:11 AM
davidxl added inline comments.Sep 21 2022, 10:39 AM
llvm/include/llvm/Analysis/InlineCost.h
155

should this include other bonuses added too? In that case, the interface name should change accordingly.

This is NFC, right? Is the use of it too complicated - not sure how I feel about code without use.

llvm/include/llvm/Analysis/InlineCost.h
99

is this ever mutated?

kazu added a comment.Sep 21 2022, 10:56 AM

This is NFC, right? Is the use of it too complicated - not sure how I feel about code without use.

I've uploaded another patch (https://reviews.llvm.org/D134376) just to show the use site. You'll find:

bool P1ReducesCallerSize = -1000 < P1.Cost && P1.Cost < 0;

I'd like to be able to say:

bool P1ReducesCallerSize = P1.Cost + P1.LastCallToStaticBonusApplied < 0;
llvm/include/llvm/Analysis/InlineCost.h
99

Good point. const is fine here. I'll add const here. I'll submit a follow-up patch to make Cost and Threshold const also.

155

Maybe not. At the moment, I am not planning to expose other bonuses applied.

kazu updated this revision to Diff 462072.Sep 21 2022, 8:25 PM

Add const.

kazu retitled this revision from [Analysis] Introduce getLastCallToStaticBonusApplied to [Analysis] Introduce getLastCallToStaticBonusApplied (NFC).Sep 21 2022, 8:26 PM
kazu added a comment.Sep 21 2022, 8:29 PM

Please take a look. Thanks!

bool P1ReducesCallerSize = -1000 < P1.Cost && P1.Cost < 0;

where I would like so say something like:

bool P1ReducesCallerSize = P1.Cost + IC.getLastCallToStaticBonusApplied() < 0;
davidxl added inline comments.Sep 23 2022, 9:50 AM
llvm/include/llvm/Analysis/InlineCost.h
155

Consider changing the name to be getStaticBonusApplied () to be more flexible. If in the future, the data needs to be fetched selectively, parameters can be added for that.

kazu updated this revision to Diff 462533.Sep 23 2022, 9:52 AM

Rebased.

Changed the type of LastCallToStaticBonusApplied to "int" from "const
int". I've made this change to be consistent with other fields, which
are also non-const. Note that I've reverted
https://reviews.llvm.org/D134388 to accommodate Yevgeny Rouban's
downstream branch where a field of InlineCost changes.

kazu updated this revision to Diff 462541.Sep 23 2022, 10:08 AM

I've renamed to getLastCallToStaticBonusApplied to
getStaticBonusApplied and made corresponding changes to the underlying
variable name.

kazu marked an inline comment as done.Sep 23 2022, 10:10 AM

Please take a look. Thanks!

Again, for a use case, please see https://reviews.llvm.org/D134376 and look for a hack:

bool P1ReducesCallerSize = -1000 < P1.Cost && P1.Cost < 0;

where I would like so say something like:

bool P1ReducesCallerSize = P1.Cost + IC.getStaticBonusApplied() < 0;
kazu retitled this revision from [Analysis] Introduce getLastCallToStaticBonusApplied (NFC) to [Analysis] Introduce getStaticBonusApplied (NFC).Sep 25 2022, 10:37 PM
kazu edited the summary of this revision. (Show Details)
kazu added a comment.Sep 25 2022, 10:45 PM

I've updated the patch title and description as well. Please take a look. Thanks!

This revision is now accepted and ready to land.Sep 25 2022, 11:03 PM
This revision was landed with ongoing or failed builds.Sep 25 2022, 11:21 PM
This revision was automatically updated to reflect the committed changes.