| 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/js-builtin-reducer.h" | 6 #include "src/compiler/js-builtin-reducer.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 #include "src/types.h" | 10 #include "src/types.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (r.InputsMatchOne(Type::Number())) { | 177 if (r.InputsMatchOne(Type::Number())) { |
| 178 // Math.fround(a:number) -> TruncateFloat64ToFloat32(a) | 178 // Math.fround(a:number) -> TruncateFloat64ToFloat32(a) |
| 179 Node* value = | 179 Node* value = |
| 180 graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left()); | 180 graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left()); |
| 181 return Replace(value); | 181 return Replace(value); |
| 182 } | 182 } |
| 183 return NoChange(); | 183 return NoChange(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 | 186 |
| 187 // ES6 draft 10-14-14, section 20.2.2.16. | |
| 188 Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) { | |
| 189 if (!machine()->HasFloat64RoundDown()) return NoChange(); | |
| 190 JSCallReduction r(node); | |
| 191 if (r.InputsMatchOne(Type::Number())) { | |
| 192 // Math.floor(a:number) -> Float64RoundDown(a) | |
| 193 Node* value = graph()->NewNode(machine()->Float64RoundDown(), r.left()); | |
| 194 return Replace(value); | |
| 195 } | |
| 196 return NoChange(); | |
| 197 } | |
| 198 | |
| 199 | |
| 200 Reduction JSBuiltinReducer::Reduce(Node* node) { | 187 Reduction JSBuiltinReducer::Reduce(Node* node) { |
| 201 JSCallReduction r(node); | 188 JSCallReduction r(node); |
| 202 | 189 |
| 203 // Dispatch according to the BuiltinFunctionId if present. | 190 // Dispatch according to the BuiltinFunctionId if present. |
| 204 if (!r.HasBuiltinFunctionId()) return NoChange(); | 191 if (!r.HasBuiltinFunctionId()) return NoChange(); |
| 205 switch (r.GetBuiltinFunctionId()) { | 192 switch (r.GetBuiltinFunctionId()) { |
| 206 case kMathAbs: | 193 case kMathAbs: |
| 207 return ReplaceWithPureReduction(node, ReduceMathAbs(node)); | 194 return ReplaceWithPureReduction(node, ReduceMathAbs(node)); |
| 208 case kMathSqrt: | 195 case kMathSqrt: |
| 209 return ReplaceWithPureReduction(node, ReduceMathSqrt(node)); | 196 return ReplaceWithPureReduction(node, ReduceMathSqrt(node)); |
| 210 case kMathMax: | 197 case kMathMax: |
| 211 return ReplaceWithPureReduction(node, ReduceMathMax(node)); | 198 return ReplaceWithPureReduction(node, ReduceMathMax(node)); |
| 212 case kMathImul: | 199 case kMathImul: |
| 213 return ReplaceWithPureReduction(node, ReduceMathImul(node)); | 200 return ReplaceWithPureReduction(node, ReduceMathImul(node)); |
| 214 case kMathFround: | 201 case kMathFround: |
| 215 return ReplaceWithPureReduction(node, ReduceMathFround(node)); | 202 return ReplaceWithPureReduction(node, ReduceMathFround(node)); |
| 216 case kMathFloor: | |
| 217 return ReplaceWithPureReduction(node, ReduceMathFloor(node)); | |
| 218 default: | 203 default: |
| 219 break; | 204 break; |
| 220 } | 205 } |
| 221 return NoChange(); | 206 return NoChange(); |
| 222 } | 207 } |
| 223 | 208 |
| 224 | 209 |
| 225 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } | 210 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } |
| 226 | 211 |
| 227 | 212 |
| 228 CommonOperatorBuilder* JSBuiltinReducer::common() const { | 213 CommonOperatorBuilder* JSBuiltinReducer::common() const { |
| 229 return jsgraph()->common(); | 214 return jsgraph()->common(); |
| 230 } | 215 } |
| 231 | 216 |
| 232 | 217 |
| 233 MachineOperatorBuilder* JSBuiltinReducer::machine() const { | 218 MachineOperatorBuilder* JSBuiltinReducer::machine() const { |
| 234 return jsgraph()->machine(); | 219 return jsgraph()->machine(); |
| 235 } | 220 } |
| 236 | 221 |
| 237 } // namespace compiler | 222 } // namespace compiler |
| 238 } // namespace internal | 223 } // namespace internal |
| 239 } // namespace v8 | 224 } // namespace v8 |
| OLD | NEW |