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

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

Issue 1410633006: [turbofan] Implement the call protocol properly for direct calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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.h" 5 #include "src/compiler/js-inlining.h"
6 6
7 #include "src/ast.h" 7 #include "src/ast.h"
8 #include "src/ast-numbering.h" 8 #include "src/ast-numbering.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/compiler/all-nodes.h" 10 #include "src/compiler/all-nodes.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 128
129 Reduction JSInliner::InlineCall(Node* call, Node* context, Node* frame_state, 129 Reduction JSInliner::InlineCall(Node* call, Node* context, Node* frame_state,
130 Node* start, Node* end) { 130 Node* start, Node* end) {
131 // The scheduler is smart enough to place our code; we just ensure {control} 131 // The scheduler is smart enough to place our code; we just ensure {control}
132 // becomes the control input of the start of the inlinee, and {effect} becomes 132 // becomes the control input of the start of the inlinee, and {effect} becomes
133 // the effect input of the start of the inlinee. 133 // the effect input of the start of the inlinee.
134 Node* control = NodeProperties::GetControlInput(call); 134 Node* control = NodeProperties::GetControlInput(call);
135 Node* effect = NodeProperties::GetEffectInput(call); 135 Node* effect = NodeProperties::GetEffectInput(call);
136 136
137 int const inlinee_arity_index =
138 static_cast<int>(start->op()->ValueOutputCount()) - 2;
137 // Context is last argument. 139 // Context is last argument.
Michael Starzinger 2015/11/04 13:43:14 nit: s/argument/parameter/ here.
Benedikt Meurer 2015/11/04 13:51:08 Done.
138 int const inlinee_context_index = 140 int const inlinee_context_index =
139 static_cast<int>(start->op()->ValueOutputCount()) - 1; 141 static_cast<int>(start->op()->ValueOutputCount()) - 1;
140 142
141 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not 143 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not
142 // context, effect, control. 144 // context, effect, control.
143 int inliner_inputs = call->op()->ValueInputCount(); 145 int inliner_inputs = call->op()->ValueInputCount();
144 // Iterate over all uses of the start node. 146 // Iterate over all uses of the start node.
145 for (Edge edge : start->use_edges()) { 147 for (Edge edge : start->use_edges()) {
146 Node* use = edge.from(); 148 Node* use = edge.from();
147 switch (use->opcode()) { 149 switch (use->opcode()) {
148 case IrOpcode::kParameter: { 150 case IrOpcode::kParameter: {
149 int index = 1 + ParameterIndexOf(use->op()); 151 int index = 1 + ParameterIndexOf(use->op());
150 DCHECK_LE(index, inlinee_context_index); 152 DCHECK_LE(index, inlinee_context_index);
151 if (index < inliner_inputs && index < inlinee_context_index) { 153 if (index < inliner_inputs && index < inlinee_arity_index) {
152 // There is an input from the call, and the index is a value 154 // There is an input from the call, and the index is a value
153 // projection but not the context, so rewire the input. 155 // projection but not the context, so rewire the input.
154 Replace(use, call->InputAt(index)); 156 Replace(use, call->InputAt(index));
157 } else if (index == inlinee_arity_index) {
158 Replace(use, jsgraph_->Int32Constant(inliner_inputs - 2));
Michael Starzinger 2015/11/04 13:43:14 nit: Can we add a comment "// The projection is re
Benedikt Meurer 2015/11/04 13:51:09 Done.
155 } else if (index == inlinee_context_index) { 159 } else if (index == inlinee_context_index) {
156 // The projection is requesting the inlinee function context. 160 // The projection is requesting the inlinee function context.
157 Replace(use, context); 161 Replace(use, context);
158 } else { 162 } else {
159 // Call has fewer arguments than required, fill with undefined. 163 // Call has fewer arguments than required, fill with undefined.
160 Replace(use, jsgraph_->UndefinedConstant()); 164 Replace(use, jsgraph_->UndefinedConstant());
161 } 165 }
162 break; 166 break;
163 } 167 }
164 default: 168 default:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 JSCallFunctionAccessor call(node); 271 JSCallFunctionAccessor call(node);
268 272
269 if (!function->shared()->IsInlineable()) { 273 if (!function->shared()->IsInlineable()) {
270 // Function must be inlineable. 274 // Function must be inlineable.
271 TRACE("Not inlining %s into %s because callee is not inlineable\n", 275 TRACE("Not inlining %s into %s because callee is not inlineable\n",
272 function->shared()->DebugName()->ToCString().get(), 276 function->shared()->DebugName()->ToCString().get(),
273 info_->shared_info()->DebugName()->ToCString().get()); 277 info_->shared_info()->DebugName()->ToCString().get());
274 return NoChange(); 278 return NoChange();
275 } 279 }
276 280
281 // Class constructors are callable, but [[Call]] will raise an exception.
282 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList).
Michael Starzinger 2015/11/04 13:43:14 nit: Parenthesis look weird, can we add a trailing
Benedikt Meurer 2015/11/04 13:51:09 Done.
283 if (IsClassConstructor(function->shared()->kind())) {
284 TRACE("Not inlining %s into %s because callee is classConstructor\n",
285 function->shared()->DebugName()->ToCString().get(),
286 info_->shared_info()->DebugName()->ToCString().get());
287 return NoChange();
288 }
289
277 if (function->shared()->HasDebugInfo()) { 290 if (function->shared()->HasDebugInfo()) {
278 // Function contains break points. 291 // Function contains break points.
279 TRACE("Not inlining %s into %s because callee may contain break points\n", 292 TRACE("Not inlining %s into %s because callee may contain break points\n",
280 function->shared()->DebugName()->ToCString().get(), 293 function->shared()->DebugName()->ToCString().get(),
281 info_->shared_info()->DebugName()->ToCString().get()); 294 info_->shared_info()->DebugName()->ToCString().get());
282 return NoChange(); 295 return NoChange();
283 } 296 }
284 297
285 // Disallow cross native-context inlining for now. This means that all parts 298 // Disallow cross native-context inlining for now. This means that all parts
286 // of the resulting code will operate on the same global object. 299 // of the resulting code will operate on the same global object.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); 447 const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
435 Node* effect = NodeProperties::GetEffectInput(node); 448 Node* effect = NodeProperties::GetEffectInput(node);
436 Node* convert = jsgraph_->graph()->NewNode( 449 Node* convert = jsgraph_->graph()->NewNode(
437 jsgraph_->javascript()->ConvertReceiver(p.convert_mode()), 450 jsgraph_->javascript()->ConvertReceiver(p.convert_mode()),
438 call.receiver(), context, call.frame_state_before(), effect, start); 451 call.receiver(), context, call.frame_state_before(), effect, start);
439 NodeProperties::ReplaceValueInput(node, convert, 1); 452 NodeProperties::ReplaceValueInput(node, convert, 1);
440 NodeProperties::ReplaceEffectInput(node, convert); 453 NodeProperties::ReplaceEffectInput(node, convert);
441 } 454 }
442 455
443 // Insert argument adaptor frame if required. The callees formal parameter 456 // Insert argument adaptor frame if required. The callees formal parameter
444 // count (i.e. value outputs of start node minus target, receiver & context) 457 // count (i.e. value outputs of start node minus target, receiver, num args
445 // have to match the number of arguments passed to the call. 458 // and context) have to match the number of arguments passed to the call.
446 DCHECK_EQ(static_cast<int>(parameter_count), 459 DCHECK_EQ(static_cast<int>(parameter_count),
447 start->op()->ValueOutputCount() - 3); 460 start->op()->ValueOutputCount() - 4);
448 if (call.formal_arguments() != parameter_count) { 461 if (call.formal_arguments() != parameter_count) {
449 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info()); 462 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info());
450 } 463 }
451 464
452 return InlineCall(node, context, frame_state, start, end); 465 return InlineCall(node, context, frame_state, start, end);
453 } 466 }
454 467
455 } // namespace compiler 468 } // namespace compiler
456 } // namespace internal 469 } // namespace internal
457 } // namespace v8 470 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698