OLD | NEW |
---|---|
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" |
11 #include "src/compiler/ast-graph-builder.h" | 11 #include "src/compiler/ast-graph-builder.h" |
12 #include "src/compiler/common-operator.h" | 12 #include "src/compiler/common-operator.h" |
13 #include "src/compiler/common-operator-reducer.h" | |
14 #include "src/compiler/dead-code-elimination.h" | |
15 #include "src/compiler/graph-reducer.h" | |
16 #include "src/compiler/js-global-specialization.h" | |
13 #include "src/compiler/js-operator.h" | 17 #include "src/compiler/js-operator.h" |
14 #include "src/compiler/node-matchers.h" | 18 #include "src/compiler/node-matchers.h" |
15 #include "src/compiler/node-properties.h" | 19 #include "src/compiler/node-properties.h" |
16 #include "src/compiler/operator-properties.h" | 20 #include "src/compiler/operator-properties.h" |
17 #include "src/full-codegen/full-codegen.h" | 21 #include "src/full-codegen/full-codegen.h" |
18 #include "src/isolate-inl.h" | 22 #include "src/isolate-inl.h" |
19 #include "src/parser.h" | 23 #include "src/parser.h" |
20 #include "src/rewriter.h" | 24 #include "src/rewriter.h" |
21 #include "src/scopes.h" | 25 #include "src/scopes.h" |
22 | 26 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 250 |
247 JSCallFunctionAccessor call(node); | 251 JSCallFunctionAccessor call(node); |
248 HeapObjectMatcher match(call.jsfunction()); | 252 HeapObjectMatcher match(call.jsfunction()); |
249 if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange(); | 253 if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange(); |
250 Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value()); | 254 Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value()); |
251 | 255 |
252 return ReduceJSCallFunction(node, function); | 256 return ReduceJSCallFunction(node, function); |
253 } | 257 } |
254 | 258 |
255 | 259 |
260 namespace { | |
261 | |
262 // TODO(mstarzinger): This will disappear once we unify the native context | |
263 // specialization with the Pipeline. | |
264 class JSGraphReducer final : public GraphReducer { | |
265 public: | |
266 JSGraphReducer(JSGraph* jsgraph, Zone* zone) | |
267 : GraphReducer(zone, jsgraph->graph(), jsgraph->Dead()) {} | |
Michael Starzinger
2015/10/14 11:28:57
As discussed offline: Let's use the GraphReducer d
Benedikt Meurer
2015/10/14 11:29:13
Done.
| |
268 ~JSGraphReducer() final {} | |
269 }; | |
270 | |
271 } // namespace | |
272 | |
256 Reduction JSInliner::ReduceJSCallFunction(Node* node, | 273 Reduction JSInliner::ReduceJSCallFunction(Node* node, |
257 Handle<JSFunction> function) { | 274 Handle<JSFunction> function) { |
258 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); | 275 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); |
259 JSCallFunctionAccessor call(node); | 276 JSCallFunctionAccessor call(node); |
260 | 277 |
261 if (!function->shared()->IsInlineable()) { | 278 if (!function->shared()->IsInlineable()) { |
262 // Function must be inlineable. | 279 // Function must be inlineable. |
263 TRACE("Not inlining %s into %s because callee is not inlineable\n", | 280 TRACE("Not inlining %s into %s because callee is not inlineable\n", |
264 function->shared()->DebugName()->ToCString().get(), | 281 function->shared()->DebugName()->ToCString().get(), |
265 info_->shared_info()->DebugName()->ToCString().get()); | 282 info_->shared_info()->DebugName()->ToCString().get()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 TRACE("Not inlining %s into %s because call is recursive\n", | 320 TRACE("Not inlining %s into %s because call is recursive\n", |
304 function->shared()->DebugName()->ToCString().get(), | 321 function->shared()->DebugName()->ToCString().get(), |
305 info_->shared_info()->DebugName()->ToCString().get()); | 322 info_->shared_info()->DebugName()->ToCString().get()); |
306 return NoChange(); | 323 return NoChange(); |
307 } | 324 } |
308 } | 325 } |
309 | 326 |
310 Zone zone; | 327 Zone zone; |
311 ParseInfo parse_info(&zone, function); | 328 ParseInfo parse_info(&zone, function); |
312 CompilationInfo info(&parse_info); | 329 CompilationInfo info(&parse_info); |
313 if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled(); | 330 if (info_->is_deoptimization_enabled()) { |
331 info.MarkAsDeoptimizationEnabled(); | |
332 } | |
333 if (info_->is_native_context_specializing()) { | |
334 info.MarkAsNativeContextSpecializing(); | |
335 } | |
336 if (info_->is_typing_enabled()) { | |
337 info.MarkAsTypingEnabled(); | |
338 } | |
314 | 339 |
315 if (!Compiler::ParseAndAnalyze(info.parse_info())) { | 340 if (!Compiler::ParseAndAnalyze(info.parse_info())) { |
316 TRACE("Not inlining %s into %s because parsing failed\n", | 341 TRACE("Not inlining %s into %s because parsing failed\n", |
317 function->shared()->DebugName()->ToCString().get(), | 342 function->shared()->DebugName()->ToCString().get(), |
318 info_->shared_info()->DebugName()->ToCString().get()); | 343 info_->shared_info()->DebugName()->ToCString().get()); |
319 if (info_->isolate()->has_pending_exception()) { | 344 if (info_->isolate()->has_pending_exception()) { |
320 info_->isolate()->clear_pending_exception(); | 345 info_->isolate()->clear_pending_exception(); |
321 } | 346 } |
322 return NoChange(); | 347 return NoChange(); |
323 } | 348 } |
324 | 349 |
325 if (!Compiler::EnsureDeoptimizationSupport(&info)) { | 350 if (!Compiler::EnsureDeoptimizationSupport(&info)) { |
326 TRACE("Not inlining %s into %s because deoptimization support failed\n", | 351 TRACE("Not inlining %s into %s because deoptimization support failed\n", |
327 function->shared()->DebugName()->ToCString().get(), | 352 function->shared()->DebugName()->ToCString().get(), |
328 info_->shared_info()->DebugName()->ToCString().get()); | 353 info_->shared_info()->DebugName()->ToCString().get()); |
329 return NoChange(); | 354 return NoChange(); |
330 } | 355 } |
331 | 356 |
332 TRACE("Inlining %s into %s\n", | 357 TRACE("Inlining %s into %s\n", |
333 function->shared()->DebugName()->ToCString().get(), | 358 function->shared()->DebugName()->ToCString().get(), |
334 info_->shared_info()->DebugName()->ToCString().get()); | 359 info_->shared_info()->DebugName()->ToCString().get()); |
335 | 360 |
336 Graph graph(info.zone()); | 361 Graph graph(info.zone()); |
337 JSGraph jsgraph(info.isolate(), &graph, jsgraph_->common(), | 362 JSGraph jsgraph(info.isolate(), &graph, jsgraph_->common(), |
338 jsgraph_->javascript(), jsgraph_->machine()); | 363 jsgraph_->javascript(), jsgraph_->machine()); |
339 AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph); | 364 AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph); |
340 graph_builder.CreateGraph(false); | 365 graph_builder.CreateGraph(false); |
341 | 366 |
367 // TODO(mstarzinger): Unify this with the Pipeline once JSInliner refactoring | |
368 // starts. | |
369 if (info.is_native_context_specializing()) { | |
370 JSGraphReducer graph_reducer(&jsgraph, local_zone_); | |
371 DeadCodeElimination dead_code_elimination(&graph_reducer, &graph, | |
372 jsgraph.common()); | |
373 CommonOperatorReducer common_reducer(&graph_reducer, &graph, | |
374 jsgraph.common(), jsgraph.machine()); | |
375 JSGlobalSpecialization::Flags flags = JSGlobalSpecialization::kNoFlags; | |
376 if (info.is_deoptimization_enabled()) { | |
377 flags |= JSGlobalSpecialization::kDeoptimizationEnabled; | |
378 } | |
379 if (info.is_typing_enabled()) { | |
380 flags |= JSGlobalSpecialization::kTypingEnabled; | |
381 } | |
382 JSGlobalSpecialization global_specialization( | |
383 &graph_reducer, &jsgraph, flags, | |
384 handle(info.global_object(), info.isolate()), info_->dependencies()); | |
385 graph_reducer.AddReducer(&dead_code_elimination); | |
386 graph_reducer.AddReducer(&common_reducer); | |
387 graph_reducer.AddReducer(&global_specialization); | |
388 graph_reducer.ReduceGraph(); | |
389 } | |
390 | |
342 // The inlinee specializes to the context from the JSFunction object. | 391 // The inlinee specializes to the context from the JSFunction object. |
343 // TODO(turbofan): We might want to load the context from the JSFunction at | 392 // TODO(turbofan): We might want to load the context from the JSFunction at |
344 // runtime in case we only know the SharedFunctionInfo once we have dynamic | 393 // runtime in case we only know the SharedFunctionInfo once we have dynamic |
345 // type feedback in the compiler. | 394 // type feedback in the compiler. |
346 Node* context = jsgraph_->Constant(handle(function->context())); | 395 Node* context = jsgraph_->Constant(handle(function->context())); |
347 | 396 |
348 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); | 397 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); |
349 visitor.CopyGraph(); | 398 visitor.CopyGraph(); |
350 | 399 |
351 Node* start = visitor.GetCopy(graph.start()); | 400 Node* start = visitor.GetCopy(graph.start()); |
(...skipping 15 matching lines...) Expand all Loading... | |
367 | 416 |
368 // Remember that we inlined this function. | 417 // Remember that we inlined this function. |
369 info_->AddInlinedFunction(info.shared_info()); | 418 info_->AddInlinedFunction(info.shared_info()); |
370 | 419 |
371 return InlineCall(node, context, frame_state, start, end); | 420 return InlineCall(node, context, frame_state, start, end); |
372 } | 421 } |
373 | 422 |
374 } // namespace compiler | 423 } // namespace compiler |
375 } // namespace internal | 424 } // namespace internal |
376 } // namespace v8 | 425 } // namespace v8 |
OLD | NEW |