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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 JSCallReduction r(node); | 96 JSCallReduction r(node); |
97 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 97 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
98 // Math.abs(a:plain-primitive) -> NumberAbs(ToNumber(a)) | 98 // Math.abs(a:plain-primitive) -> NumberAbs(ToNumber(a)) |
99 Node* input = ToNumber(r.GetJSCallInput(0)); | 99 Node* input = ToNumber(r.GetJSCallInput(0)); |
100 Node* value = graph()->NewNode(simplified()->NumberAbs(), input); | 100 Node* value = graph()->NewNode(simplified()->NumberAbs(), input); |
101 return Replace(value); | 101 return Replace(value); |
102 } | 102 } |
103 return NoChange(); | 103 return NoChange(); |
104 } | 104 } |
105 | 105 |
106 // ES6 section 20.2.2.2 Math.acos ( x ) | |
107 Reduction JSBuiltinReducer::ReduceMathAcos(Node* node) { | |
108 JSCallReduction r(node); | |
109 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
110 // Math.acos(a:plain-primitive) -> NumberAcos(ToNumber(a)) | |
111 Node* input = ToNumber(r.GetJSCallInput(0)); | |
112 Node* value = graph()->NewNode(simplified()->NumberAcos(), input); | |
113 return Replace(value); | |
114 } | |
115 return NoChange(); | |
116 } | |
117 | |
118 // ES6 section 20.2.2.3 Math.acosh ( x ) | |
119 Reduction JSBuiltinReducer::ReduceMathAcosh(Node* node) { | |
120 JSCallReduction r(node); | |
121 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
122 // Math.acosh(a:plain-primitive) -> NumberAcosh(ToNumber(a)) | |
123 Node* input = ToNumber(r.GetJSCallInput(0)); | |
124 Node* value = graph()->NewNode(simplified()->NumberAcosh(), input); | |
125 return Replace(value); | |
126 } | |
127 return NoChange(); | |
128 } | |
129 | |
130 // ES6 section 20.2.2.4 Math.asin ( x ) | |
131 Reduction JSBuiltinReducer::ReduceMathAsin(Node* node) { | |
132 JSCallReduction r(node); | |
133 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
134 // Math.asin(a:plain-primitive) -> NumberAsin(ToNumber(a)) | |
135 Node* input = ToNumber(r.GetJSCallInput(0)); | |
136 Node* value = graph()->NewNode(simplified()->NumberAsin(), input); | |
137 return Replace(value); | |
138 } | |
139 return NoChange(); | |
140 } | |
141 | |
142 // ES6 section 20.2.2.5 Math.asinh ( x ) | |
143 Reduction JSBuiltinReducer::ReduceMathAsinh(Node* node) { | |
144 JSCallReduction r(node); | |
145 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
146 // Math.asinh(a:plain-primitive) -> NumberAsinh(ToNumber(a)) | |
147 Node* input = ToNumber(r.GetJSCallInput(0)); | |
148 Node* value = graph()->NewNode(simplified()->NumberAsinh(), input); | |
149 return Replace(value); | |
150 } | |
151 return NoChange(); | |
152 } | |
Franzi
2016/07/01 09:09:48
This is a lot of code duplication. Can we use a ma
Benedikt Meurer
2016/07/01 10:48:33
Not a macro, but we will unify this whole file usi
| |
153 | |
106 // ES6 section 20.2.2.6 Math.atan ( x ) | 154 // ES6 section 20.2.2.6 Math.atan ( x ) |
107 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { | 155 Reduction JSBuiltinReducer::ReduceMathAtan(Node* node) { |
108 JSCallReduction r(node); | 156 JSCallReduction r(node); |
109 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 157 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
110 // Math.atan(a:plain-primitive) -> NumberAtan(ToNumber(a)) | 158 // Math.atan(a:plain-primitive) -> NumberAtan(ToNumber(a)) |
111 Node* input = ToNumber(r.GetJSCallInput(0)); | 159 Node* input = ToNumber(r.GetJSCallInput(0)); |
112 Node* value = graph()->NewNode(simplified()->NumberAtan(), input); | 160 Node* value = graph()->NewNode(simplified()->NumberAtan(), input); |
113 return Replace(value); | 161 return Replace(value); |
114 } | 162 } |
115 return NoChange(); | 163 return NoChange(); |
116 } | 164 } |
117 | 165 |
166 // ES6 section 20.2.2.7 Math.atanh ( x ) | |
167 Reduction JSBuiltinReducer::ReduceMathAtanh(Node* node) { | |
168 JSCallReduction r(node); | |
169 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
170 // Math.atanh(a:plain-primitive) -> NumberAtanh(ToNumber(a)) | |
171 Node* input = ToNumber(r.GetJSCallInput(0)); | |
172 Node* value = graph()->NewNode(simplified()->NumberAtanh(), input); | |
173 return Replace(value); | |
174 } | |
175 return NoChange(); | |
176 } | |
177 | |
118 // ES6 section 20.2.2.8 Math.atan2 ( y, x ) | 178 // ES6 section 20.2.2.8 Math.atan2 ( y, x ) |
119 Reduction JSBuiltinReducer::ReduceMathAtan2(Node* node) { | 179 Reduction JSBuiltinReducer::ReduceMathAtan2(Node* node) { |
120 JSCallReduction r(node); | 180 JSCallReduction r(node); |
121 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { | 181 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { |
122 // Math.atan2(a:plain-primitive, | 182 // Math.atan2(a:plain-primitive, |
123 // b:plain-primitive) -> NumberAtan2(ToNumber(a), | 183 // b:plain-primitive) -> NumberAtan2(ToNumber(a), |
124 // ToNumber(b)) | 184 // ToNumber(b)) |
125 Node* left = ToNumber(r.left()); | 185 Node* left = ToNumber(r.left()); |
126 Node* right = ToNumber(r.right()); | 186 Node* right = ToNumber(r.right()); |
127 Node* value = graph()->NewNode(simplified()->NumberAtan2(), left, right); | 187 Node* value = graph()->NewNode(simplified()->NumberAtan2(), left, right); |
128 return Replace(value); | 188 return Replace(value); |
129 } | 189 } |
130 return NoChange(); | 190 return NoChange(); |
131 } | 191 } |
132 | 192 |
133 // ES6 section 20.2.2.7 Math.atanh ( x ) | |
134 Reduction JSBuiltinReducer::ReduceMathAtanh(Node* node) { | |
135 JSCallReduction r(node); | |
136 if (r.InputsMatchOne(Type::Number())) { | |
137 // Math.atanh(a:number) -> NumberAtanh(a) | |
138 Node* value = graph()->NewNode(simplified()->NumberAtanh(), r.left()); | |
139 return Replace(value); | |
140 } | |
141 return NoChange(); | |
142 } | |
143 | |
144 // ES6 section 20.2.2.10 Math.ceil ( x ) | 193 // ES6 section 20.2.2.10 Math.ceil ( x ) |
145 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { | 194 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { |
146 JSCallReduction r(node); | 195 JSCallReduction r(node); |
147 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 196 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
148 // Math.ceil(a:plain-primitive) -> NumberCeil(ToNumber(a)) | 197 // Math.ceil(a:plain-primitive) -> NumberCeil(ToNumber(a)) |
149 Node* input = ToNumber(r.GetJSCallInput(0)); | 198 Node* input = ToNumber(r.GetJSCallInput(0)); |
150 Node* value = graph()->NewNode(simplified()->NumberCeil(), input); | 199 Node* value = graph()->NewNode(simplified()->NumberCeil(), input); |
151 return Replace(value); | 200 return Replace(value); |
152 } | 201 } |
153 return NoChange(); | 202 return NoChange(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 Reduction JSBuiltinReducer::ReduceMathCbrt(Node* node) { | 430 Reduction JSBuiltinReducer::ReduceMathCbrt(Node* node) { |
382 JSCallReduction r(node); | 431 JSCallReduction r(node); |
383 if (r.InputsMatchOne(Type::Number())) { | 432 if (r.InputsMatchOne(Type::Number())) { |
384 // Math.cbrt(a:number) -> NumberCbrt(a) | 433 // Math.cbrt(a:number) -> NumberCbrt(a) |
385 Node* value = graph()->NewNode(simplified()->NumberCbrt(), r.left()); | 434 Node* value = graph()->NewNode(simplified()->NumberCbrt(), r.left()); |
386 return Replace(value); | 435 return Replace(value); |
387 } | 436 } |
388 return NoChange(); | 437 return NoChange(); |
389 } | 438 } |
390 | 439 |
440 // ES6 section 20.2.2.29 Math.sign ( x ) | |
441 Reduction JSBuiltinReducer::ReduceMathSign(Node* node) { | |
442 JSCallReduction r(node); | |
443 if (r.InputsMatchOne(Type::PlainPrimitive())) { | |
444 // Math.sign(a:plain-primitive) -> NumberSign(ToNumber(a)) | |
445 Node* input = ToNumber(r.GetJSCallInput(0)); | |
446 Node* value = graph()->NewNode(simplified()->NumberSign(), input); | |
447 return Replace(value); | |
448 } | |
449 return NoChange(); | |
450 } | |
451 | |
391 // ES6 section 20.2.2.30 Math.sin ( x ) | 452 // ES6 section 20.2.2.30 Math.sin ( x ) |
392 Reduction JSBuiltinReducer::ReduceMathSin(Node* node) { | 453 Reduction JSBuiltinReducer::ReduceMathSin(Node* node) { |
393 JSCallReduction r(node); | 454 JSCallReduction r(node); |
394 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 455 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
395 // Math.sin(a:plain-primitive) -> NumberSin(ToNumber(a)) | 456 // Math.sin(a:plain-primitive) -> NumberSin(ToNumber(a)) |
396 Node* input = ToNumber(r.GetJSCallInput(0)); | 457 Node* input = ToNumber(r.GetJSCallInput(0)); |
397 Node* value = graph()->NewNode(simplified()->NumberSin(), input); | 458 Node* value = graph()->NewNode(simplified()->NumberSin(), input); |
398 return Replace(value); | 459 return Replace(value); |
399 } | 460 } |
400 return NoChange(); | 461 return NoChange(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 Reduction JSBuiltinReducer::Reduce(Node* node) { | 536 Reduction JSBuiltinReducer::Reduce(Node* node) { |
476 Reduction reduction = NoChange(); | 537 Reduction reduction = NoChange(); |
477 JSCallReduction r(node); | 538 JSCallReduction r(node); |
478 | 539 |
479 // Dispatch according to the BuiltinFunctionId if present. | 540 // Dispatch according to the BuiltinFunctionId if present. |
480 if (!r.HasBuiltinFunctionId()) return NoChange(); | 541 if (!r.HasBuiltinFunctionId()) return NoChange(); |
481 switch (r.GetBuiltinFunctionId()) { | 542 switch (r.GetBuiltinFunctionId()) { |
482 case kMathAbs: | 543 case kMathAbs: |
483 reduction = ReduceMathAbs(node); | 544 reduction = ReduceMathAbs(node); |
484 break; | 545 break; |
546 case kMathAcos: | |
547 reduction = ReduceMathAcos(node); | |
548 break; | |
549 case kMathAcosh: | |
550 reduction = ReduceMathAcosh(node); | |
551 break; | |
552 case kMathAsin: | |
553 reduction = ReduceMathAsin(node); | |
554 break; | |
555 case kMathAsinh: | |
556 reduction = ReduceMathAsinh(node); | |
557 break; | |
485 case kMathAtan: | 558 case kMathAtan: |
486 reduction = ReduceMathAtan(node); | 559 reduction = ReduceMathAtan(node); |
487 break; | 560 break; |
561 case kMathAtanh: | |
562 reduction = ReduceMathAtanh(node); | |
563 break; | |
488 case kMathAtan2: | 564 case kMathAtan2: |
489 reduction = ReduceMathAtan2(node); | 565 reduction = ReduceMathAtan2(node); |
490 break; | 566 break; |
491 case kMathAtanh: | |
492 reduction = ReduceMathAtanh(node); | |
493 break; | |
494 case kMathCbrt: | 567 case kMathCbrt: |
495 reduction = ReduceMathCbrt(node); | 568 reduction = ReduceMathCbrt(node); |
496 break; | 569 break; |
497 case kMathCeil: | 570 case kMathCeil: |
498 reduction = ReduceMathCeil(node); | 571 reduction = ReduceMathCeil(node); |
499 break; | 572 break; |
500 case kMathClz32: | 573 case kMathClz32: |
501 reduction = ReduceMathClz32(node); | 574 reduction = ReduceMathClz32(node); |
502 break; | 575 break; |
503 case kMathCos: | 576 case kMathCos: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 break; | 611 break; |
539 case kMathMin: | 612 case kMathMin: |
540 reduction = ReduceMathMin(node); | 613 reduction = ReduceMathMin(node); |
541 break; | 614 break; |
542 case kMathPow: | 615 case kMathPow: |
543 reduction = ReduceMathPow(node); | 616 reduction = ReduceMathPow(node); |
544 break; | 617 break; |
545 case kMathRound: | 618 case kMathRound: |
546 reduction = ReduceMathRound(node); | 619 reduction = ReduceMathRound(node); |
547 break; | 620 break; |
621 case kMathSign: | |
622 reduction = ReduceMathSign(node); | |
623 break; | |
548 case kMathSin: | 624 case kMathSin: |
549 reduction = ReduceMathSin(node); | 625 reduction = ReduceMathSin(node); |
550 break; | 626 break; |
551 case kMathSinh: | 627 case kMathSinh: |
552 reduction = ReduceMathSinh(node); | 628 reduction = ReduceMathSinh(node); |
553 break; | 629 break; |
554 case kMathSqrt: | 630 case kMathSqrt: |
555 reduction = ReduceMathSqrt(node); | 631 reduction = ReduceMathSqrt(node); |
556 break; | 632 break; |
557 case kMathTan: | 633 case kMathTan: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 } | 677 } |
602 | 678 |
603 | 679 |
604 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 680 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
605 return jsgraph()->simplified(); | 681 return jsgraph()->simplified(); |
606 } | 682 } |
607 | 683 |
608 } // namespace compiler | 684 } // namespace compiler |
609 } // namespace internal | 685 } // namespace internal |
610 } // namespace v8 | 686 } // namespace v8 |
OLD | NEW |