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-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 private: | 85 private: |
86 Node* node_; | 86 Node* node_; |
87 }; | 87 }; |
88 | 88 |
89 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph) | 89 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph) |
90 : AdvancedReducer(editor), | 90 : AdvancedReducer(editor), |
91 jsgraph_(jsgraph), | 91 jsgraph_(jsgraph), |
92 type_cache_(TypeCache::Get()) {} | 92 type_cache_(TypeCache::Get()) {} |
93 | 93 |
94 // ECMA-262, section 15.8.2.11. | 94 // ES6 section 20.2.2.6 Math.atan ( x ) |
95 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { | 95 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { |
96 JSCallReduction r(node); | 96 JSCallReduction r(node); |
97 if (r.InputsMatchZero()) { | 97 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
98 // Math.max() -> -Infinity | 98 // Math.atan(a:plain-primitive) -> NumberAtan(ToNumber(a)) |
99 return Replace(jsgraph()->Constant(-V8_INFINITY)); | 99 Node* input = ToNumber(r.GetJSCallInput(0)); |
100 } | 100 Node* value = graph()->NewNode(simplified()->NumberAtan(), input); |
101 if (r.InputsMatchOne(Type::Number())) { | |
102 // Math.max(a:number) -> a | |
103 return Replace(r.left()); | |
104 } | |
105 if (r.InputsMatchAll(Type::Integral32())) { | |
106 // Math.max(a:int32, b:int32, ...) | |
107 Node* value = r.GetJSCallInput(0); | |
108 for (int i = 1; i < r.GetJSCallArity(); i++) { | |
109 Node* const input = r.GetJSCallInput(i); | |
110 value = graph()->NewNode( | |
111 common()->Select(MachineRepresentation::kNone), | |
112 graph()->NewNode(simplified()->NumberLessThan(), input, value), value, | |
113 input); | |
114 } | |
115 return Replace(value); | 101 return Replace(value); |
116 } | 102 } |
117 return NoChange(); | 103 return NoChange(); |
118 } | 104 } |
119 | 105 |
120 // ES6 section 20.2.2.19 Math.imul ( x, y ) | 106 // ES6 section 20.2.2.8 Math.atan2 ( y, x ) |
121 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { | 107 Reduction JSBuiltinReducer::ReduceMathAtan2(Node* node) { |
122 JSCallReduction r(node); | 108 JSCallReduction r(node); |
123 if (r.InputsMatchTwo(Type::Number(), Type::Number())) { | 109 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { |
124 // Math.imul(a:number, b:number) -> NumberImul(NumberToUint32(a), | 110 // Math.atan2(a:plain-primitive, |
125 // NumberToUint32(b)) | 111 // b:plain-primitive) -> NumberAtan2(ToNumber(a), |
126 Node* a = graph()->NewNode(simplified()->NumberToUint32(), r.left()); | 112 // ToNumber(b)) |
127 Node* b = graph()->NewNode(simplified()->NumberToUint32(), r.right()); | 113 Node* left = ToNumber(r.left()); |
128 Node* value = graph()->NewNode(simplified()->NumberImul(), a, b); | 114 Node* right = ToNumber(r.right()); |
| 115 Node* value = graph()->NewNode(simplified()->NumberAtan2(), left, right); |
129 return Replace(value); | 116 return Replace(value); |
130 } | 117 } |
131 return NoChange(); | 118 return NoChange(); |
132 } | 119 } |
133 | 120 |
134 // ES6 section 20.2.2.10 Math.ceil ( x ) | 121 // ES6 section 20.2.2.10 Math.ceil ( x ) |
135 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { | 122 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { |
136 JSCallReduction r(node); | 123 JSCallReduction r(node); |
137 if (r.InputsMatchOne(Type::Number())) { | 124 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
138 // Math.ceil(a:number) -> NumberCeil(a) | 125 // Math.ceil(a:plain-primitive) -> NumberCeil(ToNumber(a)) |
139 Node* value = graph()->NewNode(simplified()->NumberCeil(), r.left()); | 126 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 127 Node* value = graph()->NewNode(simplified()->NumberCeil(), input); |
140 return Replace(value); | 128 return Replace(value); |
141 } | 129 } |
142 return NoChange(); | 130 return NoChange(); |
143 } | 131 } |
144 | 132 |
145 // ES6 section 20.2.2.11 Math.clz32 ( x ) | 133 // ES6 section 20.2.2.11 Math.clz32 ( x ) |
146 Reduction JSBuiltinReducer::ReduceMathClz32(Node* node) { | 134 Reduction JSBuiltinReducer::ReduceMathClz32(Node* node) { |
147 JSCallReduction r(node); | 135 JSCallReduction r(node); |
148 if (r.InputsMatchOne(Type::Unsigned32())) { | 136 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
149 // Math.clz32(a:unsigned32) -> NumberClz32(a) | 137 // Math.clz32(a:plain-primitive) -> NumberClz32(ToUint32(a)) |
150 Node* value = graph()->NewNode(simplified()->NumberClz32(), r.left()); | 138 Node* input = ToUint32(r.GetJSCallInput(0)); |
151 return Replace(value); | 139 Node* value = graph()->NewNode(simplified()->NumberClz32(), input); |
152 } | |
153 if (r.InputsMatchOne(Type::Number())) { | |
154 // Math.clz32(a:number) -> NumberClz32(NumberToUint32(a)) | |
155 Node* value = graph()->NewNode( | |
156 simplified()->NumberClz32(), | |
157 graph()->NewNode(simplified()->NumberToUint32(), r.left())); | |
158 return Replace(value); | 140 return Replace(value); |
159 } | 141 } |
160 return NoChange(); | 142 return NoChange(); |
161 } | 143 } |
162 | 144 |
163 // ES6 draft 08-24-14, section 20.2.2.16. | 145 // ES6 section 20.2.2.16 Math.floor ( x ) |
164 Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) { | 146 Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) { |
165 JSCallReduction r(node); | 147 JSCallReduction r(node); |
166 if (r.InputsMatchOne(Type::Number())) { | 148 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
167 // Math.floor(a:number) -> NumberFloor(a) | 149 // Math.floor(a:plain-primitive) -> NumberFloor(ToNumber(a)) |
168 Node* value = graph()->NewNode(simplified()->NumberFloor(), r.left()); | 150 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 151 Node* value = graph()->NewNode(simplified()->NumberFloor(), input); |
169 return Replace(value); | 152 return Replace(value); |
170 } | 153 } |
171 return NoChange(); | 154 return NoChange(); |
172 } | 155 } |
173 | 156 |
174 // ES6 draft 08-24-14, section 20.2.2.17. | 157 // ES6 section 20.2.2.17 Math.fround ( x ) |
175 Reduction JSBuiltinReducer::ReduceMathFround(Node* node) { | 158 Reduction JSBuiltinReducer::ReduceMathFround(Node* node) { |
176 JSCallReduction r(node); | 159 JSCallReduction r(node); |
177 if (r.InputsMatchOne(Type::NumberOrUndefined())) { | 160 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
178 // Math.fround(a:number) -> TruncateFloat64ToFloat32(a) | 161 // Math.fround(a:plain-primitive) -> NumberFround(ToNumber(a)) |
179 Node* value = | 162 Node* input = ToNumber(r.GetJSCallInput(0)); |
180 graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left()); | 163 Node* value = graph()->NewNode(simplified()->NumberFround(), input); |
181 return Replace(value); | 164 return Replace(value); |
182 } | 165 } |
183 return NoChange(); | 166 return NoChange(); |
184 } | 167 } |
185 | 168 |
186 // ES6 section 20.2.2.6 Math.atan ( x ) | 169 // ES6 section 20.2.2.19 Math.imul ( x, y ) |
187 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { | 170 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { |
188 JSCallReduction r(node); | 171 JSCallReduction r(node); |
189 if (r.InputsMatchOne(Type::Number())) { | 172 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { |
190 // Math.atan(a:number) -> NumberAtan(a) | 173 // Math.imul(a:plain-primitive, |
191 Node* value = graph()->NewNode(simplified()->NumberAtan(), r.left()); | 174 // b:plain-primitive) -> NumberImul(ToUint32(a), |
192 return Replace(value); | 175 // ToUint32(b)) |
193 } | 176 Node* left = ToUint32(r.left()); |
194 return NoChange(); | 177 Node* right = ToUint32(r.right()); |
195 } | 178 Node* value = graph()->NewNode(simplified()->NumberImul(), left, right); |
196 | |
197 // ES6 section 20.2.2.8 Math.atan2 ( y, x ) | |
198 Reduction JSBuiltinReducer::ReduceMathAtan2(Node* node) { | |
199 JSCallReduction r(node); | |
200 if (r.InputsMatchTwo(Type::Number(), Type::Number())) { | |
201 // Math.atan2(a:number, b:number) -> NumberAtan2(a, b) | |
202 Node* value = | |
203 graph()->NewNode(simplified()->NumberAtan2(), r.left(), r.right()); | |
204 return Replace(value); | 179 return Replace(value); |
205 } | 180 } |
206 return NoChange(); | 181 return NoChange(); |
207 } | 182 } |
208 | 183 |
209 // ES6 section 20.2.2.20 Math.log ( x ) | 184 // ES6 section 20.2.2.20 Math.log ( x ) |
210 Reduction JSBuiltinReducer::ReduceMathLog(Node* node) { | 185 Reduction JSBuiltinReducer::ReduceMathLog(Node* node) { |
211 JSCallReduction r(node); | 186 JSCallReduction r(node); |
212 if (r.InputsMatchOne(Type::Number())) { | 187 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
213 // Math.log(a:number) -> NumberLog(a) | 188 // Math.log(a:plain-primitive) -> NumberLog(ToNumber(a)) |
214 Node* value = graph()->NewNode(simplified()->NumberLog(), r.left()); | 189 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 190 Node* value = graph()->NewNode(simplified()->NumberLog(), input); |
215 return Replace(value); | 191 return Replace(value); |
216 } | 192 } |
217 return NoChange(); | 193 return NoChange(); |
218 } | 194 } |
219 | 195 |
220 // ES6 section 20.2.2.21 Math.log1p ( x ) | 196 // ES6 section 20.2.2.21 Math.log1p ( x ) |
221 Reduction JSBuiltinReducer::ReduceMathLog1p(Node* node) { | 197 Reduction JSBuiltinReducer::ReduceMathLog1p(Node* node) { |
222 JSCallReduction r(node); | 198 JSCallReduction r(node); |
223 if (r.InputsMatchOne(Type::Number())) { | 199 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
224 // Math.log1p(a:number) -> NumberLog1p(a) | 200 // Math.log1p(a:plain-primitive) -> NumberLog1p(ToNumber(a)) |
225 Node* value = graph()->NewNode(simplified()->NumberLog1p(), r.left()); | 201 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 202 Node* value = graph()->NewNode(simplified()->NumberLog1p(), input); |
226 return Replace(value); | 203 return Replace(value); |
227 } | 204 } |
228 return NoChange(); | 205 return NoChange(); |
| 206 } |
| 207 |
| 208 // ES6 section 20.2.2.24 Math.max ( value1, value2, ...values ) |
| 209 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { |
| 210 JSCallReduction r(node); |
| 211 if (r.InputsMatchZero()) { |
| 212 // Math.max() -> -Infinity |
| 213 return Replace(jsgraph()->Constant(-V8_INFINITY)); |
| 214 } |
| 215 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 216 // Math.max(a:plain-primitive) -> ToNumber(a) |
| 217 Node* value = ToNumber(r.GetJSCallInput(0)); |
| 218 return Replace(value); |
| 219 } |
| 220 if (r.InputsMatchAll(Type::Integral32())) { |
| 221 // Math.max(a:int32, b:int32, ...) |
| 222 Node* value = r.GetJSCallInput(0); |
| 223 for (int i = 1; i < r.GetJSCallArity(); i++) { |
| 224 Node* const input = r.GetJSCallInput(i); |
| 225 value = graph()->NewNode( |
| 226 common()->Select(MachineRepresentation::kNone), |
| 227 graph()->NewNode(simplified()->NumberLessThan(), input, value), value, |
| 228 input); |
| 229 } |
| 230 return Replace(value); |
| 231 } |
| 232 return NoChange(); |
| 233 } |
| 234 |
| 235 // ES6 section 20.2.2.25 Math.min ( value1, value2, ...values ) |
| 236 Reduction JSBuiltinReducer::ReduceMathMin(Node* node) { |
| 237 JSCallReduction r(node); |
| 238 if (r.InputsMatchZero()) { |
| 239 // Math.min() -> Infinity |
| 240 return Replace(jsgraph()->Constant(V8_INFINITY)); |
| 241 } |
| 242 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 243 // Math.min(a:plain-primitive) -> ToNumber(a) |
| 244 Node* value = ToNumber(r.GetJSCallInput(0)); |
| 245 return Replace(value); |
| 246 } |
| 247 if (r.InputsMatchAll(Type::Integral32())) { |
| 248 // Math.min(a:int32, b:int32, ...) |
| 249 Node* value = r.GetJSCallInput(0); |
| 250 for (int i = 1; i < r.GetJSCallArity(); i++) { |
| 251 Node* const input = r.GetJSCallInput(i); |
| 252 value = graph()->NewNode( |
| 253 common()->Select(MachineRepresentation::kNone), |
| 254 graph()->NewNode(simplified()->NumberLessThan(), input, value), input, |
| 255 value); |
| 256 } |
| 257 return Replace(value); |
| 258 } |
| 259 return NoChange(); |
229 } | 260 } |
230 | 261 |
231 // ES6 section 20.2.2.28 Math.round ( x ) | 262 // ES6 section 20.2.2.28 Math.round ( x ) |
232 Reduction JSBuiltinReducer::ReduceMathRound(Node* node) { | 263 Reduction JSBuiltinReducer::ReduceMathRound(Node* node) { |
233 JSCallReduction r(node); | 264 JSCallReduction r(node); |
234 if (r.InputsMatchOne(Type::Number())) { | 265 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
235 // Math.round(a:number) -> NumberRound(a) | 266 // Math.round(a:plain-primitive) -> NumberRound(ToNumber(a)) |
236 Node* value = graph()->NewNode(simplified()->NumberRound(), r.left()); | 267 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 268 Node* value = graph()->NewNode(simplified()->NumberRound(), input); |
237 return Replace(value); | 269 return Replace(value); |
238 } | 270 } |
239 return NoChange(); | 271 return NoChange(); |
240 } | 272 } |
241 | 273 |
242 // ES6 section 20.2.2.32 Math.sqrt ( x ) | 274 // ES6 section 20.2.2.32 Math.sqrt ( x ) |
243 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { | 275 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { |
244 JSCallReduction r(node); | 276 JSCallReduction r(node); |
245 if (r.InputsMatchOne(Type::Number())) { | 277 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
246 // Math.sqrt(a:number) -> Float64Sqrt(a) | 278 // Math.sqrt(a:plain-primitive) -> NumberSqrt(ToNumber(a)) |
247 Node* value = graph()->NewNode(machine()->Float64Sqrt(), r.left()); | 279 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 280 Node* value = graph()->NewNode(simplified()->NumberSqrt(), input); |
248 return Replace(value); | 281 return Replace(value); |
249 } | 282 } |
250 return NoChange(); | 283 return NoChange(); |
251 } | 284 } |
252 | 285 |
253 // ES6 section 20.2.2.35 Math.trunc ( x ) | 286 // ES6 section 20.2.2.35 Math.trunc ( x ) |
254 Reduction JSBuiltinReducer::ReduceMathTrunc(Node* node) { | 287 Reduction JSBuiltinReducer::ReduceMathTrunc(Node* node) { |
255 JSCallReduction r(node); | 288 JSCallReduction r(node); |
256 if (r.InputsMatchOne(Type::Number())) { | 289 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
257 // Math.trunc(a:number) -> NumberTrunc(a) | 290 // Math.trunc(a:plain-primitive) -> NumberTrunc(ToNumber(a)) |
258 Node* value = graph()->NewNode(simplified()->NumberTrunc(), r.left()); | 291 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 292 Node* value = graph()->NewNode(simplified()->NumberTrunc(), input); |
259 return Replace(value); | 293 return Replace(value); |
260 } | 294 } |
261 return NoChange(); | 295 return NoChange(); |
262 } | 296 } |
263 | 297 |
264 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) | 298 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) |
265 Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) { | 299 Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) { |
266 JSCallReduction r(node); | 300 JSCallReduction r(node); |
267 if (r.InputsMatchOne(Type::Number())) { | 301 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
268 // String.fromCharCode(a:number) -> StringFromCharCode(a) | 302 // String.fromCharCode(a:plain-primitive) -> StringFromCharCode(a) |
269 Node* value = | 303 Node* input = ToNumber(r.GetJSCallInput(0)); |
270 graph()->NewNode(simplified()->StringFromCharCode(), r.left()); | 304 Node* value = graph()->NewNode(simplified()->StringFromCharCode(), input); |
271 return Replace(value); | 305 return Replace(value); |
272 } | 306 } |
273 return NoChange(); | 307 return NoChange(); |
274 } | 308 } |
275 | 309 |
276 Reduction JSBuiltinReducer::Reduce(Node* node) { | 310 Reduction JSBuiltinReducer::Reduce(Node* node) { |
277 Reduction reduction = NoChange(); | 311 Reduction reduction = NoChange(); |
278 JSCallReduction r(node); | 312 JSCallReduction r(node); |
279 | 313 |
280 // Dispatch according to the BuiltinFunctionId if present. | 314 // Dispatch according to the BuiltinFunctionId if present. |
281 if (!r.HasBuiltinFunctionId()) return NoChange(); | 315 if (!r.HasBuiltinFunctionId()) return NoChange(); |
282 switch (r.GetBuiltinFunctionId()) { | 316 switch (r.GetBuiltinFunctionId()) { |
283 case kMathMax: | 317 case kMathAtan: |
284 reduction = ReduceMathMax(node); | 318 reduction = ReduceMathAtan(node); |
285 break; | 319 break; |
286 case kMathImul: | 320 case kMathAtan2: |
287 reduction = ReduceMathImul(node); | 321 reduction = ReduceMathAtan2(node); |
288 break; | 322 break; |
289 case kMathClz32: | 323 case kMathClz32: |
290 reduction = ReduceMathClz32(node); | 324 reduction = ReduceMathClz32(node); |
291 break; | 325 break; |
292 case kMathCeil: | 326 case kMathCeil: |
293 reduction = ReduceMathCeil(node); | 327 reduction = ReduceMathCeil(node); |
294 break; | 328 break; |
295 case kMathFloor: | 329 case kMathFloor: |
296 reduction = ReduceMathFloor(node); | 330 reduction = ReduceMathFloor(node); |
297 break; | 331 break; |
298 case kMathFround: | 332 case kMathFround: |
299 reduction = ReduceMathFround(node); | 333 reduction = ReduceMathFround(node); |
300 break; | 334 break; |
301 case kMathAtan: | 335 case kMathImul: |
302 reduction = ReduceMathAtan(node); | 336 reduction = ReduceMathImul(node); |
303 break; | |
304 case kMathAtan2: | |
305 reduction = ReduceMathAtan2(node); | |
306 break; | 337 break; |
307 case kMathLog: | 338 case kMathLog: |
308 reduction = ReduceMathLog(node); | 339 reduction = ReduceMathLog(node); |
309 break; | 340 break; |
310 case kMathLog1p: | 341 case kMathLog1p: |
311 reduction = ReduceMathLog1p(node); | 342 reduction = ReduceMathLog1p(node); |
312 break; | 343 break; |
| 344 case kMathMax: |
| 345 reduction = ReduceMathMax(node); |
| 346 break; |
| 347 case kMathMin: |
| 348 reduction = ReduceMathMin(node); |
| 349 break; |
313 case kMathRound: | 350 case kMathRound: |
314 reduction = ReduceMathRound(node); | 351 reduction = ReduceMathRound(node); |
315 break; | 352 break; |
316 case kMathSqrt: | 353 case kMathSqrt: |
317 reduction = ReduceMathSqrt(node); | 354 reduction = ReduceMathSqrt(node); |
318 break; | 355 break; |
319 case kMathTrunc: | 356 case kMathTrunc: |
320 reduction = ReduceMathTrunc(node); | 357 reduction = ReduceMathTrunc(node); |
321 break; | 358 break; |
322 case kStringFromCharCode: | 359 case kStringFromCharCode: |
323 reduction = ReduceStringFromCharCode(node); | 360 reduction = ReduceStringFromCharCode(node); |
324 break; | 361 break; |
325 default: | 362 default: |
326 break; | 363 break; |
327 } | 364 } |
328 | 365 |
329 // Replace builtin call assuming replacement nodes are pure values that don't | 366 // Replace builtin call assuming replacement nodes are pure values that don't |
330 // produce an effect. Replaces {node} with {reduction} and relaxes effects. | 367 // produce an effect. Replaces {node} with {reduction} and relaxes effects. |
331 if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement()); | 368 if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement()); |
332 | 369 |
333 return reduction; | 370 return reduction; |
334 } | 371 } |
335 | 372 |
| 373 Node* JSBuiltinReducer::ToNumber(Node* input) { |
| 374 Type* input_type = NodeProperties::GetType(input); |
| 375 if (input_type->Is(Type::Number())) return input; |
| 376 return graph()->NewNode(simplified()->PlainPrimitiveToNumber(), input); |
| 377 } |
| 378 |
| 379 Node* JSBuiltinReducer::ToUint32(Node* input) { |
| 380 input = ToNumber(input); |
| 381 Type* input_type = NodeProperties::GetType(input); |
| 382 if (input_type->Is(Type::Unsigned32())) return input; |
| 383 return graph()->NewNode(simplified()->NumberToUint32(), input); |
| 384 } |
336 | 385 |
337 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } | 386 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } |
338 | 387 |
339 | 388 |
340 Isolate* JSBuiltinReducer::isolate() const { return jsgraph()->isolate(); } | 389 Isolate* JSBuiltinReducer::isolate() const { return jsgraph()->isolate(); } |
341 | 390 |
342 | 391 |
343 CommonOperatorBuilder* JSBuiltinReducer::common() const { | 392 CommonOperatorBuilder* JSBuiltinReducer::common() const { |
344 return jsgraph()->common(); | 393 return jsgraph()->common(); |
345 } | 394 } |
346 | 395 |
347 | 396 |
348 MachineOperatorBuilder* JSBuiltinReducer::machine() const { | |
349 return jsgraph()->machine(); | |
350 } | |
351 | |
352 | |
353 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 397 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
354 return jsgraph()->simplified(); | 398 return jsgraph()->simplified(); |
355 } | 399 } |
356 | 400 |
357 } // namespace compiler | 401 } // namespace compiler |
358 } // namespace internal | 402 } // namespace internal |
359 } // namespace v8 | 403 } // namespace v8 |
OLD | NEW |