| 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 // ES6 section 20.2.2.1 Math.abs ( x ) |
| 95 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { |
| 96 JSCallReduction r(node); |
| 97 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 98 // Math.abs(a:plain-primitive) -> NumberAbs(ToNumber(a)) |
| 99 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 100 Node* value = graph()->NewNode(simplified()->NumberAbs(), input); |
| 101 return Replace(value); |
| 102 } |
| 103 return NoChange(); |
| 104 } |
| 105 |
| 94 // ES6 section 20.2.2.6 Math.atan ( x ) | 106 // ES6 section 20.2.2.6 Math.atan ( x ) |
| 95 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { | 107 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { |
| 96 JSCallReduction r(node); | 108 JSCallReduction r(node); |
| 97 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 109 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
| 98 // Math.atan(a:plain-primitive) -> NumberAtan(ToNumber(a)) | 110 // Math.atan(a:plain-primitive) -> NumberAtan(ToNumber(a)) |
| 99 Node* input = ToNumber(r.GetJSCallInput(0)); | 111 Node* input = ToNumber(r.GetJSCallInput(0)); |
| 100 Node* value = graph()->NewNode(simplified()->NumberAtan(), input); | 112 Node* value = graph()->NewNode(simplified()->NumberAtan(), input); |
| 101 return Replace(value); | 113 return Replace(value); |
| 102 } | 114 } |
| 103 return NoChange(); | 115 return NoChange(); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 return NoChange(); | 422 return NoChange(); |
| 411 } | 423 } |
| 412 | 424 |
| 413 Reduction JSBuiltinReducer::Reduce(Node* node) { | 425 Reduction JSBuiltinReducer::Reduce(Node* node) { |
| 414 Reduction reduction = NoChange(); | 426 Reduction reduction = NoChange(); |
| 415 JSCallReduction r(node); | 427 JSCallReduction r(node); |
| 416 | 428 |
| 417 // Dispatch according to the BuiltinFunctionId if present. | 429 // Dispatch according to the BuiltinFunctionId if present. |
| 418 if (!r.HasBuiltinFunctionId()) return NoChange(); | 430 if (!r.HasBuiltinFunctionId()) return NoChange(); |
| 419 switch (r.GetBuiltinFunctionId()) { | 431 switch (r.GetBuiltinFunctionId()) { |
| 432 case kMathAbs: |
| 433 reduction = ReduceMathAbs(node); |
| 434 break; |
| 420 case kMathAtan: | 435 case kMathAtan: |
| 421 reduction = ReduceMathAtan(node); | 436 reduction = ReduceMathAtan(node); |
| 422 break; | 437 break; |
| 423 case kMathAtan2: | 438 case kMathAtan2: |
| 424 reduction = ReduceMathAtan2(node); | 439 reduction = ReduceMathAtan2(node); |
| 425 break; | 440 break; |
| 426 case kMathAtanh: | 441 case kMathAtanh: |
| 427 reduction = ReduceMathAtanh(node); | 442 reduction = ReduceMathAtanh(node); |
| 428 break; | 443 break; |
| 429 case kMathClz32: | 444 case kMathClz32: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 539 } |
| 525 | 540 |
| 526 | 541 |
| 527 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 542 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
| 528 return jsgraph()->simplified(); | 543 return jsgraph()->simplified(); |
| 529 } | 544 } |
| 530 | 545 |
| 531 } // namespace compiler | 546 } // namespace compiler |
| 532 } // namespace internal | 547 } // namespace internal |
| 533 } // namespace v8 | 548 } // namespace v8 |
| OLD | NEW |