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

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

Issue 1435873002: [turbofan] Initial support for constructor call inlining. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. 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
« no previous file with comments | « src/compiler/js-inlining.cc ('k') | src/compiler/js-operator.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 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/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/objects-inl.h" 9 #include "src/objects-inl.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace compiler { 13 namespace compiler {
14 14
15 Reduction JSInliningHeuristic::Reduce(Node* node) { 15 Reduction JSInliningHeuristic::Reduce(Node* node) {
16 if (node->opcode() != IrOpcode::kJSCallFunction) return NoChange(); 16 if (!IrOpcode::IsInlineeOpcode(node->opcode())) return NoChange();
17 17
18 // Check if we already saw that {node} before, and if so, just skip it. 18 // Check if we already saw that {node} before, and if so, just skip it.
19 if (seen_.find(node->id()) != seen_.end()) return NoChange(); 19 if (seen_.find(node->id()) != seen_.end()) return NoChange();
20 seen_.insert(node->id()); 20 seen_.insert(node->id());
21 21
22 Node* callee = node->InputAt(0); 22 Node* callee = node->InputAt(0);
23 HeapObjectMatcher match(callee); 23 HeapObjectMatcher match(callee);
24 if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange(); 24 if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange();
25 Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value()); 25 Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value());
26 26
27 // Functions marked with %SetForceInlineFlag are immediately inlined. 27 // Functions marked with %SetForceInlineFlag are immediately inlined.
28 if (function->shared()->force_inline()) { 28 if (function->shared()->force_inline()) {
29 return inliner_.ReduceJSCallFunction(node, function); 29 return inliner_.ReduceJSCall(node, function);
30 } 30 }
31 31
32 // Handling of special inlining modes right away: 32 // Handling of special inlining modes right away:
33 // - For restricted inlining: stop all handling at this point. 33 // - For restricted inlining: stop all handling at this point.
34 // - For stressing inlining: immediately handle all functions. 34 // - For stressing inlining: immediately handle all functions.
35 switch (mode_) { 35 switch (mode_) {
36 case kRestrictedInlining: 36 case kRestrictedInlining:
37 return NoChange(); 37 return NoChange();
38 case kStressInlining: 38 case kStressInlining:
39 return inliner_.ReduceJSCallFunction(node, function); 39 return inliner_.ReduceJSCall(node, function);
40 case kGeneralInlining: 40 case kGeneralInlining:
41 break; 41 break;
42 } 42 }
43 43
44 // --------------------------------------------------------------------------- 44 // ---------------------------------------------------------------------------
45 // Everything below this line is part of the inlining heuristic. 45 // Everything below this line is part of the inlining heuristic.
46 // --------------------------------------------------------------------------- 46 // ---------------------------------------------------------------------------
47 47
48 // Built-in functions are handled by the JSBuiltinReducer. 48 // Built-in functions are handled by the JSBuiltinReducer.
49 if (function->shared()->HasBuiltinFunctionId()) return NoChange(); 49 if (function->shared()->HasBuiltinFunctionId()) return NoChange();
(...skipping 10 matching lines...) Expand all
60 if (function->shared()->ast_node_count() > FLAG_max_inlined_nodes) { 60 if (function->shared()->ast_node_count() > FLAG_max_inlined_nodes) {
61 return NoChange(); 61 return NoChange();
62 } 62 }
63 63
64 // Avoid inlining within or across the boundary of asm.js code. 64 // Avoid inlining within or across the boundary of asm.js code.
65 if (info_->shared_info()->asm_function()) return NoChange(); 65 if (info_->shared_info()->asm_function()) return NoChange();
66 if (function->shared()->asm_function()) return NoChange(); 66 if (function->shared()->asm_function()) return NoChange();
67 67
68 // Stop inlinining once the maximum allowed level is reached. 68 // Stop inlinining once the maximum allowed level is reached.
69 int level = 0; 69 int level = 0;
70 for (Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); 70 for (Node* frame_state = NodeProperties::GetFrameStateInput(node, 0);
71 frame_state->opcode() == IrOpcode::kFrameState; 71 frame_state->opcode() == IrOpcode::kFrameState;
72 frame_state = NodeProperties::GetFrameStateInput(frame_state, 0)) { 72 frame_state = NodeProperties::GetFrameStateInput(frame_state, 0)) {
73 if (++level > FLAG_max_inlining_levels) return NoChange(); 73 if (++level > FLAG_max_inlining_levels) return NoChange();
74 } 74 }
75 75
76 // Gather feedback on how often this call site has been hit before. 76 // Gather feedback on how often this call site has been hit before.
77 CallFunctionParameters p = CallFunctionParametersOf(node->op());
78 int calls = -1; // Same default as CallICNexus::ExtractCallCount. 77 int calls = -1; // Same default as CallICNexus::ExtractCallCount.
79 if (p.feedback().IsValid()) { 78 // TODO(turbofan): We also want call counts for constructor calls.
80 CallICNexus nexus(p.feedback().vector(), p.feedback().slot()); 79 if (node->opcode() == IrOpcode::kJSCallFunction) {
81 calls = nexus.ExtractCallCount(); 80 CallFunctionParameters p = CallFunctionParametersOf(node->op());
81 if (p.feedback().IsValid()) {
82 CallICNexus nexus(p.feedback().vector(), p.feedback().slot());
83 calls = nexus.ExtractCallCount();
84 }
82 } 85 }
83 86
84 // --------------------------------------------------------------------------- 87 // ---------------------------------------------------------------------------
85 // Everything above this line is part of the inlining heuristic. 88 // Everything above this line is part of the inlining heuristic.
86 // --------------------------------------------------------------------------- 89 // ---------------------------------------------------------------------------
87 90
88 // In the general case we remember the candidate for later. 91 // In the general case we remember the candidate for later.
89 candidates_.insert({function, node, calls}); 92 candidates_.insert({function, node, calls});
90 return NoChange(); 93 return NoChange();
91 } 94 }
92 95
93 96
94 void JSInliningHeuristic::Finalize() { 97 void JSInliningHeuristic::Finalize() {
95 if (candidates_.empty()) return; // Nothing to do without candidates. 98 if (candidates_.empty()) return; // Nothing to do without candidates.
96 if (FLAG_trace_turbo_inlining) PrintCandidates(); 99 if (FLAG_trace_turbo_inlining) PrintCandidates();
97 100
98 while (!candidates_.empty()) { 101 while (!candidates_.empty()) {
99 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) break; 102 if (cumulative_count_ > FLAG_max_inlined_nodes_cumulative) break;
100 auto i = candidates_.begin(); 103 auto i = candidates_.begin();
101 Candidate const& candidate = *i; 104 Candidate const& candidate = *i;
102 inliner_.ReduceJSCallFunction(candidate.node, candidate.function); 105 inliner_.ReduceJSCall(candidate.node, candidate.function);
103 cumulative_count_ += candidate.function->shared()->ast_node_count(); 106 cumulative_count_ += candidate.function->shared()->ast_node_count();
104 candidates_.erase(i); 107 candidates_.erase(i);
105 } 108 }
106 } 109 }
107 110
108 111
109 bool JSInliningHeuristic::CandidateCompare::operator()( 112 bool JSInliningHeuristic::CandidateCompare::operator()(
110 const Candidate& left, const Candidate& right) const { 113 const Candidate& left, const Candidate& right) const {
111 return left.node != right.node && left.calls >= right.calls; 114 return left.node != right.node && left.calls >= right.calls;
112 } 115 }
113 116
114 117
115 void JSInliningHeuristic::PrintCandidates() { 118 void JSInliningHeuristic::PrintCandidates() {
116 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size()); 119 PrintF("Candidates for inlining (size=%zu):\n", candidates_.size());
117 for (const Candidate& candidate : candidates_) { 120 for (const Candidate& candidate : candidates_) {
118 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n", 121 PrintF(" id:%d, calls:%d, size[source]:%d, size[ast]:%d / %s\n",
119 candidate.node->id(), candidate.calls, 122 candidate.node->id(), candidate.calls,
120 candidate.function->shared()->SourceSize(), 123 candidate.function->shared()->SourceSize(),
121 candidate.function->shared()->ast_node_count(), 124 candidate.function->shared()->ast_node_count(),
122 candidate.function->shared()->DebugName()->ToCString().get()); 125 candidate.function->shared()->DebugName()->ToCString().get());
123 } 126 }
124 } 127 }
125 128
126 } // namespace compiler 129 } // namespace compiler
127 } // namespace internal 130 } // namespace internal
128 } // namespace v8 131 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-inlining.cc ('k') | src/compiler/js-operator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698