diff options
author | 2022-10-31 11:27:24 +0000 | |
---|---|---|
committer | 2022-11-02 08:06:51 +0000 | |
commit | a669df3cb61b88c9dadd161962a9b4ecb7ce8a03 (patch) | |
tree | f3c8069a3b07f267ef29bb81eb9c82a2b1c6de3c /compiler/optimizing/inliner.cc | |
parent | 8f8a8a45835c4306a446a9bbb6cfb0e833924b0b (diff) |
Don't inline methods whose basic blocks end with a throw
If the basic block will end up throwing, it is commonly not in the
critical path. If we throw, we incur in a performance cost anyway
so we can skip inlining those methods. Additionally, methods
before a throw are sometimes construct information which is
something we are not interested in inlining.
Note that this CL doesn't stop inlining for methods that eventually
always end with a throw. See the 2243- test for an example
(testEndsWithThrowButNotDirectly). We could perform a more detailed
analysis but that analysis will increase compile time so it is left
as a further optimization if needed.
Locally in a Pixel 5 with AOSP, code size improved:
* AGSA: 15.3 MB (~4.6%)
* System Server: 1.9 MB (~3.74%)
* SysemUIGoogle: 0.88MB (~3.05%)
Bug: 252884414
Bug: 256052088
Bug: 255984757
Bug: 227283224
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Change-Id: Id0b7894c0d63591e3b354520a47252bf8b91f44f
Diffstat (limited to 'compiler/optimizing/inliner.cc')
-rw-r--r-- | compiler/optimizing/inliner.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 0dc4256ed7..fe398b045d 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -1469,9 +1469,9 @@ bool HInliner::IsInliningSupported(const HInvoke* invoke_instruction, return true; } -// Returns whether our resource limits allow inlining this method. -bool HInliner::IsInliningBudgetAvailable(ArtMethod* method, - const CodeItemDataAccessor& accessor) const { +bool HInliner::IsInliningEncouraged(const HInvoke* invoke_instruction, + ArtMethod* method, + const CodeItemDataAccessor& accessor) const { if (CountRecursiveCallsOf(method) > kMaximumNumberOfRecursiveCalls) { LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedRecursiveBudget) << "Method " @@ -1491,6 +1491,13 @@ bool HInliner::IsInliningBudgetAvailable(ArtMethod* method, return false; } + if (invoke_instruction->GetBlock()->GetLastInstruction()->IsThrow()) { + LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedEndsWithThrow) + << "Method " << method->PrettyMethod() + << " is not inlined because its block ends with a throw"; + return false; + } + return true; } @@ -1557,7 +1564,7 @@ bool HInliner::TryBuildAndInline(HInvoke* invoke_instruction, return false; } - if (!IsInliningBudgetAvailable(method, accessor)) { + if (!IsInliningEncouraged(invoke_instruction, method, accessor)) { return false; } |