| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/representation-change.h" | 5 #include "src/compiler/representation-change.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // static | 56 // static |
| 57 Truncation::TruncationKind Truncation::Generalize(TruncationKind rep1, | 57 Truncation::TruncationKind Truncation::Generalize(TruncationKind rep1, |
| 58 TruncationKind rep2) { | 58 TruncationKind rep2) { |
| 59 if (LessGeneral(rep1, rep2)) return rep2; | 59 if (LessGeneral(rep1, rep2)) return rep2; |
| 60 if (LessGeneral(rep2, rep1)) return rep1; | 60 if (LessGeneral(rep2, rep1)) return rep1; |
| 61 // Handle the generalization of float64-representable values. | 61 // Handle the generalization of float64-representable values. |
| 62 if (LessGeneral(rep1, TruncationKind::kFloat64) && | 62 if (LessGeneral(rep1, TruncationKind::kFloat64) && |
| 63 LessGeneral(rep2, TruncationKind::kFloat64)) { | 63 LessGeneral(rep2, TruncationKind::kFloat64)) { |
| 64 return TruncationKind::kFloat64; | 64 return TruncationKind::kFloat64; |
| 65 } | 65 } |
| 66 // Handle the generalization of any-representable values. |
| 67 if (LessGeneral(rep1, TruncationKind::kAny) && |
| 68 LessGeneral(rep2, TruncationKind::kAny)) { |
| 69 return TruncationKind::kAny; |
| 70 } |
| 66 // All other combinations are illegal. | 71 // All other combinations are illegal. |
| 67 FATAL("Tried to combine incompatible truncations"); | 72 FATAL("Tried to combine incompatible truncations"); |
| 68 return TruncationKind::kNone; | 73 return TruncationKind::kNone; |
| 69 } | 74 } |
| 70 | 75 |
| 71 | 76 |
| 72 // static | 77 // static |
| 73 bool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) { | 78 bool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) { |
| 74 switch (rep1) { | 79 switch (rep1) { |
| 75 case TruncationKind::kNone: | 80 case TruncationKind::kNone: |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 truncation.TruncatesToWord32()) { | 276 truncation.TruncatesToWord32()) { |
| 272 // Either the output is uint32 or the uses only care about the | 277 // Either the output is uint32 or the uses only care about the |
| 273 // low 32 bits (so we can pick uint32 safely). | 278 // low 32 bits (so we can pick uint32 safely). |
| 274 | 279 |
| 275 // uint32 -> float64 -> float32 | 280 // uint32 -> float64 -> float32 |
| 276 op = machine()->ChangeUint32ToFloat64(); | 281 op = machine()->ChangeUint32ToFloat64(); |
| 277 node = jsgraph()->graph()->NewNode(op, node); | 282 node = jsgraph()->graph()->NewNode(op, node); |
| 278 op = machine()->TruncateFloat64ToFloat32(); | 283 op = machine()->TruncateFloat64ToFloat32(); |
| 279 } | 284 } |
| 280 } else if (output_rep == MachineRepresentation::kTagged) { | 285 } else if (output_rep == MachineRepresentation::kTagged) { |
| 281 if (output_type->Is(Type::NumberOrUndefined())) { | 286 if (output_type->Is(Type::NumberOrOddball())) { |
| 282 // tagged -> float64 -> float32 | 287 // tagged -> float64 -> float32 |
| 283 if (output_type->Is(Type::Number())) { | 288 if (output_type->Is(Type::Number())) { |
| 284 op = simplified()->ChangeTaggedToFloat64(); | 289 op = simplified()->ChangeTaggedToFloat64(); |
| 285 } else { | 290 } else { |
| 286 op = simplified()->TruncateTaggedToFloat64(); | 291 op = simplified()->TruncateTaggedToFloat64(); |
| 287 } | 292 } |
| 288 node = jsgraph()->graph()->NewNode(op, node); | 293 node = jsgraph()->graph()->NewNode(op, node); |
| 289 op = machine()->TruncateFloat64ToFloat32(); | 294 op = machine()->TruncateFloat64ToFloat32(); |
| 290 } | 295 } |
| 291 } else if (output_rep == MachineRepresentation::kFloat64) { | 296 } else if (output_rep == MachineRepresentation::kFloat64) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 342 } |
| 338 } else if (output_rep == MachineRepresentation::kTagged) { | 343 } else if (output_rep == MachineRepresentation::kTagged) { |
| 339 if (output_type->Is(Type::Undefined())) { | 344 if (output_type->Is(Type::Undefined())) { |
| 340 return jsgraph()->Float64Constant( | 345 return jsgraph()->Float64Constant( |
| 341 std::numeric_limits<double>::quiet_NaN()); | 346 std::numeric_limits<double>::quiet_NaN()); |
| 342 } else if (output_type->Is(Type::TaggedSigned())) { | 347 } else if (output_type->Is(Type::TaggedSigned())) { |
| 343 node = InsertChangeTaggedSignedToInt32(node); | 348 node = InsertChangeTaggedSignedToInt32(node); |
| 344 op = machine()->ChangeInt32ToFloat64(); | 349 op = machine()->ChangeInt32ToFloat64(); |
| 345 } else if (output_type->Is(Type::Number())) { | 350 } else if (output_type->Is(Type::Number())) { |
| 346 op = simplified()->ChangeTaggedToFloat64(); | 351 op = simplified()->ChangeTaggedToFloat64(); |
| 347 } else if (output_type->Is(Type::NumberOrUndefined())) { | 352 } else if (output_type->Is(Type::NumberOrOddball())) { |
| 348 // TODO(jarin) Here we should check that truncation is Number. | 353 // TODO(jarin) Here we should check that truncation is Number. |
| 349 op = simplified()->TruncateTaggedToFloat64(); | 354 op = simplified()->TruncateTaggedToFloat64(); |
| 350 } else if (use_info.type_check() == TypeCheckKind::kNumberOrUndefined) { | 355 } else if (use_info.type_check() == TypeCheckKind::kNumberOrOddball) { |
| 351 op = simplified()->CheckedTaggedToFloat64(); | 356 op = simplified()->CheckedTaggedToFloat64(); |
| 352 } | 357 } |
| 353 } else if (output_rep == MachineRepresentation::kFloat32) { | 358 } else if (output_rep == MachineRepresentation::kFloat32) { |
| 354 op = machine()->ChangeFloat32ToFloat64(); | 359 op = machine()->ChangeFloat32ToFloat64(); |
| 355 } | 360 } |
| 356 if (op == nullptr) { | 361 if (op == nullptr) { |
| 357 return TypeError(node, output_rep, output_type, | 362 return TypeError(node, output_rep, output_type, |
| 358 MachineRepresentation::kFloat64); | 363 MachineRepresentation::kFloat64); |
| 359 } | 364 } |
| 360 return InsertConversion(node, op, use_node); | 365 return InsertConversion(node, op, use_node); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 807 } |
| 803 | 808 |
| 804 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 809 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
| 805 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 810 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
| 806 node); | 811 node); |
| 807 } | 812 } |
| 808 | 813 |
| 809 } // namespace compiler | 814 } // namespace compiler |
| 810 } // namespace internal | 815 } // namespace internal |
| 811 } // namespace v8 | 816 } // namespace v8 |
| OLD | NEW |