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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 // Select the correct X -> Float32 operator. | 272 // Select the correct X -> Float32 operator. |
273 const Operator* op = nullptr; | 273 const Operator* op = nullptr; |
274 if (IsWord(output_rep)) { | 274 if (IsWord(output_rep)) { |
275 if (output_type->Is(Type::Signed32())) { | 275 if (output_type->Is(Type::Signed32())) { |
276 // int32 -> float64 -> float32 | 276 // int32 -> float64 -> float32 |
277 op = machine()->ChangeInt32ToFloat64(); | 277 op = machine()->ChangeInt32ToFloat64(); |
278 node = jsgraph()->graph()->NewNode(op, node); | 278 node = jsgraph()->graph()->NewNode(op, node); |
279 op = machine()->TruncateFloat64ToFloat32(); | 279 op = machine()->TruncateFloat64ToFloat32(); |
280 } else if (output_type->Is(Type::Unsigned32()) || | 280 } else if (output_type->Is(Type::Unsigned32()) || |
281 truncation.TruncatesToWord32()) { | 281 truncation.IsUsedAsWord32()) { |
282 // Either the output is uint32 or the uses only care about the | 282 // Either the output is uint32 or the uses only care about the |
283 // low 32 bits (so we can pick uint32 safely). | 283 // low 32 bits (so we can pick uint32 safely). |
284 | 284 |
285 // uint32 -> float64 -> float32 | 285 // uint32 -> float64 -> float32 |
286 op = machine()->ChangeUint32ToFloat64(); | 286 op = machine()->ChangeUint32ToFloat64(); |
287 node = jsgraph()->graph()->NewNode(op, node); | 287 node = jsgraph()->graph()->NewNode(op, node); |
288 op = machine()->TruncateFloat64ToFloat32(); | 288 op = machine()->TruncateFloat64ToFloat32(); |
289 } | 289 } |
290 } else if (output_rep == MachineRepresentation::kTagged) { | 290 } else if (output_rep == MachineRepresentation::kTagged) { |
291 if (output_type->Is(Type::NumberOrOddball())) { | 291 if (output_type->Is(Type::NumberOrOddball())) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 default: | 333 default: |
334 break; | 334 break; |
335 } | 335 } |
336 } | 336 } |
337 // Select the correct X -> Float64 operator. | 337 // Select the correct X -> Float64 operator. |
338 const Operator* op = nullptr; | 338 const Operator* op = nullptr; |
339 if (IsWord(output_rep)) { | 339 if (IsWord(output_rep)) { |
340 if (output_type->Is(Type::Signed32())) { | 340 if (output_type->Is(Type::Signed32())) { |
341 op = machine()->ChangeInt32ToFloat64(); | 341 op = machine()->ChangeInt32ToFloat64(); |
342 } else if (output_type->Is(Type::Unsigned32()) || | 342 } else if (output_type->Is(Type::Unsigned32()) || |
343 use_info.truncation().TruncatesToWord32()) { | 343 use_info.truncation().IsUsedAsWord32()) { |
344 // Either the output is uint32 or the uses only care about the | 344 // Either the output is uint32 or the uses only care about the |
345 // low 32 bits (so we can pick uint32 safely). | 345 // low 32 bits (so we can pick uint32 safely). |
346 op = machine()->ChangeUint32ToFloat64(); | 346 op = machine()->ChangeUint32ToFloat64(); |
347 } | 347 } |
348 } else if (output_rep == MachineRepresentation::kBit) { | 348 } else if (output_rep == MachineRepresentation::kBit) { |
349 op = machine()->ChangeUint32ToFloat64(); | 349 op = machine()->ChangeUint32ToFloat64(); |
350 } else if (output_rep == MachineRepresentation::kTagged) { | 350 } else if (output_rep == MachineRepresentation::kTagged) { |
351 if (output_type->Is(Type::Undefined())) { | 351 if (output_type->Is(Type::Undefined())) { |
352 return jsgraph()->Float64Constant( | 352 return jsgraph()->Float64Constant( |
353 std::numeric_limits<double>::quiet_NaN()); | 353 std::numeric_limits<double>::quiet_NaN()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 // Select the correct X -> Word32 operator. | 409 // Select the correct X -> Word32 operator. |
410 const Operator* op = nullptr; | 410 const Operator* op = nullptr; |
411 if (output_rep == MachineRepresentation::kBit) { | 411 if (output_rep == MachineRepresentation::kBit) { |
412 return node; // Sloppy comparison -> word32 | 412 return node; // Sloppy comparison -> word32 |
413 } else if (output_rep == MachineRepresentation::kFloat64) { | 413 } else if (output_rep == MachineRepresentation::kFloat64) { |
414 if (output_type->Is(Type::Unsigned32())) { | 414 if (output_type->Is(Type::Unsigned32())) { |
415 op = machine()->ChangeFloat64ToUint32(); | 415 op = machine()->ChangeFloat64ToUint32(); |
416 } else if (output_type->Is(Type::Signed32())) { | 416 } else if (output_type->Is(Type::Signed32())) { |
417 op = machine()->ChangeFloat64ToInt32(); | 417 op = machine()->ChangeFloat64ToInt32(); |
418 } else if (use_info.truncation().TruncatesToWord32()) { | 418 } else if (use_info.truncation().IsUsedAsWord32()) { |
419 op = machine()->TruncateFloat64ToWord32(); | 419 op = machine()->TruncateFloat64ToWord32(); |
420 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { | 420 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { |
421 op = simplified()->CheckedFloat64ToInt32(); | 421 op = simplified()->CheckedFloat64ToInt32(); |
422 } | 422 } |
423 } else if (output_rep == MachineRepresentation::kFloat32) { | 423 } else if (output_rep == MachineRepresentation::kFloat32) { |
424 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 | 424 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 |
425 if (output_type->Is(Type::Unsigned32())) { | 425 if (output_type->Is(Type::Unsigned32())) { |
426 op = machine()->ChangeFloat64ToUint32(); | 426 op = machine()->ChangeFloat64ToUint32(); |
427 } else if (output_type->Is(Type::Signed32())) { | 427 } else if (output_type->Is(Type::Signed32())) { |
428 op = machine()->ChangeFloat64ToInt32(); | 428 op = machine()->ChangeFloat64ToInt32(); |
429 } else if (use_info.truncation().TruncatesToWord32()) { | 429 } else if (use_info.truncation().IsUsedAsWord32()) { |
430 op = machine()->TruncateFloat64ToWord32(); | 430 op = machine()->TruncateFloat64ToWord32(); |
431 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { | 431 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { |
432 op = simplified()->CheckedFloat64ToInt32(); | 432 op = simplified()->CheckedFloat64ToInt32(); |
433 } | 433 } |
434 } else if (output_rep == MachineRepresentation::kTagged) { | 434 } else if (output_rep == MachineRepresentation::kTagged) { |
435 if (output_type->Is(Type::TaggedSigned())) { | 435 if (output_type->Is(Type::TaggedSigned())) { |
436 op = simplified()->ChangeTaggedSignedToInt32(); | 436 op = simplified()->ChangeTaggedSignedToInt32(); |
437 } else if (output_type->Is(Type::Unsigned32())) { | 437 } else if (output_type->Is(Type::Unsigned32())) { |
438 op = simplified()->ChangeTaggedToUint32(); | 438 op = simplified()->ChangeTaggedToUint32(); |
439 } else if (output_type->Is(Type::Signed32())) { | 439 } else if (output_type->Is(Type::Signed32())) { |
440 op = simplified()->ChangeTaggedToInt32(); | 440 op = simplified()->ChangeTaggedToInt32(); |
441 } else if (use_info.truncation().TruncatesToWord32()) { | 441 } else if (use_info.truncation().IsUsedAsWord32()) { |
442 op = simplified()->TruncateTaggedToWord32(); | 442 op = simplified()->TruncateTaggedToWord32(); |
443 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { | 443 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { |
444 op = simplified()->CheckedTaggedToInt32(); | 444 op = simplified()->CheckedTaggedToInt32(); |
445 } | 445 } |
446 } else if (output_rep == MachineRepresentation::kWord32) { | 446 } else if (output_rep == MachineRepresentation::kWord32) { |
447 // Only the checked case should get here, the non-checked case is | 447 // Only the checked case should get here, the non-checked case is |
448 // handled in GetRepresentationFor. | 448 // handled in GetRepresentationFor. |
449 DCHECK(use_info.type_check() == TypeCheckKind::kSigned32); | 449 DCHECK(use_info.type_check() == TypeCheckKind::kSigned32); |
450 if (output_type->Is(Type::Signed32())) { | 450 if (output_type->Is(Type::Signed32())) { |
451 return node; | 451 return node; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 if (output_type->Is(Type::Unsigned32())) { | 536 if (output_type->Is(Type::Unsigned32())) { |
537 op = simplified()->CheckedUint32ToInt32(); | 537 op = simplified()->CheckedUint32ToInt32(); |
538 } | 538 } |
539 } else if (output_rep == MachineRepresentation::kBit) { | 539 } else if (output_rep == MachineRepresentation::kBit) { |
540 return node; // Sloppy comparison -> word32 | 540 return node; // Sloppy comparison -> word32 |
541 } else if (output_rep == MachineRepresentation::kFloat64) { | 541 } else if (output_rep == MachineRepresentation::kFloat64) { |
542 if (output_type->Is(Type::Unsigned32())) { | 542 if (output_type->Is(Type::Unsigned32())) { |
543 op = machine()->ChangeFloat64ToUint32(); | 543 op = machine()->ChangeFloat64ToUint32(); |
544 } else if (output_type->Is(Type::Signed32())) { | 544 } else if (output_type->Is(Type::Signed32())) { |
545 op = machine()->ChangeFloat64ToInt32(); | 545 op = machine()->ChangeFloat64ToInt32(); |
546 } else if (truncation.TruncatesToWord32()) { | 546 } else if (truncation.IsUsedAsWord32()) { |
547 op = machine()->TruncateFloat64ToWord32(); | 547 op = machine()->TruncateFloat64ToWord32(); |
548 } else if (check == TypeCheckKind::kSigned32) { | 548 } else if (check == TypeCheckKind::kSigned32) { |
549 op = simplified()->CheckedFloat64ToInt32(); | 549 op = simplified()->CheckedFloat64ToInt32(); |
550 } | 550 } |
551 } else if (output_rep == MachineRepresentation::kFloat32) { | 551 } else if (output_rep == MachineRepresentation::kFloat32) { |
552 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 | 552 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 |
553 if (output_type->Is(Type::Unsigned32())) { | 553 if (output_type->Is(Type::Unsigned32())) { |
554 op = machine()->ChangeFloat64ToUint32(); | 554 op = machine()->ChangeFloat64ToUint32(); |
555 } else if (output_type->Is(Type::Signed32())) { | 555 } else if (output_type->Is(Type::Signed32())) { |
556 op = machine()->ChangeFloat64ToInt32(); | 556 op = machine()->ChangeFloat64ToInt32(); |
557 } else if (truncation.TruncatesToWord32()) { | 557 } else if (truncation.IsUsedAsWord32()) { |
558 op = machine()->TruncateFloat64ToWord32(); | 558 op = machine()->TruncateFloat64ToWord32(); |
559 } else if (check == TypeCheckKind::kSigned32) { | 559 } else if (check == TypeCheckKind::kSigned32) { |
560 op = simplified()->CheckedFloat64ToInt32(); | 560 op = simplified()->CheckedFloat64ToInt32(); |
561 } | 561 } |
562 } else if (output_rep == MachineRepresentation::kTagged) { | 562 } else if (output_rep == MachineRepresentation::kTagged) { |
563 if (output_type->Is(Type::TaggedSigned())) { | 563 if (output_type->Is(Type::TaggedSigned())) { |
564 op = simplified()->ChangeTaggedSignedToInt32(); | 564 op = simplified()->ChangeTaggedSignedToInt32(); |
565 } else if (output_type->Is(Type::Unsigned32())) { | 565 } else if (output_type->Is(Type::Unsigned32())) { |
566 op = simplified()->ChangeTaggedToUint32(); | 566 op = simplified()->ChangeTaggedToUint32(); |
567 } else if (output_type->Is(Type::Signed32())) { | 567 } else if (output_type->Is(Type::Signed32())) { |
568 op = simplified()->ChangeTaggedToInt32(); | 568 op = simplified()->ChangeTaggedToInt32(); |
569 } else if (truncation.TruncatesToWord32()) { | 569 } else if (truncation.IsUsedAsWord32()) { |
570 op = simplified()->TruncateTaggedToWord32(); | 570 op = simplified()->TruncateTaggedToWord32(); |
571 } else if (check == TypeCheckKind::kSigned32) { | 571 } else if (check == TypeCheckKind::kSigned32) { |
572 op = simplified()->CheckedTaggedToInt32(); | 572 op = simplified()->CheckedTaggedToInt32(); |
573 } | 573 } |
574 } | 574 } |
575 if (op == nullptr) { | 575 if (op == nullptr) { |
576 return TypeError(node, output_rep, output_type, | 576 return TypeError(node, output_rep, output_type, |
577 MachineRepresentation::kWord32); | 577 MachineRepresentation::kWord32); |
578 } | 578 } |
579 if (op->ControlInputCount() > 0) { | 579 if (op->ControlInputCount() > 0) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 814 } |
815 | 815 |
816 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 816 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
817 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 817 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
818 node); | 818 node); |
819 } | 819 } |
820 | 820 |
821 } // namespace compiler | 821 } // namespace compiler |
822 } // namespace internal | 822 } // namespace internal |
823 } // namespace v8 | 823 } // namespace v8 |
OLD | NEW |