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

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

Issue 581673002: Revert "Add handling for argument adaptor frames to inlining." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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"
19 #include "src/parser.h" 18 #include "src/parser.h"
20 #include "src/rewriter.h" 19 #include "src/rewriter.h"
21 #include "src/scopes.h" 20 #include "src/scopes.h"
22 21
23 22
24 namespace v8 { 23 namespace v8 {
25 namespace internal { 24 namespace internal {
26 namespace compiler { 25 namespace compiler {
27 26
28 class InlinerVisitor : public NullNodeVisitor { 27 class InlinerVisitor : public NullNodeVisitor {
(...skipping 19 matching lines...) Expand all
48 void JSInliner::Inline() { 47 void JSInliner::Inline() {
49 InlinerVisitor visitor(this); 48 InlinerVisitor visitor(this);
50 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); 49 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor);
51 } 50 }
52 51
53 52
54 // TODO(sigurds) Find a home for this function and reuse it everywhere (esp. in 53 // TODO(sigurds) Find a home for this function and reuse it everywhere (esp. in
55 // test cases, where similar code is currently duplicated). 54 // test cases, where similar code is currently duplicated).
56 static void Parse(Handle<JSFunction> function, CompilationInfoWithZone* info) { 55 static void Parse(Handle<JSFunction> function, CompilationInfoWithZone* info) {
57 CHECK(Parser::Parse(info)); 56 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
103 // Inline this graph at {call}, use {jsgraph} and its zone to create 93 // Inline this graph at {call}, use {jsgraph} and its zone to create
104 // any new nodes. 94 // any new nodes.
105 void InlineAtCall(JSGraph* jsgraph, Node* call); 95 void InlineAtCall(JSGraph* jsgraph, Node* call);
106 96
107 // Ensure that only a single return reaches the end node. 97 // Ensure that only a single return reaches the end node.
108 static void UnifyReturn(JSGraph* jsgraph); 98 static void UnifyReturn(JSGraph* jsgraph);
109 99
110 private: 100 private:
111 Node* start_; 101 Node* start_;
112 Node* end_; 102 Node* end_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 189
200 void CopyGraph() { 190 void CopyGraph() {
201 source_graph_->VisitNodeInputsFromEnd(this); 191 source_graph_->VisitNodeInputsFromEnd(this);
202 ReplaceSentinels(); 192 ReplaceSentinels();
203 } 193 }
204 194
205 const NodeVector& copies() { return copies_; } 195 const NodeVector& copies() { return copies_; }
206 196
207 private: 197 private:
208 void ReplaceSentinels() { 198 void ReplaceSentinels() {
209 for (NodeId id = 0; id < source_graph_->NodeCount(); ++id) { 199 for (int id = 0; id < source_graph_->NodeCount(); ++id) {
210 Node* sentinel = sentinels_[id]; 200 Node* sentinel = sentinels_[id];
211 if (sentinel == NULL) continue; 201 if (sentinel == NULL) continue;
212 Node* copy = copies_[id]; 202 Node* copy = copies_[id];
213 DCHECK_NE(NULL, copy); 203 DCHECK_NE(NULL, copy);
214 sentinel->ReplaceUses(copy); 204 sentinel->ReplaceUses(copy);
215 } 205 }
216 } 206 }
217 207
218 Node* GetSentinel(Node* original) { 208 Node* GetSentinel(Node* original) {
219 Node* sentinel = sentinels_[original->id()]; 209 Node* sentinel = sentinels_[original->id()];
(...skipping 18 matching lines...) Expand all
238 Node* control = NodeProperties::GetControlInput(call); 228 Node* control = NodeProperties::GetControlInput(call);
239 229
240 // The inlinee uses the context from the JSFunction object. This will 230 // The inlinee uses the context from the JSFunction object. This will
241 // also be the effect dependency for the inlinee as it produces an effect. 231 // also be the effect dependency for the inlinee as it produces an effect.
242 SimplifiedOperatorBuilder simplified(jsgraph->zone()); 232 SimplifiedOperatorBuilder simplified(jsgraph->zone());
243 Node* context = jsgraph->graph()->NewNode( 233 Node* context = jsgraph->graph()->NewNode(
244 simplified.LoadField(AccessBuilder::ForJSFunctionContext()), 234 simplified.LoadField(AccessBuilder::ForJSFunctionContext()),
245 NodeProperties::GetValueInput(call, 0), 235 NodeProperties::GetValueInput(call, 0),
246 NodeProperties::GetEffectInput(call)); 236 NodeProperties::GetEffectInput(call));
247 237
238 // {inlinee_inputs} counts JSFunction, Receiver, arguments, context,
239 // but not effect, control.
240 int inlinee_inputs = start_->op()->OutputCount();
248 // Context is last argument. 241 // Context is last argument.
249 int inlinee_context_index = static_cast<int>(total_parameters()) - 1; 242 int inlinee_context_index = inlinee_inputs - 1;
250 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not 243 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not
251 // context, effect, control. 244 // context, effect, control.
252 int inliner_inputs = OperatorProperties::GetValueInputCount(call->op()); 245 int inliner_inputs = OperatorProperties::GetValueInputCount(call->op());
253 // Iterate over all uses of the start node. 246 // Iterate over all uses of the start node.
254 UseIter iter = start_->uses().begin(); 247 UseIter iter = start_->uses().begin();
255 while (iter != start_->uses().end()) { 248 while (iter != start_->uses().end()) {
256 Node* use = *iter; 249 Node* use = *iter;
257 switch (use->opcode()) { 250 switch (use->opcode()) {
258 case IrOpcode::kParameter: { 251 case IrOpcode::kParameter: {
259 int index = 1 + OpParameter<int>(use->op()); 252 int index = 1 + OpParameter<int>(use->op());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 iter.UpdateToAndIncrement(value_output()); 292 iter.UpdateToAndIncrement(value_output());
300 } 293 }
301 } 294 }
302 call->RemoveAllInputs(); 295 call->RemoveAllInputs();
303 DCHECK_EQ(0, call->UseCount()); 296 DCHECK_EQ(0, call->UseCount());
304 // TODO(sigurds) Remove this once we copy. 297 // TODO(sigurds) Remove this once we copy.
305 unique_return()->RemoveAllInputs(); 298 unique_return()->RemoveAllInputs();
306 } 299 }
307 300
308 301
309 // TODO(turbofan) Provide such accessors for every node, possibly even 302 void JSInliner::TryInlineCall(Node* call) {
310 // generate them. 303 DCHECK_EQ(IrOpcode::kJSCallFunction, call->opcode());
311 class JSCallFunctionAccessor {
312 public:
313 explicit JSCallFunctionAccessor(Node* call) : call_(call) {
314 DCHECK_EQ(IrOpcode::kJSCallFunction, call->opcode());
315 }
316 304
317 Node* jsfunction() { return call_->InputAt(0); } 305 HeapObjectMatcher<JSFunction> match(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());
377 if (!match.HasValue()) { 306 if (!match.HasValue()) {
378 return; 307 return;
379 } 308 }
380 309
381 Handle<JSFunction> function = match.Value().handle(); 310 Handle<JSFunction> function = match.Value().handle();
382 311
383 if (function->shared()->native()) { 312 if (function->shared()->native()) {
384 if (FLAG_trace_turbo_inlining) { 313 if (FLAG_trace_turbo_inlining) {
385 SmartArrayPointer<char> name = 314 SmartArrayPointer<char> name =
386 function->shared()->DebugName()->ToCString(); 315 function->shared()->DebugName()->ToCString();
387 PrintF("Not Inlining %s into %s because inlinee is native\n", name.get(), 316 PrintF("Not Inlining %s into %s because inlinee is native\n", name.get(),
388 info_->shared_info()->DebugName()->ToCString().get()); 317 info_->shared_info()->DebugName()->ToCString().get());
389 } 318 }
390 return; 319 return;
391 } 320 }
392 321
393 CompilationInfoWithZone info(function); 322 CompilationInfoWithZone info(function);
394 Parse(function, &info); 323 Parse(function, &info);
395 324
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
408 if (info.scope()->arguments() != NULL) { 325 if (info.scope()->arguments() != NULL) {
409 // For now do not inline functions that use their arguments array. 326 // For now do not inline functions that use their arguments array.
410 SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString(); 327 SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString();
411 if (FLAG_trace_turbo_inlining) { 328 if (FLAG_trace_turbo_inlining) {
412 PrintF( 329 PrintF(
413 "Not Inlining %s into %s because inlinee uses arguments " 330 "Not Inlining %s into %s because inlinee uses arguments "
414 "array\n", 331 "array\n",
415 name.get(), info_->shared_info()->DebugName()->ToCString().get()); 332 name.get(), info_->shared_info()->DebugName()->ToCString().get());
416 } 333 }
417 return; 334 return;
(...skipping 11 matching lines...) Expand all
429 jsgraph_->machine()); 346 jsgraph_->machine());
430 347
431 AstGraphBuilder graph_builder(&info, &jsgraph); 348 AstGraphBuilder graph_builder(&info, &jsgraph);
432 graph_builder.CreateGraph(); 349 graph_builder.CreateGraph();
433 Inlinee::UnifyReturn(&jsgraph); 350 Inlinee::UnifyReturn(&jsgraph);
434 351
435 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); 352 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone());
436 visitor.CopyGraph(); 353 visitor.CopyGraph();
437 354
438 Inlinee inlinee(visitor.GetCopy(graph.start()), visitor.GetCopy(graph.end())); 355 Inlinee inlinee(visitor.GetCopy(graph.start()), visitor.GetCopy(graph.end()));
439 356 inlinee.InlineAtCall(jsgraph_, call);
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);
457 } 357 }
458 } 358 }
459 } 359 }
460 } // namespace v8::internal::compiler 360 } // 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