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/diamond.h" | 5 #include "src/compiler/diamond.h" |
6 #include "src/compiler/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
7 #include "src/compiler/js-builtin-reducer.h" | 7 #include "src/compiler/js-builtin-reducer.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
10 #include "src/types.h" | 10 #include "src/types.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 // ECMA-262, section 15.8.2.1. | 99 // ECMA-262, section 15.8.2.1. |
100 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { | 100 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { |
101 JSCallReduction r(node); | 101 JSCallReduction r(node); |
102 if (r.InputsMatchOne(Type::Unsigned32())) { | 102 if (r.InputsMatchOne(Type::Unsigned32())) { |
103 // Math.abs(a:uint32) -> a | 103 // Math.abs(a:uint32) -> a |
104 return Replace(r.left()); | 104 return Replace(r.left()); |
105 } | 105 } |
106 if (r.InputsMatchOne(Type::Number())) { | 106 if (r.InputsMatchOne(Type::Number())) { |
107 // Math.abs(a:number) -> (a > 0 ? a : 0 - a) | 107 // Math.abs(a:number) -> (a > 0 ? a : 0 - a) |
108 Node* value = r.left(); | 108 Node* const value = r.left(); |
109 Node* zero = jsgraph()->ZeroConstant(); | 109 Node* const zero = jsgraph()->ZeroConstant(); |
110 Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), zero, value); | 110 return Replace(graph()->NewNode( |
111 Diamond d(graph(), common(), cmp); | 111 common()->Select(kMachNone), |
112 Node* neg = graph()->NewNode(simplified()->NumberSubtract(), zero, value); | 112 graph()->NewNode(simplified()->NumberLessThan(), zero, value), value, |
113 return Replace(d.Phi(kMachNone, value, neg)); | 113 graph()->NewNode(simplified()->NumberSubtract(), zero, value))); |
114 } | 114 } |
115 return NoChange(); | 115 return NoChange(); |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 // ECMA-262, section 15.8.2.17. | 119 // ECMA-262, section 15.8.2.17. |
120 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { | 120 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { |
121 JSCallReduction r(node); | 121 JSCallReduction r(node); |
122 if (r.InputsMatchOne(Type::Number())) { | 122 if (r.InputsMatchOne(Type::Number())) { |
123 // Math.sqrt(a:number) -> Float64Sqrt(a) | 123 // Math.sqrt(a:number) -> Float64Sqrt(a) |
(...skipping 12 matching lines...) Expand all Loading... |
136 return Replace(jsgraph()->Constant(-V8_INFINITY)); | 136 return Replace(jsgraph()->Constant(-V8_INFINITY)); |
137 } | 137 } |
138 if (r.InputsMatchOne(Type::Number())) { | 138 if (r.InputsMatchOne(Type::Number())) { |
139 // Math.max(a:number) -> a | 139 // Math.max(a:number) -> a |
140 return Replace(r.left()); | 140 return Replace(r.left()); |
141 } | 141 } |
142 if (r.InputsMatchAll(Type::Integral32())) { | 142 if (r.InputsMatchAll(Type::Integral32())) { |
143 // Math.max(a:int32, b:int32, ...) | 143 // Math.max(a:int32, b:int32, ...) |
144 Node* value = r.GetJSCallInput(0); | 144 Node* value = r.GetJSCallInput(0); |
145 for (int i = 1; i < r.GetJSCallArity(); i++) { | 145 for (int i = 1; i < r.GetJSCallArity(); i++) { |
146 Node* p = r.GetJSCallInput(i); | 146 Node* const input = r.GetJSCallInput(i); |
147 Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), value, p); | 147 value = graph()->NewNode( |
148 Diamond d(graph(), common(), cmp); | 148 common()->Select(kMachNone), |
149 value = d.Phi(kMachNone, p, value); | 149 graph()->NewNode(simplified()->NumberLessThan(), input, value), input, |
| 150 value); |
150 } | 151 } |
151 return Replace(value); | 152 return Replace(value); |
152 } | 153 } |
153 return NoChange(); | 154 return NoChange(); |
154 } | 155 } |
155 | 156 |
156 | 157 |
157 // ES6 draft 08-24-14, section 20.2.2.19. | 158 // ES6 draft 08-24-14, section 20.2.2.19. |
158 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { | 159 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { |
159 JSCallReduction r(node); | 160 JSCallReduction r(node); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 return ReplaceWithPureReduction(node, ReduceMathCeil(node)); | 228 return ReplaceWithPureReduction(node, ReduceMathCeil(node)); |
228 default: | 229 default: |
229 break; | 230 break; |
230 } | 231 } |
231 return NoChange(); | 232 return NoChange(); |
232 } | 233 } |
233 | 234 |
234 } // namespace compiler | 235 } // namespace compiler |
235 } // namespace internal | 236 } // namespace internal |
236 } // namespace v8 | 237 } // namespace v8 |
OLD | NEW |