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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // We inline at most one candidate in every iteration of the fixpoint. | 101 // We inline at most one candidate in every iteration of the fixpoint. |
102 // This is to ensure that we don't consume the full inlining budget | 102 // This is to ensure that we don't consume the full inlining budget |
103 // on things that aren't called very often. | 103 // on things that aren't called very often. |
104 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) return; | 104 // TODO(bmeurer): Use std::priority_queue instead of std::set here. |
105 auto i = candidates_.begin(); | 105 while (!candidates_.empty()) { |
106 Candidate const& candidate = *i; | 106 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) return; |
107 inliner_.ReduceJSCall(candidate.node, candidate.function); | 107 auto i = candidates_.begin(); |
108 cumulative_count_ += candidate.function->shared()->ast_node_count(); | 108 Candidate candidate = *i; |
109 candidates_.erase(i); | 109 candidates_.erase(i); |
| 110 Reduction r = inliner_.ReduceJSCall(candidate.node, candidate.function); |
| 111 if (r.Changed()) { |
| 112 cumulative_count_ += candidate.function->shared()->ast_node_count(); |
| 113 return; |
| 114 } |
| 115 } |
110 } | 116 } |
111 | 117 |
112 | 118 |
113 bool JSInliningHeuristic::CandidateCompare::operator()( | 119 bool JSInliningHeuristic::CandidateCompare::operator()( |
114 const Candidate& left, const Candidate& right) const { | 120 const Candidate& left, const Candidate& right) const { |
115 return left.node != right.node && left.calls >= right.calls; | 121 return left.node != right.node && left.calls >= right.calls; |
116 } | 122 } |
117 | 123 |
118 | 124 |
119 void JSInliningHeuristic::PrintCandidates() { | 125 void JSInliningHeuristic::PrintCandidates() { |
120 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); | 126 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); |
121 for (const Candidate& candidate : candidates_) { | 127 for (const Candidate& candidate : candidates_) { |
122 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n", | 128 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n", |
123 candidate.node->id(), candidate.calls, | 129 candidate.node->id(), candidate.calls, |
124 candidate.function->shared()->SourceSize(), | 130 candidate.function->shared()->SourceSize(), |
125 candidate.function->shared()->ast_node_count(), | 131 candidate.function->shared()->ast_node_count(), |
126 candidate.function->shared()->DebugName()->ToCString().get()); | 132 candidate.function->shared()->DebugName()->ToCString().get()); |
127 } | 133 } |
128 } | 134 } |
129 | 135 |
130 } // namespace compiler | 136 } // namespace compiler |
131 } // namespace internal | 137 } // namespace internal |
132 } // namespace v8 | 138 } // namespace v8 |
OLD | NEW |