This is an archive of the discontinued LLVM Phabricator instance.

[Inliner] Introduce a backend option to suppress inlining of functions with large stack sizes
AcceptedPublic

Authored by wolfgangp on Jun 16 2022, 10:50 AM.

Details

Summary

See discussion here.

-mllvm -inline-max-stacksize=<NBytes>

The intent is to give the user a way to prevent inlining of functions with large stack sizes. There is no change in behavior if the option is not used. I opted for direct suppression instead of adding to the inlining cost, as that would have added uncertainty.

Works for LTO as well.

If this is acceptable I'll add a clang option in a separate patch.

Any opinions or suggestions are welcome.

Diff Detail

Event Timeline

wolfgangp created this revision.Jun 16 2022, 10:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 10:50 AM
wolfgangp requested review of this revision.Jun 16 2022, 10:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 10:50 AM
mtrofin accepted this revision.Jun 16 2022, 4:27 PM
This revision is now accepted and ready to land.Jun 16 2022, 4:27 PM

I'm not sure if the clang driver normally passes arguments via -mllvm flags or more often via PipelineTuningOptions, which would thread the flag into InlinerPass's constructor

If I have lot of functions where the stack size is 1 byte below the threshold and do a lot of inlining, then the aggregated stack size will explode?

If I have lot of functions where the stack size is 1 byte below the threshold and do a lot of inlining, then the aggregated stack size will explode?

Right, but this is already the behavior today. One could think of a more sophisticated scheme, where the cost of inlining a function gets larger the more the caller's stack size grows, for example.

wenlei added a subscriber: wenlei.Jul 7 2022, 4:25 PM

I think it's also worth making TotalAllocaSizeRecursiveCaller tunable. We need to be more conservative for stack size for recursive inlining, so a general size limit may not be enough there. We ran into trouble with the default 1024 callee stack limit for a deep recursion. Will probably send up a patch to add a llvm flag.

(Random drive-by comment: command line flags like these don't compose well with LTO; they tend to get dropped on the floor unless they get passed to the linker instead of the compiler. Adding metadata to the IR rather than new internal command
line flags avoids this issue entirely). Yes, I've seen https://reviews.llvm.org/D131986.