This is an archive of the discontinued LLVM Phabricator instance.

[Inline] Introduce function attribute to control maximum stack size of inlined functions
ClosedPublic

Authored by wolfgangp on Jul 15 2022, 2:15 PM.

Details

Summary

In D128454 a backend option was introduced to control the maximum stack size of inlined functions (-mllvm -inline-max-stacksize=<N>).

It seems advantageous to implement this functionality via a function attribute in order to make it work smoothly for LTO, while retaining the ability to override the value on the command line.

Note that the attribute pertains to the caller and not the callee, i.e. if function foo() has the attribute, it means "don't inline any function with a stacksize larger than the given value".

If this is OK, I'll follow up with a clang patch that sets the attribute based on a command line option.

Diff Detail

Event Timeline

wolfgangp created this revision.Jul 15 2022, 2:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 2:15 PM
wolfgangp requested review of this revision.Jul 15 2022, 2:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 2:15 PM
mtrofin accepted this revision.Aug 8 2022, 10:01 AM
mtrofin added inline comments.
llvm/lib/Analysis/InlineCost.cpp
166

Nit: can you please initialize AttrValue at declaration - just less chances of odd bug chases later.

2729

nit: make inline-max-stacksize a constant so, later, there's less chance of people copying around the free string.

This revision is now accepted and ready to land.Aug 8 2022, 10:01 AM
kazu added inline comments.Aug 8 2022, 10:30 AM
llvm/lib/Analysis/InlineCost.cpp
173–185

Do we need this? It looks like your modification in analyze() is using Optional<int> getStringFnAttrAsInt(Function *F, StringRef AttrKind), not the CallBase &CB variant.

wolfgangp added inline comments.Aug 8 2022, 11:32 AM
llvm/lib/Analysis/InlineCost.cpp
173–185

To me this seemed like the best way to avoid code duplication (of the code that I moved to the Attribute variant).

kazu added inline comments.Aug 8 2022, 12:47 PM
llvm/lib/Analysis/InlineCost.cpp
173–185

Oops. Sorry, I misread your code. I thought you were adding getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind), which is not the case.

This revision was landed with ongoing or failed builds.Aug 12 2022, 11:07 AM
This revision was automatically updated to reflect the committed changes.