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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { | 122 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { |
123 JSCallReduction r(node); | 123 JSCallReduction r(node); |
124 if (r.InputsMatchTwo(Type::Integral32(), Type::Integral32())) { | 124 if (r.InputsMatchTwo(Type::Integral32(), Type::Integral32())) { |
125 // Math.imul(a:int32, b:int32) -> Int32Mul(a, b) | 125 // Math.imul(a:int32, b:int32) -> Int32Mul(a, b) |
126 Node* value = graph()->NewNode(machine()->Int32Mul(), r.left(), r.right()); | 126 Node* value = graph()->NewNode(machine()->Int32Mul(), r.left(), r.right()); |
127 return Replace(value); | 127 return Replace(value); |
128 } | 128 } |
129 return NoChange(); | 129 return NoChange(); |
130 } | 130 } |
131 | 131 |
132 // ES6 draft 08-24-14, section 20.2.2.16. | 132 // ES6 section 20.2.2.10 Math.ceil ( x ) |
133 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { | 133 Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) { |
134 JSCallReduction r(node); | 134 JSCallReduction r(node); |
135 if (r.InputsMatchOne(Type::Number())) { | 135 if (r.InputsMatchOne(Type::Number())) { |
136 // Math.ceil(a:number) -> NumberCeil(a) | 136 // Math.ceil(a:number) -> NumberCeil(a) |
137 Node* value = graph()->NewNode(simplified()->NumberCeil(), r.left()); | 137 Node* value = graph()->NewNode(simplified()->NumberCeil(), r.left()); |
138 return Replace(value); | 138 return Replace(value); |
139 } | 139 } |
140 return NoChange(); | 140 return NoChange(); |
141 } | 141 } |
142 | 142 |
| 143 // ES6 section 20.2.2.11 Math.clz32 ( x ) |
| 144 Reduction JSBuiltinReducer::ReduceMathClz32(Node* node) { |
| 145 JSCallReduction r(node); |
| 146 if (r.InputsMatchOne(Type::Unsigned32())) { |
| 147 // Math.clz32(a:unsigned32) -> NumberClz32(a) |
| 148 Node* value = graph()->NewNode(simplified()->NumberClz32(), r.left()); |
| 149 return Replace(value); |
| 150 } |
| 151 if (r.InputsMatchOne(Type::Number())) { |
| 152 // Math.clz32(a:number) -> NumberClz32(NumberToUint32(a)) |
| 153 Node* value = graph()->NewNode( |
| 154 simplified()->NumberClz32(), |
| 155 graph()->NewNode(simplified()->NumberToUint32(), r.left())); |
| 156 return Replace(value); |
| 157 } |
| 158 return NoChange(); |
| 159 } |
| 160 |
143 // ES6 draft 08-24-14, section 20.2.2.16. | 161 // ES6 draft 08-24-14, section 20.2.2.16. |
144 Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) { | 162 Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) { |
145 JSCallReduction r(node); | 163 JSCallReduction r(node); |
146 if (r.InputsMatchOne(Type::Number())) { | 164 if (r.InputsMatchOne(Type::Number())) { |
147 // Math.floor(a:number) -> NumberFloor(a) | 165 // Math.floor(a:number) -> NumberFloor(a) |
148 Node* value = graph()->NewNode(simplified()->NumberFloor(), r.left()); | 166 Node* value = graph()->NewNode(simplified()->NumberFloor(), r.left()); |
149 return Replace(value); | 167 return Replace(value); |
150 } | 168 } |
151 return NoChange(); | 169 return NoChange(); |
152 } | 170 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 220 |
203 // Dispatch according to the BuiltinFunctionId if present. | 221 // Dispatch according to the BuiltinFunctionId if present. |
204 if (!r.HasBuiltinFunctionId()) return NoChange(); | 222 if (!r.HasBuiltinFunctionId()) return NoChange(); |
205 switch (r.GetBuiltinFunctionId()) { | 223 switch (r.GetBuiltinFunctionId()) { |
206 case kMathMax: | 224 case kMathMax: |
207 reduction = ReduceMathMax(node); | 225 reduction = ReduceMathMax(node); |
208 break; | 226 break; |
209 case kMathImul: | 227 case kMathImul: |
210 reduction = ReduceMathImul(node); | 228 reduction = ReduceMathImul(node); |
211 break; | 229 break; |
| 230 case kMathClz32: |
| 231 reduction = ReduceMathClz32(node); |
| 232 break; |
212 case kMathCeil: | 233 case kMathCeil: |
213 reduction = ReduceMathCeil(node); | 234 reduction = ReduceMathCeil(node); |
214 break; | 235 break; |
215 case kMathFloor: | 236 case kMathFloor: |
216 reduction = ReduceMathFloor(node); | 237 reduction = ReduceMathFloor(node); |
217 break; | 238 break; |
218 case kMathFround: | 239 case kMathFround: |
219 reduction = ReduceMathFround(node); | 240 reduction = ReduceMathFround(node); |
220 break; | 241 break; |
221 case kMathRound: | 242 case kMathRound: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 276 } |
256 | 277 |
257 | 278 |
258 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 279 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
259 return jsgraph()->simplified(); | 280 return jsgraph()->simplified(); |
260 } | 281 } |
261 | 282 |
262 } // namespace compiler | 283 } // namespace compiler |
263 } // namespace internal | 284 } // namespace internal |
264 } // namespace v8 | 285 } // namespace v8 |
OLD | NEW |