| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/js-inlining-heuristic.h" | 5 #include "src/compiler/js-inlining-heuristic.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
| 9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // In the general case we remember the candidate for later. | 91 // In the general case we remember the candidate for later. |
| 92 candidates_.insert({function, node, calls}); | 92 candidates_.insert({function, node, calls}); |
| 93 return NoChange(); | 93 return NoChange(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 void JSInliningHeuristic::Finalize() { | 97 void JSInliningHeuristic::Finalize() { |
| 98 if (candidates_.empty()) return; // Nothing to do without candidates. | 98 if (candidates_.empty()) return; // Nothing to do without candidates. |
| 99 if (FLAG_trace_turbo_inlining) PrintCandidates(); | 99 if (FLAG_trace_turbo_inlining) PrintCandidates(); |
| 100 | 100 |
| 101 while (!candidates_.empty()) { | 101 // We inline at most one candidate in every iteration of the fixpoint. |
| 102 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) break; | 102 // This is to ensure that we don't consume the full inlining budget |
| 103 auto i = candidates_.begin(); | 103 // on things that aren't called very often. |
| 104 Candidate const& candidate = *i; | 104 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) return; |
| 105 inliner_.ReduceJSCall(candidate.node, candidate.function); | 105 auto i = candidates_.begin(); |
| 106 cumulative_count_ += candidate.function->shared()->ast_node_count(); | 106 Candidate const& candidate = *i; |
| 107 candidates_.erase(i); | 107 inliner_.ReduceJSCall(candidate.node, candidate.function); |
| 108 } | 108 cumulative_count_ += candidate.function->shared()->ast_node_count(); |
| 109 candidates_.erase(i); |
| 109 } | 110 } |
| 110 | 111 |
| 111 | 112 |
| 112 bool JSInliningHeuristic::CandidateCompare::operator()( | 113 bool JSInliningHeuristic::CandidateCompare::operator()( |
| 113 const Candidate& left, const Candidate& right) const { | 114 const Candidate& left, const Candidate& right) const { |
| 114 return left.node != right.node && left.calls >= right.calls; | 115 return left.node != right.node && left.calls >= right.calls; |
| 115 } | 116 } |
| 116 | 117 |
| 117 | 118 |
| 118 void JSInliningHeuristic::PrintCandidates() { | 119 void JSInliningHeuristic::PrintCandidates() { |
| 119 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); | 120 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); |
| 120 for (const Candidate& candidate : candidates_) { | 121 for (const Candidate& candidate : candidates_) { |
| 121 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n", | 122 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n", |
| 122 candidate.node->id(), candidate.calls, | 123 candidate.node->id(), candidate.calls, |
| 123 candidate.function->shared()->SourceSize(), | 124 candidate.function->shared()->SourceSize(), |
| 124 candidate.function->shared()->ast_node_count(), | 125 candidate.function->shared()->ast_node_count(), |
| 125 candidate.function->shared()->DebugName()->ToCString().get()); | 126 candidate.function->shared()->DebugName()->ToCString().get()); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 } // namespace compiler | 130 } // namespace compiler |
| 130 } // namespace internal | 131 } // namespace internal |
| 131 } // namespace v8 | 132 } // namespace v8 |
| OLD | NEW |