Open mraleph opened 4 years ago
While discussing this with @mkustermann I have done a bit of digging into why this had such a drastic effect on Flutter Gallery size. Turns out that it disproportionally hits localisation related getters which are generated in large numbers on Flutter Gallery because it supports a lot of different locales. We have 83906 frameless functions and 21303 framefull functions - however out of 83906 frameless functions 80938 originate from localization related generated code.
This means on an average Flutter application this is not likely to have similar impact (unless of course it includes similar amount of localizations done in a similar way).
/cc @alexmarkov
We already had a bug for this in https://github.com/dart-lang/sdk/issues/40195 . Due to more context here I'll close the other issue.
@sstrickl is going to work on this soon.
@mraleph Since you made the PoC, maybe you can upstream them as well?
If a function is a leaf and does not contain any spills it does not need a frame.
POC https://github.com/mraleph/sdk/commit/a70a694193917f8f43b47ebd47102346daad5736 reveals that a lot of functions in Flutter Gallery fit this definition - and dropping frame setup leads to a significant code size improvement (and potentially performance improvement as well).
Store barrier introduces a slight complication into this on ARM/ARM64 because of its outlined slow-path. This slow-path can only call leaf-runtime entry, but nevertheless calling the slow-path clobbers
LR
. We already support generating store barriers in intrinsics - which are also frameless and thus don't haveLR
saved - however this introduces explicit pushing and popping ofLR
which needs to be taken into account when deciding if it is worth to setup a frame (e.g. POC allows at most 1 instruction with a store barrier per frameless function). One dodgy part here is the lack of static guarantee: location summaries capture which instructions perform calls and which don't, with the exception of store barrier call. I suggest that turning POC into a real implementation requires at least adding an assertion that checks that branch-link instruction is only allows to be emitted when IL instruction is marked as clobbering LR.part of go/dart-llvm-assessment
/cc @mkustermann for triage and assignment