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

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

Issue 544953006: Reland "Add handling for argument adaptor frames to inlining." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reland fix: Add framestate to CollectStackTrace runtime call. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/js-inlining.h ('k') | src/compiler/linkage.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/access-builder.h" 5 #include "src/compiler/access-builder.h"
6 #include "src/compiler/ast-graph-builder.h" 6 #include "src/compiler/ast-graph-builder.h"
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/generic-node-inl.h" 8 #include "src/compiler/generic-node-inl.h"
9 #include "src/compiler/graph-inl.h" 9 #include "src/compiler/graph-inl.h"
10 #include "src/compiler/graph-visualizer.h" 10 #include "src/compiler/graph-visualizer.h"
11 #include "src/compiler/js-inlining.h" 11 #include "src/compiler/js-inlining.h"
12 #include "src/compiler/js-operator.h" 12 #include "src/compiler/js-operator.h"
13 #include "src/compiler/node-aux-data-inl.h" 13 #include "src/compiler/node-aux-data-inl.h"
14 #include "src/compiler/node-matchers.h" 14 #include "src/compiler/node-matchers.h"
15 #include "src/compiler/node-properties-inl.h" 15 #include "src/compiler/node-properties-inl.h"
16 #include "src/compiler/simplified-operator.h" 16 #include "src/compiler/simplified-operator.h"
17 #include "src/compiler/typer.h" 17 #include "src/compiler/typer.h"
18 #include "src/full-codegen.h"
18 #include "src/parser.h" 19 #include "src/parser.h"
19 #include "src/rewriter.h" 20 #include "src/rewriter.h"
20 #include "src/scopes.h" 21 #include "src/scopes.h"
21 22
22 23
23 namespace v8 { 24 namespace v8 {
24 namespace internal { 25 namespace internal {
25 namespace compiler { 26 namespace compiler {
26 27
27 class InlinerVisitor : public NullNodeVisitor { 28 class InlinerVisitor : public NullNodeVisitor {
(...skipping 19 matching lines...) Expand all
47 void JSInliner::Inline() { 48 void JSInliner::Inline() {
48 InlinerVisitor visitor(this); 49 InlinerVisitor visitor(this);
49 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); 50 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor);
50 } 51 }
51 52
52 53
53 // TODO(sigurds) Find a home for this function and reuse it everywhere (esp. in 54 // TODO(sigurds) Find a home for this function and reuse it everywhere (esp. in
54 // test cases, where similar code is currently duplicated). 55 // test cases, where similar code is currently duplicated).
55 static void Parse(Handle<JSFunction> function, CompilationInfoWithZone* info) { 56 static void Parse(Handle<JSFunction> function, CompilationInfoWithZone* info) {
56 CHECK(Parser::Parse(info)); 57 CHECK(Parser::Parse(info));
57 info->SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
58 CHECK(Rewriter::Rewrite(info)); 58 CHECK(Rewriter::Rewrite(info));
59 CHECK(Scope::Analyze(info)); 59 CHECK(Scope::Analyze(info));
60 CHECK_NE(NULL, info->scope()); 60 CHECK_NE(NULL, info->scope());
61 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); 61 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone());
62 info->shared_info()->set_scope_info(*scope_info); 62 info->shared_info()->set_scope_info(*scope_info);
63 } 63 }
64 64
65 65
66 // A facade on a JSFunction's graph to facilitate inlining. It assumes the 66 // A facade on a JSFunction's graph to facilitate inlining. It assumes the
67 // that the function graph has only one return statement, and provides 67 // that the function graph has only one return statement, and provides
(...skipping 15 matching lines...) Expand all
83 // that is the value input of the return statement of the inlinee. 83 // that is the value input of the return statement of the inlinee.
84 Node* value_output() { 84 Node* value_output() {
85 return NodeProperties::GetValueInput(unique_return(), 0); 85 return NodeProperties::GetValueInput(unique_return(), 0);
86 } 86 }
87 // Return the unique return statement of the graph. 87 // Return the unique return statement of the graph.
88 Node* unique_return() { 88 Node* unique_return() {
89 Node* unique_return = NodeProperties::GetControlInput(end_); 89 Node* unique_return = NodeProperties::GetControlInput(end_);
90 DCHECK_EQ(IrOpcode::kReturn, unique_return->opcode()); 90 DCHECK_EQ(IrOpcode::kReturn, unique_return->opcode());
91 return unique_return; 91 return unique_return;
92 } 92 }
93
94 // Counts JSFunction, Receiver, arguments, context but not effect, control.
95 size_t total_parameters() { return start_->op()->OutputCount(); }
96
97 // Counts only formal parameters.
98 size_t formal_parameters() {
99 DCHECK_GE(total_parameters(), 3);
100 return total_parameters() - 3;
101 }
102
93 // Inline this graph at {call}, use {jsgraph} and its zone to create 103 // Inline this graph at {call}, use {jsgraph} and its zone to create
94 // any new nodes. 104 // any new nodes.
95 void InlineAtCall(JSGraph* jsgraph, Node* call); 105 void InlineAtCall(JSGraph* jsgraph, Node* call);
96 106
97 // Ensure that only a single return reaches the end node. 107 // Ensure that only a single return reaches the end node.
98 static void UnifyReturn(JSGraph* jsgraph); 108 static void UnifyReturn(JSGraph* jsgraph);
99 109
100 private: 110 private:
101 Node* start_; 111 Node* start_;
102 Node* end_; 112 Node* end_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 199
190 void CopyGraph() { 200 void CopyGraph() {
191 source_graph_->VisitNodeInputsFromEnd(this); 201 source_graph_->VisitNodeInputsFromEnd(this);
192 ReplaceSentinels(); 202 ReplaceSentinels();
193 } 203 }
194 204
195 const NodeVector& copies() { return copies_; } 205 const NodeVector& copies() { return copies_; }
196 206
197 private: 207 private:
198 void ReplaceSentinels() { 208 void ReplaceSentinels() {
199 for (int id = 0; id < source_graph_->NodeCount(); ++id) { 209 for (NodeId id = 0; id < source_graph_->NodeCount(); ++id) {
200 Node* sentinel = sentinels_[id]; 210 Node* sentinel = sentinels_[id];
201 if (sentinel == NULL) continue; 211 if (sentinel == NULL) continue;
202 Node* copy = copies_[id]; 212 Node* copy = copies_[id];
203 DCHECK_NE(NULL, copy); 213 DCHECK_NE(NULL, copy);
204 sentinel->ReplaceUses(copy); 214 sentinel->ReplaceUses(copy);
205 } 215 }
206 } 216 }
207 217
208 Node* GetSentinel(Node* original) { 218 Node* GetSentinel(Node* original) {
209 Node* sentinel = sentinels_[original->id()]; 219 Node* sentinel = sentinels_[original->id()];
(...skipping 18 matching lines...) Expand all
228 Node* control = NodeProperties::GetControlInput(call); 238 Node* control = NodeProperties::GetControlInput(call);
229 239
230 // The inlinee uses the context from the JSFunction object. This will 240 // The inlinee uses the context from the JSFunction object. This will
231 // also be the effect dependency for the inlinee as it produces an effect. 241 // also be the effect dependency for the inlinee as it produces an effect.
232 SimplifiedOperatorBuilder simplified(jsgraph->zone()); 242 SimplifiedOperatorBuilder simplified(jsgraph->zone());
233 Node* context = jsgraph->graph()->NewNode( 243 Node* context = jsgraph->graph()->NewNode(
234 simplified.LoadField(AccessBuilder::ForJSFunctionContext()), 244 simplified.LoadField(AccessBuilder::ForJSFunctionContext()),
235 NodeProperties::GetValueInput(call, 0), 245 NodeProperties::GetValueInput(call, 0),
236 NodeProperties::GetEffectInput(call)); 246 NodeProperties::GetEffectInput(call));
237 247
238 // {inlinee_inputs} counts JSFunction, Receiver, arguments, context,
239 // but not effect, control.
240 int inlinee_inputs = start_->op()->OutputCount();
241 // Context is last argument. 248 // Context is last argument.
242 int inlinee_context_index = inlinee_inputs - 1; 249 int inlinee_context_index = static_cast<int>(total_parameters()) - 1;
243 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not 250 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not
244 // context, effect, control. 251 // context, effect, control.
245 int inliner_inputs = OperatorProperties::GetValueInputCount(call->op()); 252 int inliner_inputs = OperatorProperties::GetValueInputCount(call->op());
246 // Iterate over all uses of the start node. 253 // Iterate over all uses of the start node.
247 UseIter iter = start_->uses().begin(); 254 UseIter iter = start_->uses().begin();
248 while (iter != start_->uses().end()) { 255 while (iter != start_->uses().end()) {
249 Node* use = *iter; 256 Node* use = *iter;
250 switch (use->opcode()) { 257 switch (use->opcode()) {
251 case IrOpcode::kParameter: { 258 case IrOpcode::kParameter: {
252 int index = 1 + OpParameter<int>(use->op()); 259 int index = 1 + OpParameter<int>(use->op());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 iter.UpdateToAndIncrement(value_output()); 299 iter.UpdateToAndIncrement(value_output());
293 } 300 }
294 } 301 }
295 call->RemoveAllInputs(); 302 call->RemoveAllInputs();
296 DCHECK_EQ(0, call->UseCount()); 303 DCHECK_EQ(0, call->UseCount());
297 // TODO(sigurds) Remove this once we copy. 304 // TODO(sigurds) Remove this once we copy.
298 unique_return()->RemoveAllInputs(); 305 unique_return()->RemoveAllInputs();
299 } 306 }
300 307
301 308
302 void JSInliner::TryInlineCall(Node* call) { 309 // TODO(turbofan) Provide such accessors for every node, possibly even
303 DCHECK_EQ(IrOpcode::kJSCallFunction, call->opcode()); 310 // generate them.
311 class JSCallFunctionAccessor {
312 public:
313 explicit JSCallFunctionAccessor(Node* call) : call_(call) {
314 DCHECK_EQ(IrOpcode::kJSCallFunction, call->opcode());
315 }
304 316
305 HeapObjectMatcher<JSFunction> match(call->InputAt(0)); 317 Node* jsfunction() { return call_->InputAt(0); }
318
319 Node* receiver() { return call_->InputAt(1); }
320
321 Node* formal_argument(size_t index) {
322 DCHECK(index < formal_arguments());
323 return call_->InputAt(static_cast<int>(2 + index));
324 }
325
326 size_t formal_arguments() {
327 // {value_inputs} includes jsfunction and receiver.
328 size_t value_inputs = OperatorProperties::GetValueInputCount(call_->op());
329 DCHECK_GE(call_->InputCount(), 2);
330 return value_inputs - 2;
331 }
332
333 Node* frame_state() { return NodeProperties::GetFrameStateInput(call_); }
334
335 private:
336 Node* call_;
337 };
338
339
340 void JSInliner::AddClosureToFrameState(Node* frame_state,
341 Handle<JSFunction> jsfunction) {
342 FrameStateCallInfo call_info = OpParameter<FrameStateCallInfo>(frame_state);
343 const Operator* op = jsgraph_->common()->FrameState(
344 FrameStateType::JS_FRAME, call_info.bailout_id(),
345 call_info.state_combine(), jsfunction);
346 frame_state->set_op(op);
347 }
348
349
350 Node* JSInliner::CreateArgumentsAdaptorFrameState(JSCallFunctionAccessor* call,
351 Handle<JSFunction> jsfunction,
352 Zone* temp_zone) {
353 const Operator* op =
354 jsgraph_->common()->FrameState(FrameStateType::ARGUMENTS_ADAPTOR,
355 BailoutId(-1), kIgnoreOutput, jsfunction);
356 const Operator* op0 = jsgraph_->common()->StateValues(0);
357 Node* node0 = jsgraph_->graph()->NewNode(op0);
358 NodeVector params(temp_zone);
359 params.push_back(call->receiver());
360 for (size_t argument = 0; argument != call->formal_arguments(); ++argument) {
361 params.push_back(call->formal_argument(argument));
362 }
363 const Operator* op_param =
364 jsgraph_->common()->StateValues(static_cast<int>(params.size()));
365 Node* params_node = jsgraph_->graph()->NewNode(
366 op_param, static_cast<int>(params.size()), &params.front());
367 return jsgraph_->graph()->NewNode(op, params_node, node0, node0,
368 jsgraph_->UndefinedConstant(),
369 call->frame_state());
370 }
371
372
373 void JSInliner::TryInlineCall(Node* call_node) {
374 JSCallFunctionAccessor call(call_node);
375
376 HeapObjectMatcher<JSFunction> match(call.jsfunction());
306 if (!match.HasValue()) { 377 if (!match.HasValue()) {
307 return; 378 return;
308 } 379 }
309 380
310 Handle<JSFunction> function = match.Value().handle(); 381 Handle<JSFunction> function = match.Value().handle();
311 382
312 if (function->shared()->native()) { 383 if (function->shared()->native()) {
313 if (FLAG_trace_turbo_inlining) { 384 if (FLAG_trace_turbo_inlining) {
314 SmartArrayPointer<char> name = 385 SmartArrayPointer<char> name =
315 function->shared()->DebugName()->ToCString(); 386 function->shared()->DebugName()->ToCString();
316 PrintF("Not Inlining %s into %s because inlinee is native\n", name.get(), 387 PrintF("Not Inlining %s into %s because inlinee is native\n", name.get(),
317 info_->shared_info()->DebugName()->ToCString().get()); 388 info_->shared_info()->DebugName()->ToCString().get());
318 } 389 }
319 return; 390 return;
320 } 391 }
321 392
322 CompilationInfoWithZone info(function); 393 CompilationInfoWithZone info(function);
323 Parse(function, &info); 394 Parse(function, &info);
324 395
396 if (!function->shared()->has_deoptimization_support()) {
397 // TODO(turbofan) In the future, unoptimized code with deopt support could
398 // be generated lazily once deopt is triggered.
399 info.EnableDeoptimizationSupport();
400 if (!FullCodeGenerator::MakeCode(&info)) {
401 DCHECK(false);
402 return;
403 }
404 function->shared()->EnableDeoptimizationSupport(*info.code());
405 function->shared()->set_feedback_vector(*info.feedback_vector());
406 }
407
325 if (info.scope()->arguments() != NULL) { 408 if (info.scope()->arguments() != NULL) {
326 // For now do not inline functions that use their arguments array. 409 // For now do not inline functions that use their arguments array.
327 SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString(); 410 SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString();
328 if (FLAG_trace_turbo_inlining) { 411 if (FLAG_trace_turbo_inlining) {
329 PrintF( 412 PrintF(
330 "Not Inlining %s into %s because inlinee uses arguments " 413 "Not Inlining %s into %s because inlinee uses arguments "
331 "array\n", 414 "array\n",
332 name.get(), info_->shared_info()->DebugName()->ToCString().get()); 415 name.get(), info_->shared_info()->DebugName()->ToCString().get());
333 } 416 }
334 return; 417 return;
(...skipping 11 matching lines...) Expand all
346 jsgraph_->machine()); 429 jsgraph_->machine());
347 430
348 AstGraphBuilder graph_builder(&info, &jsgraph); 431 AstGraphBuilder graph_builder(&info, &jsgraph);
349 graph_builder.CreateGraph(); 432 graph_builder.CreateGraph();
350 Inlinee::UnifyReturn(&jsgraph); 433 Inlinee::UnifyReturn(&jsgraph);
351 434
352 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); 435 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone());
353 visitor.CopyGraph(); 436 visitor.CopyGraph();
354 437
355 Inlinee inlinee(visitor.GetCopy(graph.start()), visitor.GetCopy(graph.end())); 438 Inlinee inlinee(visitor.GetCopy(graph.start()), visitor.GetCopy(graph.end()));
356 inlinee.InlineAtCall(jsgraph_, call); 439
440 Node* outer_frame_state = call.frame_state();
441 // Insert argument adaptor frame if required.
442 if (call.formal_arguments() != inlinee.formal_parameters()) {
443 outer_frame_state =
444 CreateArgumentsAdaptorFrameState(&call, function, info.zone());
445 }
446
447 for (NodeVectorConstIter it = visitor.copies().begin();
448 it != visitor.copies().end(); ++it) {
449 Node* node = *it;
450 if (node != NULL && node->opcode() == IrOpcode::kFrameState) {
451 AddClosureToFrameState(node, function);
452 NodeProperties::ReplaceFrameStateInput(node, outer_frame_state);
453 }
454 }
455
456 inlinee.InlineAtCall(jsgraph_, call_node);
357 } 457 }
358 } 458 }
359 } 459 }
360 } // namespace v8::internal::compiler 460 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/js-inlining.h ('k') | src/compiler/linkage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698