Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: src/compiler/js-inlining-heuristic.cc

Issue 2330883002: [turbofan] Call frequencies for JSCallFunction and JSCallConstruct. (Closed)
Patch Set: REBASE Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/compilation-info.h" 7 #include "src/compilation-info.h"
8 #include "src/compiler/common-operator.h" 8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/simplified-operator.h" 10 #include "src/compiler/simplified-operator.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 "%d exceeds maximum allowed level %d\n", 116 "%d exceeds maximum allowed level %d\n",
117 node->id(), node->op()->mnemonic(), level, 117 node->id(), node->op()->mnemonic(), level,
118 FLAG_max_inlining_levels); 118 FLAG_max_inlining_levels);
119 return NoChange(); 119 return NoChange();
120 } 120 }
121 } 121 }
122 } 122 }
123 123
124 // Gather feedback on how often this call site has been hit before. 124 // Gather feedback on how often this call site has been hit before.
125 if (node->opcode() == IrOpcode::kJSCallFunction) { 125 if (node->opcode() == IrOpcode::kJSCallFunction) {
126 CallFunctionParameters p = CallFunctionParametersOf(node->op()); 126 CallFunctionParameters const p = CallFunctionParametersOf(node->op());
127 if (p.feedback().IsValid()) { 127 candidate.frequency = p.frequency();
128 CallICNexus nexus(p.feedback().vector(), p.feedback().slot());
129 candidate.calls = nexus.ExtractCallCount();
130 }
131 } else { 128 } else {
132 DCHECK_EQ(IrOpcode::kJSCallConstruct, node->opcode()); 129 DCHECK_EQ(IrOpcode::kJSCallConstruct, node->opcode());
133 CallConstructParameters p = CallConstructParametersOf(node->op()); 130 CallConstructParameters const p = CallConstructParametersOf(node->op());
134 if (p.feedback().IsValid()) { 131 candidate.frequency = p.frequency();
135 int const extra_index =
136 p.feedback().vector()->GetIndex(p.feedback().slot()) + 1;
137 Object* feedback_extra = p.feedback().vector()->get(extra_index);
138 if (feedback_extra->IsSmi()) {
139 candidate.calls = Smi::cast(feedback_extra)->value();
140 }
141 }
142 } 132 }
143 133
144 // Handling of special inlining modes right away: 134 // Handling of special inlining modes right away:
145 // - For restricted inlining: stop all handling at this point. 135 // - For restricted inlining: stop all handling at this point.
146 // - For stressing inlining: immediately handle all functions. 136 // - For stressing inlining: immediately handle all functions.
147 switch (mode_) { 137 switch (mode_) {
148 case kRestrictedInlining: 138 case kRestrictedInlining:
149 return NoChange(); 139 return NoChange();
150 case kStressInlining: 140 case kStressInlining:
151 return InlineCandidate(candidate); 141 return InlineCandidate(candidate);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (reduction.Changed()) { 263 if (reduction.Changed()) {
274 cumulative_count_ += function->shared()->ast_node_count(); 264 cumulative_count_ += function->shared()->ast_node_count();
275 } 265 }
276 } 266 }
277 267
278 return Replace(value); 268 return Replace(value);
279 } 269 }
280 270
281 bool JSInliningHeuristic::CandidateCompare::operator()( 271 bool JSInliningHeuristic::CandidateCompare::operator()(
282 const Candidate& left, const Candidate& right) const { 272 const Candidate& left, const Candidate& right) const {
283 if (left.calls != right.calls) { 273 if (left.frequency > right.frequency) {
284 return left.calls > right.calls; 274 return true;
275 } else if (left.frequency < right.frequency) {
276 return false;
277 } else {
278 return left.node < right.node;
Jarin 2016/09/12 13:10:01 Could we compare on node->id(), so that we do not
Benedikt Meurer 2016/09/13 17:45:07 Done.
285 } 279 }
286 return left.node < right.node;
287 } 280 }
288 281
289 void JSInliningHeuristic::PrintCandidates() { 282 void JSInliningHeuristic::PrintCandidates() {
290 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); 283 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size());
291 for (const Candidate& candidate : candidates_) { 284 for (const Candidate& candidate : candidates_) {
292 PrintF(" #%d:%s, calls:%d\n", candidate.node->id(), 285 PrintF(" #%d:%s, frequency:%g\n", candidate.node->id(),
293 candidate.node->op()->mnemonic(), candidate.calls); 286 candidate.node->op()->mnemonic(), candidate.frequency);
294 for (int i = 0; i < candidate.num_functions; ++i) { 287 for (int i = 0; i < candidate.num_functions; ++i) {
295 Handle<JSFunction> function = candidate.functions[i]; 288 Handle<JSFunction> function = candidate.functions[i];
296 PrintF(" - size[source]:%d, size[ast]:%d, name: %s\n", 289 PrintF(" - size[source]:%d, size[ast]:%d, name: %s\n",
297 function->shared()->SourceSize(), 290 function->shared()->SourceSize(),
298 function->shared()->ast_node_count(), 291 function->shared()->ast_node_count(),
299 function->shared()->DebugName()->ToCString().get()); 292 function->shared()->DebugName()->ToCString().get());
300 } 293 }
301 } 294 }
302 } 295 }
303 296
304 Graph* JSInliningHeuristic::graph() const { return jsgraph()->graph(); } 297 Graph* JSInliningHeuristic::graph() const { return jsgraph()->graph(); }
305 298
306 CommonOperatorBuilder* JSInliningHeuristic::common() const { 299 CommonOperatorBuilder* JSInliningHeuristic::common() const {
307 return jsgraph()->common(); 300 return jsgraph()->common();
308 } 301 }
309 302
310 SimplifiedOperatorBuilder* JSInliningHeuristic::simplified() const { 303 SimplifiedOperatorBuilder* JSInliningHeuristic::simplified() const {
311 return jsgraph()->simplified(); 304 return jsgraph()->simplified();
312 } 305 }
313 306
314 } // namespace compiler 307 } // namespace compiler
315 } // namespace internal 308 } // namespace internal
316 } // namespace v8 309 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698