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

Side by Side Diff: src/compiler/js-builtin-reducer.cc

Issue 1439533002: [turbofan] Add support to lower Function.prototype.call. (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
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | no next file » | 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/diamond.h" 5 #include "src/compiler/diamond.h"
6 #include "src/compiler/js-builtin-reducer.h" 6 #include "src/compiler/js-builtin-reducer.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "src/compiler/simplified-operator.h" 10 #include "src/compiler/simplified-operator.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 private: 85 private:
86 Node* node_; 86 Node* node_;
87 }; 87 };
88 88
89 89
90 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph) 90 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph)
91 : AdvancedReducer(editor), jsgraph_(jsgraph) {} 91 : AdvancedReducer(editor), jsgraph_(jsgraph) {}
92 92
93 93
94 // ES6 section 19.2.3.3 Function.prototype.call (thisArg, ...args)
95 Reduction JSBuiltinReducer::ReduceFunctionCall(Node* node) {
96 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode());
97 CallFunctionParameters const& p = CallFunctionParametersOf(node->op());
98 Handle<JSFunction> apply = Handle<JSFunction>::cast(
99 HeapObjectMatcher(NodeProperties::GetValueInput(node, 0)).Value());
100 // Change context of {node} to the Function.prototype.call context,
101 // to ensure any exception is thrown in the correct context.
102 NodeProperties::ReplaceContextInput(
103 node, jsgraph()->HeapConstant(handle(apply->context(), isolate())));
104 // Remove the target from {node} and use the receiver as target instead, and
105 // the thisArg becomes the new target. If thisArg was not provided, insert
106 // undefined instead.
107 size_t arity = p.arity();
108 DCHECK_LE(2u, arity);
109 ConvertReceiverMode convert_mode;
110 if (arity == 2) {
111 // The thisArg was not provided, use undefined as receiver.
112 convert_mode = ConvertReceiverMode::kNullOrUndefined;
113 node->ReplaceInput(0, node->InputAt(1));
114 node->ReplaceInput(1, jsgraph()->UndefinedConstant());
115 } else {
116 // Just remove the target, which is the first value input.
117 convert_mode = ConvertReceiverMode::kAny;
118 node->RemoveInput(0);
119 --arity;
120 }
121 // TODO(turbofan): Migrate the call count to the new operator?
122 NodeProperties::ChangeOp(node, javascript()->CallFunction(
123 arity, p.language_mode(), VectorSlotPair(),
124 convert_mode, p.tail_call_mode()));
125 return Changed(node);
126 }
127
128
94 // ECMA-262, section 15.8.2.11. 129 // ECMA-262, section 15.8.2.11.
95 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { 130 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
96 JSCallReduction r(node); 131 JSCallReduction r(node);
97 if (r.InputsMatchZero()) { 132 if (r.InputsMatchZero()) {
98 // Math.max() -> -Infinity 133 // Math.max() -> -Infinity
99 return Replace(jsgraph()->Constant(-V8_INFINITY)); 134 return Replace(jsgraph()->Constant(-V8_INFINITY));
100 } 135 }
101 if (r.InputsMatchOne(Type::Number())) { 136 if (r.InputsMatchOne(Type::Number())) {
102 // Math.max(a:number) -> a 137 // Math.max(a:number) -> a
103 return Replace(r.left()); 138 return Replace(r.left());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 178 }
144 179
145 180
146 Reduction JSBuiltinReducer::Reduce(Node* node) { 181 Reduction JSBuiltinReducer::Reduce(Node* node) {
147 Reduction reduction = NoChange(); 182 Reduction reduction = NoChange();
148 JSCallReduction r(node); 183 JSCallReduction r(node);
149 184
150 // Dispatch according to the BuiltinFunctionId if present. 185 // Dispatch according to the BuiltinFunctionId if present.
151 if (!r.HasBuiltinFunctionId()) return NoChange(); 186 if (!r.HasBuiltinFunctionId()) return NoChange();
152 switch (r.GetBuiltinFunctionId()) { 187 switch (r.GetBuiltinFunctionId()) {
188 case kFunctionCall:
189 return ReduceFunctionCall(node);
153 case kMathMax: 190 case kMathMax:
154 reduction = ReduceMathMax(node); 191 reduction = ReduceMathMax(node);
155 break; 192 break;
156 case kMathImul: 193 case kMathImul:
157 reduction = ReduceMathImul(node); 194 reduction = ReduceMathImul(node);
158 break; 195 break;
159 case kMathFround: 196 case kMathFround:
160 reduction = ReduceMathFround(node); 197 reduction = ReduceMathFround(node);
161 break; 198 break;
162 default: 199 default:
163 break; 200 break;
164 } 201 }
165 202
166 // Replace builtin call assuming replacement nodes are pure values that don't 203 // Replace builtin call assuming replacement nodes are pure values that don't
167 // produce an effect. Replaces {node} with {reduction} and relaxes effects. 204 // produce an effect. Replaces {node} with {reduction} and relaxes effects.
168 if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement()); 205 if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement());
169 206
170 return reduction; 207 return reduction;
171 } 208 }
172 209
173 210
174 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } 211 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); }
175 212
176 213
214 Isolate* JSBuiltinReducer::isolate() const { return jsgraph()->isolate(); }
215
216
177 CommonOperatorBuilder* JSBuiltinReducer::common() const { 217 CommonOperatorBuilder* JSBuiltinReducer::common() const {
178 return jsgraph()->common(); 218 return jsgraph()->common();
179 } 219 }
180 220
181 221
182 MachineOperatorBuilder* JSBuiltinReducer::machine() const { 222 MachineOperatorBuilder* JSBuiltinReducer::machine() const {
183 return jsgraph()->machine(); 223 return jsgraph()->machine();
184 } 224 }
185 225
186 226
187 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { 227 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const {
188 return jsgraph()->simplified(); 228 return jsgraph()->simplified();
189 } 229 }
190 230
231
232 JSOperatorBuilder* JSBuiltinReducer::javascript() const {
233 return jsgraph()->javascript();
234 }
235
191 } // namespace compiler 236 } // namespace compiler
192 } // namespace internal 237 } // namespace internal
193 } // namespace v8 238 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698