| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 JSCallReduction r(node); | 146 JSCallReduction r(node); |
| 147 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 147 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 148 // Math.clz32(a:plain-primitive) -> NumberClz32(ToUint32(a)) | 148 // Math.clz32(a:plain-primitive) -> NumberClz32(ToUint32(a)) |
| 149 Node* input = ToUint32(r.GetJSCallInput(0)); | 149 Node* input = ToUint32(r.GetJSCallInput(0)); |
| 150 Node* value = graph()->NewNode(simplified()->NumberClz32(), input); | 150 Node* value = graph()->NewNode(simplified()->NumberClz32(), input); |
| 151 return Replace(value); | 151 return Replace(value); |
| 152 } | 152 } |
| 153 return NoChange(); | 153 return NoChange(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // ES6 section 20.2.2.12 Math.cos ( x ) |
| 157 Reduction JSBuiltinReducer::ReduceMathCos(Node* node) { |
| 158 JSCallReduction r(node); |
| 159 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 160 // Math.cos(a:plain-primitive) -> NumberCos(ToNumber(a)) |
| 161 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 162 Node* value = graph()->NewNode(simplified()->NumberCos(), input); |
| 163 return Replace(value); |
| 164 } |
| 165 return NoChange(); |
| 166 } |
| 167 |
| 156 // ES6 section 20.2.2.14 Math.exp ( x ) | 168 // ES6 section 20.2.2.14 Math.exp ( x ) |
| 157 Reduction JSBuiltinReducer::ReduceMathExp(Node* node) { | 169 Reduction JSBuiltinReducer::ReduceMathExp(Node* node) { |
| 158 JSCallReduction r(node); | 170 JSCallReduction r(node); |
| 159 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 171 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 160 // Math.exp(a:plain-primitive) -> NumberExp(ToNumber(a)) | 172 // Math.exp(a:plain-primitive) -> NumberExp(ToNumber(a)) |
| 161 Node* input = ToNumber(r.GetJSCallInput(0)); | 173 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 162 Node* value = graph()->NewNode(simplified()->NumberExp(), input); | 174 Node* value = graph()->NewNode(simplified()->NumberExp(), input); |
| 163 return Replace(value); | 175 return Replace(value); |
| 164 } | 176 } |
| 165 return NoChange(); | 177 return NoChange(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 JSCallReduction r(node); | 244 JSCallReduction r(node); |
| 233 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 245 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 234 // Math.log1p(a:plain-primitive) -> NumberLog1p(ToNumber(a)) | 246 // Math.log1p(a:plain-primitive) -> NumberLog1p(ToNumber(a)) |
| 235 Node* input = ToNumber(r.GetJSCallInput(0)); | 247 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 236 Node* value = graph()->NewNode(simplified()->NumberLog1p(), input); | 248 Node* value = graph()->NewNode(simplified()->NumberLog1p(), input); |
| 237 return Replace(value); | 249 return Replace(value); |
| 238 } | 250 } |
| 239 return NoChange(); | 251 return NoChange(); |
| 240 } | 252 } |
| 241 | 253 |
| 254 // ES6 section 20.2.2.22 Math.log10 ( x ) |
| 255 Reduction JSBuiltinReducer::ReduceMathLog10(Node* node) { |
| 256 JSCallReduction r(node); |
| 257 if (r.InputsMatchOne(Type::Number())) { |
| 258 // Math.log10(a:number) -> NumberLog10(a) |
| 259 Node* value = graph()->NewNode(simplified()->NumberLog10(), r.left()); |
| 260 return Replace(value); |
| 261 } |
| 262 return NoChange(); |
| 263 } |
| 264 |
| 265 // ES6 section 20.2.2.23 Math.log2 ( x ) |
| 266 Reduction JSBuiltinReducer::ReduceMathLog2(Node* node) { |
| 267 JSCallReduction r(node); |
| 268 if (r.InputsMatchOne(Type::Number())) { |
| 269 // Math.log2(a:number) -> NumberLog(a) |
| 270 Node* value = graph()->NewNode(simplified()->NumberLog2(), r.left()); |
| 271 return Replace(value); |
| 272 } |
| 273 return NoChange(); |
| 274 } |
| 275 |
| 242 // ES6 section 20.2.2.24 Math.max ( value1, value2, ...values ) | 276 // ES6 section 20.2.2.24 Math.max ( value1, value2, ...values ) |
| 243 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { | 277 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { |
| 244 JSCallReduction r(node); | 278 JSCallReduction r(node); |
| 245 if (r.InputsMatchZero()) { | 279 if (r.InputsMatchZero()) { |
| 246 // Math.max() -> -Infinity | 280 // Math.max() -> -Infinity |
| 247 return Replace(jsgraph()->Constant(-V8_INFINITY)); | 281 return Replace(jsgraph()->Constant(-V8_INFINITY)); |
| 248 } | 282 } |
| 249 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 283 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 250 // Math.max(a:plain-primitive) -> ToNumber(a) | 284 // Math.max(a:plain-primitive) -> ToNumber(a) |
| 251 Node* value = ToNumber(r.GetJSCallInput(0)); | 285 Node* value = ToNumber(r.GetJSCallInput(0)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 value = graph()->NewNode( | 320 value = graph()->NewNode( |
| 287 common()->Select(MachineRepresentation::kNone), | 321 common()->Select(MachineRepresentation::kNone), |
| 288 graph()->NewNode(simplified()->NumberLessThan(), input, value), input, | 322 graph()->NewNode(simplified()->NumberLessThan(), input, value), input, |
| 289 value); | 323 value); |
| 290 } | 324 } |
| 291 return Replace(value); | 325 return Replace(value); |
| 292 } | 326 } |
| 293 return NoChange(); | 327 return NoChange(); |
| 294 } | 328 } |
| 295 | 329 |
| 296 // ES6 section 20.2.2.23 Math.log2 ( x ) | 330 // ES6 section 20.2.2.28 Math.round ( x ) |
| 297 Reduction JSBuiltinReducer::ReduceMathLog2(Node* node) { | 331 Reduction JSBuiltinReducer::ReduceMathRound(Node* node) { |
| 298 JSCallReduction r(node); | 332 JSCallReduction r(node); |
| 299 if (r.InputsMatchOne(Type::Number())) { | 333 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 300 // Math.log2(a:number) -> NumberLog(a) | 334 // Math.round(a:plain-primitive) -> NumberRound(ToNumber(a)) |
| 301 Node* value = graph()->NewNode(simplified()->NumberLog2(), r.left()); | 335 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 336 Node* value = graph()->NewNode(simplified()->NumberRound(), input); |
| 302 return Replace(value); | 337 return Replace(value); |
| 303 } | 338 } |
| 304 return NoChange(); | 339 return NoChange(); |
| 305 } | |
| 306 | |
| 307 // ES6 section 20.2.2.22 Math.log10 ( x ) | |
| 308 Reduction JSBuiltinReducer::ReduceMathLog10(Node* node) { | |
| 309 JSCallReduction r(node); | |
| 310 if (r.InputsMatchOne(Type::Number())) { | |
| 311 // Math.log10(a:number) -> NumberLog10(a) | |
| 312 Node* value = graph()->NewNode(simplified()->NumberLog10(), r.left()); | |
| 313 return Replace(value); | |
| 314 } | |
| 315 return NoChange(); | |
| 316 } | 340 } |
| 317 | 341 |
| 318 // ES6 section 20.2.2.9 Math.cbrt ( x ) | 342 // ES6 section 20.2.2.9 Math.cbrt ( x ) |
| 319 Reduction JSBuiltinReducer::ReduceMathCbrt(Node* node) { | 343 Reduction JSBuiltinReducer::ReduceMathCbrt(Node* node) { |
| 320 JSCallReduction r(node); | 344 JSCallReduction r(node); |
| 321 if (r.InputsMatchOne(Type::Number())) { | 345 if (r.InputsMatchOne(Type::Number())) { |
| 322 // Math.cbrt(a:number) -> NumberCbrt(a) | 346 // Math.cbrt(a:number) -> NumberCbrt(a) |
| 323 Node* value = graph()->NewNode(simplified()->NumberCbrt(), r.left()); | 347 Node* value = graph()->NewNode(simplified()->NumberCbrt(), r.left()); |
| 324 return Replace(value); | 348 return Replace(value); |
| 325 } | 349 } |
| 326 return NoChange(); | 350 return NoChange(); |
| 327 } | 351 } |
| 328 | 352 |
| 329 // ES6 section 20.2.2.28 Math.round ( x ) | 353 // ES6 section 20.2.2.30 Math.sin ( x ) |
| 330 Reduction JSBuiltinReducer::ReduceMathRound(Node* node) { | 354 Reduction JSBuiltinReducer::ReduceMathSin(Node* node) { |
| 331 JSCallReduction r(node); | 355 JSCallReduction r(node); |
| 332 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 356 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 333 // Math.round(a:plain-primitive) -> NumberRound(ToNumber(a)) | 357 // Math.sin(a:plain-primitive) -> NumberSin(ToNumber(a)) |
| 334 Node* input = ToNumber(r.GetJSCallInput(0)); | 358 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 335 Node* value = graph()->NewNode(simplified()->NumberRound(), input); | 359 Node* value = graph()->NewNode(simplified()->NumberSin(), input); |
| 336 return Replace(value); | 360 return Replace(value); |
| 337 } | 361 } |
| 338 return NoChange(); | 362 return NoChange(); |
| 339 } | 363 } |
| 340 | 364 |
| 341 // ES6 section 20.2.2.32 Math.sqrt ( x ) | 365 // ES6 section 20.2.2.32 Math.sqrt ( x ) |
| 342 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { | 366 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { |
| 343 JSCallReduction r(node); | 367 JSCallReduction r(node); |
| 344 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 368 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 345 // Math.sqrt(a:plain-primitive) -> NumberSqrt(ToNumber(a)) | 369 // Math.sqrt(a:plain-primitive) -> NumberSqrt(ToNumber(a)) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 break; | 413 break; |
| 390 case kMathAtanh: | 414 case kMathAtanh: |
| 391 reduction = ReduceMathAtanh(node); | 415 reduction = ReduceMathAtanh(node); |
| 392 break; | 416 break; |
| 393 case kMathClz32: | 417 case kMathClz32: |
| 394 reduction = ReduceMathClz32(node); | 418 reduction = ReduceMathClz32(node); |
| 395 break; | 419 break; |
| 396 case kMathCeil: | 420 case kMathCeil: |
| 397 reduction = ReduceMathCeil(node); | 421 reduction = ReduceMathCeil(node); |
| 398 break; | 422 break; |
| 423 case kMathCos: |
| 424 reduction = ReduceMathCos(node); |
| 425 break; |
| 399 case kMathExp: | 426 case kMathExp: |
| 400 reduction = ReduceMathExp(node); | 427 reduction = ReduceMathExp(node); |
| 401 break; | 428 break; |
| 402 case kMathExpm1: | 429 case kMathExpm1: |
| 403 reduction = ReduceMathExpm1(node); | 430 reduction = ReduceMathExpm1(node); |
| 404 break; | 431 break; |
| 405 case kMathFloor: | 432 case kMathFloor: |
| 406 reduction = ReduceMathFloor(node); | 433 reduction = ReduceMathFloor(node); |
| 407 break; | 434 break; |
| 408 case kMathFround: | 435 case kMathFround: |
| 409 reduction = ReduceMathFround(node); | 436 reduction = ReduceMathFround(node); |
| 410 break; | 437 break; |
| 411 case kMathImul: | 438 case kMathImul: |
| 412 reduction = ReduceMathImul(node); | 439 reduction = ReduceMathImul(node); |
| 413 break; | 440 break; |
| 414 case kMathLog: | 441 case kMathLog: |
| 415 reduction = ReduceMathLog(node); | 442 reduction = ReduceMathLog(node); |
| 416 break; | 443 break; |
| 417 case kMathLog1p: | 444 case kMathLog1p: |
| 418 reduction = ReduceMathLog1p(node); | 445 reduction = ReduceMathLog1p(node); |
| 419 break; | 446 break; |
| 447 case kMathLog10: |
| 448 reduction = ReduceMathLog10(node); |
| 449 break; |
| 420 case kMathLog2: | 450 case kMathLog2: |
| 421 reduction = ReduceMathLog2(node); | 451 reduction = ReduceMathLog2(node); |
| 422 break; | 452 break; |
| 423 case kMathLog10: | |
| 424 reduction = ReduceMathLog10(node); | |
| 425 break; | |
| 426 case kMathMax: | 453 case kMathMax: |
| 427 reduction = ReduceMathMax(node); | 454 reduction = ReduceMathMax(node); |
| 428 break; | 455 break; |
| 429 case kMathMin: | 456 case kMathMin: |
| 430 reduction = ReduceMathMin(node); | 457 reduction = ReduceMathMin(node); |
| 431 break; | 458 break; |
| 432 case kMathCbrt: | 459 case kMathCbrt: |
| 433 reduction = ReduceMathCbrt(node); | 460 reduction = ReduceMathCbrt(node); |
| 434 break; | 461 break; |
| 435 case kMathRound: | 462 case kMathRound: |
| 436 reduction = ReduceMathRound(node); | 463 reduction = ReduceMathRound(node); |
| 437 break; | 464 break; |
| 465 case kMathSin: |
| 466 reduction = ReduceMathSin(node); |
| 467 break; |
| 438 case kMathSqrt: | 468 case kMathSqrt: |
| 439 reduction = ReduceMathSqrt(node); | 469 reduction = ReduceMathSqrt(node); |
| 440 break; | 470 break; |
| 441 case kMathTrunc: | 471 case kMathTrunc: |
| 442 reduction = ReduceMathTrunc(node); | 472 reduction = ReduceMathTrunc(node); |
| 443 break; | 473 break; |
| 444 case kStringFromCharCode: | 474 case kStringFromCharCode: |
| 445 reduction = ReduceStringFromCharCode(node); | 475 reduction = ReduceStringFromCharCode(node); |
| 446 break; | 476 break; |
| 447 default: | 477 default: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 509 } |
| 480 | 510 |
| 481 | 511 |
| 482 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 512 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
| 483 return jsgraph()->simplified(); | 513 return jsgraph()->simplified(); |
| 484 } | 514 } |
| 485 | 515 |
| 486 } // namespace compiler | 516 } // namespace compiler |
| 487 } // namespace internal | 517 } // namespace internal |
| 488 } // namespace v8 | 518 } // namespace v8 |
| OLD | NEW |