Commit a0c2b7f2 authored by Mythri's avatar Mythri Committed by Commit Bot

[Turbofan] Inline only if the candidate doesn't use all the available budget.

Inline only if there is some additional budget left even after inlining
the current candidate. This allows any small functions exposed by this
function to be inlined. Earlier we used to check for the limit after
inlining the function.

Bug: v8:6682
Change-Id: Ia3931751f212e89ca6d9c8500c6b3a909f12d962
Reviewed-on: https://chromium-review.googlesource.com/608970Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47285}
parent 493a7d64
...@@ -107,6 +107,7 @@ Reduction JSInliningHeuristic::Reduce(Node* node) { ...@@ -107,6 +107,7 @@ Reduction JSInliningHeuristic::Reduce(Node* node) {
// Functions marked with %SetForceInlineFlag are immediately inlined. // Functions marked with %SetForceInlineFlag are immediately inlined.
bool can_inline = false, force_inline = true, small_inline = true; bool can_inline = false, force_inline = true, small_inline = true;
candidate.total_size = 0;
for (int i = 0; i < candidate.num_functions; ++i) { for (int i = 0; i < candidate.num_functions; ++i) {
Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo> shared =
candidate.functions[i].is_null() candidate.functions[i].is_null()
...@@ -118,6 +119,7 @@ Reduction JSInliningHeuristic::Reduce(Node* node) { ...@@ -118,6 +119,7 @@ Reduction JSInliningHeuristic::Reduce(Node* node) {
candidate.can_inline_function[i] = CanInlineFunction(shared); candidate.can_inline_function[i] = CanInlineFunction(shared);
if (candidate.can_inline_function[i]) { if (candidate.can_inline_function[i]) {
can_inline = true; can_inline = true;
candidate.total_size += shared->bytecode_array()->length();
} }
if (!IsSmallInlineFunction(shared)) { if (!IsSmallInlineFunction(shared)) {
small_inline = false; small_inline = false;
...@@ -196,10 +198,20 @@ void JSInliningHeuristic::Finalize() { ...@@ -196,10 +198,20 @@ void JSInliningHeuristic::Finalize() {
// on things that aren't called very often. // on things that aren't called very often.
// TODO(bmeurer): Use std::priority_queue instead of std::set here. // TODO(bmeurer): Use std::priority_queue instead of std::set here.
while (!candidates_.empty()) { while (!candidates_.empty()) {
if (cumulative_count_ > FLAG_max_inlined_bytecode_size_cumulative) return;
auto i = candidates_.begin(); auto i = candidates_.begin();
Candidate candidate = *i; Candidate candidate = *i;
candidates_.erase(i); candidates_.erase(i);
// Make sure we have some extra budget left, so that any small functions
// exposed by this function would be given a chance to inline.
double size_of_candidate =
candidate.total_size * FLAG_reserve_inline_budget_scale_factor;
int total_size = cumulative_count_ + static_cast<int>(size_of_candidate);
if (total_size > FLAG_max_inlined_bytecode_size_cumulative) {
// Try if any smaller functions are available to inline.
continue;
}
// Make sure we don't try to inline dead candidate nodes. // Make sure we don't try to inline dead candidate nodes.
if (!candidate.node->IsDead()) { if (!candidate.node->IsDead()) {
Reduction const reduction = InlineCandidate(candidate, false); Reduction const reduction = InlineCandidate(candidate, false);
......
...@@ -50,6 +50,7 @@ class JSInliningHeuristic final : public AdvancedReducer { ...@@ -50,6 +50,7 @@ class JSInliningHeuristic final : public AdvancedReducer {
int num_functions; int num_functions;
Node* node = nullptr; // The call site at which to inline. Node* node = nullptr; // The call site at which to inline.
CallFrequency frequency; // Relative frequency of this call site. CallFrequency frequency; // Relative frequency of this call site.
int total_size = 0;
}; };
// Comparator for candidates. // Comparator for candidates.
......
...@@ -346,6 +346,8 @@ DEFINE_INT(max_inlined_bytecode_size_absolute, 4000, ...@@ -346,6 +346,8 @@ DEFINE_INT(max_inlined_bytecode_size_absolute, 4000,
"(incl. small functions)") "(incl. small functions)")
DEFINE_INT(max_inlined_bytecode_size_cumulative, 1000, DEFINE_INT(max_inlined_bytecode_size_cumulative, 1000,
"maximum cumulative size of bytecode considered for inlining") "maximum cumulative size of bytecode considered for inlining")
DEFINE_FLOAT(reserve_inline_budget_scale_factor, 1.2,
"maximum cumulative size of bytecode considered for inlining")
DEFINE_INT(max_inlined_bytecode_size_small, 30, DEFINE_INT(max_inlined_bytecode_size_small, 30,
"maximum size of bytecode considered for small function inlining") "maximum size of bytecode considered for small function inlining")
DEFINE_FLOAT(min_inlining_frequency, 0.15, "minimum frequency for inlining") DEFINE_FLOAT(min_inlining_frequency, 0.15, "minimum frequency for inlining")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment