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 "test/unittests/compiler/graph-unittest.h" | 5 #include "test/unittests/compiler/graph-unittest.h" |
6 | 6 |
7 #include <ostream> // NOLINT(readability/streams) | 7 #include <ostream> // NOLINT(readability/streams) |
8 | 8 |
9 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
10 #include "src/compiler/simplified-operator.h" | |
11 | 10 |
12 using testing::_; | 11 using testing::_; |
13 using testing::MakeMatcher; | 12 using testing::MakeMatcher; |
14 using testing::MatcherInterface; | 13 using testing::MatcherInterface; |
15 using testing::MatchResultListener; | 14 using testing::MatchResultListener; |
16 using testing::StringMatchResultListener; | 15 using testing::StringMatchResultListener; |
17 | 16 |
18 namespace v8 { | 17 namespace v8 { |
19 namespace internal { | 18 namespace internal { |
20 | 19 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 Node* GraphTest::Int64Constant(int64_t value) { | 61 Node* GraphTest::Int64Constant(int64_t value) { |
63 return graph()->NewNode(common()->Int64Constant(value)); | 62 return graph()->NewNode(common()->Int64Constant(value)); |
64 } | 63 } |
65 | 64 |
66 | 65 |
67 Node* GraphTest::NumberConstant(volatile double value) { | 66 Node* GraphTest::NumberConstant(volatile double value) { |
68 return graph()->NewNode(common()->NumberConstant(value)); | 67 return graph()->NewNode(common()->NumberConstant(value)); |
69 } | 68 } |
70 | 69 |
71 | 70 |
72 Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) { | |
73 return HeapConstant(Unique<HeapObject>::CreateUninitialized(value)); | |
74 } | |
75 | |
76 | |
77 Node* GraphTest::HeapConstant(const Unique<HeapObject>& value) { | 71 Node* GraphTest::HeapConstant(const Unique<HeapObject>& value) { |
78 Node* node = graph()->NewNode(common()->HeapConstant(value)); | 72 return graph()->NewNode(common()->HeapConstant(value)); |
79 Type* type = Type::Constant(value.handle(), zone()); | |
80 NodeProperties::SetBounds(node, Bounds(type)); | |
81 return node; | |
82 } | 73 } |
83 | 74 |
84 | 75 |
85 Node* GraphTest::FalseConstant() { | 76 Node* GraphTest::FalseConstant() { |
86 return HeapConstant( | 77 return HeapConstant( |
87 Unique<HeapObject>::CreateImmovable(factory()->false_value())); | 78 Unique<HeapObject>::CreateImmovable(factory()->false_value())); |
88 } | 79 } |
89 | 80 |
90 | 81 |
91 Node* GraphTest::TrueConstant() { | 82 Node* GraphTest::TrueConstant() { |
92 return HeapConstant( | 83 return HeapConstant( |
93 Unique<HeapObject>::CreateImmovable(factory()->true_value())); | 84 Unique<HeapObject>::CreateImmovable(factory()->true_value())); |
94 } | 85 } |
95 | 86 |
96 | 87 |
97 Node* GraphTest::UndefinedConstant() { | |
98 return HeapConstant( | |
99 Unique<HeapObject>::CreateImmovable(factory()->undefined_value())); | |
100 } | |
101 | |
102 | |
103 Matcher<Node*> GraphTest::IsFalseConstant() { | 88 Matcher<Node*> GraphTest::IsFalseConstant() { |
104 return IsHeapConstant( | 89 return IsHeapConstant( |
105 Unique<HeapObject>::CreateImmovable(factory()->false_value())); | 90 Unique<HeapObject>::CreateImmovable(factory()->false_value())); |
106 } | 91 } |
107 | 92 |
108 | 93 |
109 Matcher<Node*> GraphTest::IsTrueConstant() { | 94 Matcher<Node*> GraphTest::IsTrueConstant() { |
110 return IsHeapConstant( | 95 return IsHeapConstant( |
111 Unique<HeapObject>::CreateImmovable(factory()->true_value())); | 96 Unique<HeapObject>::CreateImmovable(factory()->true_value())); |
112 } | 97 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 const Matcher<CallDescriptor*> descriptor_matcher_; | 423 const Matcher<CallDescriptor*> descriptor_matcher_; |
439 const Matcher<Node*> value0_matcher_; | 424 const Matcher<Node*> value0_matcher_; |
440 const Matcher<Node*> value1_matcher_; | 425 const Matcher<Node*> value1_matcher_; |
441 const Matcher<Node*> value2_matcher_; | 426 const Matcher<Node*> value2_matcher_; |
442 const Matcher<Node*> value3_matcher_; | 427 const Matcher<Node*> value3_matcher_; |
443 const Matcher<Node*> effect_matcher_; | 428 const Matcher<Node*> effect_matcher_; |
444 const Matcher<Node*> control_matcher_; | 429 const Matcher<Node*> control_matcher_; |
445 }; | 430 }; |
446 | 431 |
447 | 432 |
448 class IsLoadFieldMatcher FINAL : public NodeMatcher { | |
449 public: | |
450 IsLoadFieldMatcher(const Matcher<FieldAccess>& access_matcher, | |
451 const Matcher<Node*>& base_matcher, | |
452 const Matcher<Node*>& effect_matcher) | |
453 : NodeMatcher(IrOpcode::kLoadField), | |
454 access_matcher_(access_matcher), | |
455 base_matcher_(base_matcher), | |
456 effect_matcher_(effect_matcher) {} | |
457 | |
458 virtual void DescribeTo(std::ostream* os) const OVERRIDE { | |
459 NodeMatcher::DescribeTo(os); | |
460 *os << " whose access ("; | |
461 access_matcher_.DescribeTo(os); | |
462 *os << "), base ("; | |
463 base_matcher_.DescribeTo(os); | |
464 *os << ") and effect ("; | |
465 effect_matcher_.DescribeTo(os); | |
466 *os << ")"; | |
467 } | |
468 | |
469 virtual bool MatchAndExplain(Node* node, | |
470 MatchResultListener* listener) const OVERRIDE { | |
471 return (NodeMatcher::MatchAndExplain(node, listener) && | |
472 PrintMatchAndExplain(OpParameter<FieldAccess>(node), "access", | |
473 access_matcher_, listener) && | |
474 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", | |
475 base_matcher_, listener) && | |
476 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | |
477 effect_matcher_, listener)); | |
478 } | |
479 | |
480 private: | |
481 const Matcher<FieldAccess> access_matcher_; | |
482 const Matcher<Node*> base_matcher_; | |
483 const Matcher<Node*> effect_matcher_; | |
484 }; | |
485 | |
486 | |
487 class IsLoadElementMatcher FINAL : public NodeMatcher { | |
488 public: | |
489 IsLoadElementMatcher(const Matcher<ElementAccess>& access_matcher, | |
490 const Matcher<Node*>& base_matcher, | |
491 const Matcher<Node*>& index_matcher, | |
492 const Matcher<Node*>& length_matcher, | |
493 const Matcher<Node*>& effect_matcher, | |
494 const Matcher<Node*>& control_matcher) | |
495 : NodeMatcher(IrOpcode::kLoadElement), | |
496 access_matcher_(access_matcher), | |
497 base_matcher_(base_matcher), | |
498 index_matcher_(index_matcher), | |
499 length_matcher_(length_matcher), | |
500 effect_matcher_(effect_matcher), | |
501 control_matcher_(control_matcher) {} | |
502 | |
503 virtual void DescribeTo(std::ostream* os) const OVERRIDE { | |
504 NodeMatcher::DescribeTo(os); | |
505 *os << " whose access ("; | |
506 access_matcher_.DescribeTo(os); | |
507 *os << "), base ("; | |
508 base_matcher_.DescribeTo(os); | |
509 *os << "), index ("; | |
510 index_matcher_.DescribeTo(os); | |
511 *os << "), length ("; | |
512 length_matcher_.DescribeTo(os); | |
513 *os << "), effect ("; | |
514 effect_matcher_.DescribeTo(os); | |
515 *os << ") and control ("; | |
516 control_matcher_.DescribeTo(os); | |
517 *os << ")"; | |
518 } | |
519 | |
520 virtual bool MatchAndExplain(Node* node, | |
521 MatchResultListener* listener) const OVERRIDE { | |
522 return (NodeMatcher::MatchAndExplain(node, listener) && | |
523 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access", | |
524 access_matcher_, listener) && | |
525 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", | |
526 base_matcher_, listener) && | |
527 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), | |
528 "index", index_matcher_, listener) && | |
529 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), | |
530 "length", length_matcher_, listener) && | |
531 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | |
532 effect_matcher_, listener) && | |
533 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | |
534 "control", control_matcher_, listener)); | |
535 } | |
536 | |
537 private: | |
538 const Matcher<ElementAccess> access_matcher_; | |
539 const Matcher<Node*> base_matcher_; | |
540 const Matcher<Node*> index_matcher_; | |
541 const Matcher<Node*> length_matcher_; | |
542 const Matcher<Node*> effect_matcher_; | |
543 const Matcher<Node*> control_matcher_; | |
544 }; | |
545 | |
546 | |
547 class IsStoreElementMatcher FINAL : public NodeMatcher { | |
548 public: | |
549 IsStoreElementMatcher(const Matcher<ElementAccess>& access_matcher, | |
550 const Matcher<Node*>& base_matcher, | |
551 const Matcher<Node*>& index_matcher, | |
552 const Matcher<Node*>& length_matcher, | |
553 const Matcher<Node*>& value_matcher, | |
554 const Matcher<Node*>& effect_matcher, | |
555 const Matcher<Node*>& control_matcher) | |
556 : NodeMatcher(IrOpcode::kStoreElement), | |
557 access_matcher_(access_matcher), | |
558 base_matcher_(base_matcher), | |
559 index_matcher_(index_matcher), | |
560 length_matcher_(length_matcher), | |
561 value_matcher_(value_matcher), | |
562 effect_matcher_(effect_matcher), | |
563 control_matcher_(control_matcher) {} | |
564 | |
565 virtual void DescribeTo(std::ostream* os) const OVERRIDE { | |
566 NodeMatcher::DescribeTo(os); | |
567 *os << " whose access ("; | |
568 access_matcher_.DescribeTo(os); | |
569 *os << "), base ("; | |
570 base_matcher_.DescribeTo(os); | |
571 *os << "), index ("; | |
572 index_matcher_.DescribeTo(os); | |
573 *os << "), length ("; | |
574 length_matcher_.DescribeTo(os); | |
575 *os << "), value ("; | |
576 value_matcher_.DescribeTo(os); | |
577 *os << "), effect ("; | |
578 effect_matcher_.DescribeTo(os); | |
579 *os << ") and control ("; | |
580 control_matcher_.DescribeTo(os); | |
581 *os << ")"; | |
582 } | |
583 | |
584 virtual bool MatchAndExplain(Node* node, | |
585 MatchResultListener* listener) const OVERRIDE { | |
586 return (NodeMatcher::MatchAndExplain(node, listener) && | |
587 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access", | |
588 access_matcher_, listener) && | |
589 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", | |
590 base_matcher_, listener) && | |
591 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), | |
592 "index", index_matcher_, listener) && | |
593 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), | |
594 "length", length_matcher_, listener) && | |
595 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3), | |
596 "value", value_matcher_, listener) && | |
597 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | |
598 effect_matcher_, listener) && | |
599 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | |
600 "control", control_matcher_, listener)); | |
601 } | |
602 | |
603 private: | |
604 const Matcher<ElementAccess> access_matcher_; | |
605 const Matcher<Node*> base_matcher_; | |
606 const Matcher<Node*> index_matcher_; | |
607 const Matcher<Node*> length_matcher_; | |
608 const Matcher<Node*> value_matcher_; | |
609 const Matcher<Node*> effect_matcher_; | |
610 const Matcher<Node*> control_matcher_; | |
611 }; | |
612 | |
613 | |
614 class IsLoadMatcher FINAL : public NodeMatcher { | 433 class IsLoadMatcher FINAL : public NodeMatcher { |
615 public: | 434 public: |
616 IsLoadMatcher(const Matcher<LoadRepresentation>& rep_matcher, | 435 IsLoadMatcher(const Matcher<LoadRepresentation>& rep_matcher, |
617 const Matcher<Node*>& base_matcher, | 436 const Matcher<Node*>& base_matcher, |
618 const Matcher<Node*>& index_matcher, | 437 const Matcher<Node*>& index_matcher, |
619 const Matcher<Node*>& effect_matcher, | 438 const Matcher<Node*>& effect_matcher, |
620 const Matcher<Node*>& control_matcher) | 439 const Matcher<Node*>& control_matcher) |
621 : NodeMatcher(IrOpcode::kLoad), | 440 : NodeMatcher(IrOpcode::kLoad), |
622 rep_matcher_(rep_matcher), | 441 rep_matcher_(rep_matcher), |
623 base_matcher_(base_matcher), | 442 base_matcher_(base_matcher), |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 const Matcher<Node*>& value2_matcher, | 708 const Matcher<Node*>& value2_matcher, |
890 const Matcher<Node*>& value3_matcher, | 709 const Matcher<Node*>& value3_matcher, |
891 const Matcher<Node*>& effect_matcher, | 710 const Matcher<Node*>& effect_matcher, |
892 const Matcher<Node*>& control_matcher) { | 711 const Matcher<Node*>& control_matcher) { |
893 return MakeMatcher(new IsCallMatcher( | 712 return MakeMatcher(new IsCallMatcher( |
894 descriptor_matcher, value0_matcher, value1_matcher, value2_matcher, | 713 descriptor_matcher, value0_matcher, value1_matcher, value2_matcher, |
895 value3_matcher, effect_matcher, control_matcher)); | 714 value3_matcher, effect_matcher, control_matcher)); |
896 } | 715 } |
897 | 716 |
898 | 717 |
899 Matcher<Node*> IsLoadField(const Matcher<FieldAccess>& access_matcher, | |
900 const Matcher<Node*>& base_matcher, | |
901 const Matcher<Node*>& effect_matcher) { | |
902 return MakeMatcher( | |
903 new IsLoadFieldMatcher(access_matcher, base_matcher, effect_matcher)); | |
904 } | |
905 | |
906 | |
907 Matcher<Node*> IsLoadElement(const Matcher<ElementAccess>& access_matcher, | |
908 const Matcher<Node*>& base_matcher, | |
909 const Matcher<Node*>& index_matcher, | |
910 const Matcher<Node*>& length_matcher, | |
911 const Matcher<Node*>& effect_matcher, | |
912 const Matcher<Node*>& control_matcher) { | |
913 return MakeMatcher(new IsLoadElementMatcher(access_matcher, base_matcher, | |
914 index_matcher, length_matcher, | |
915 effect_matcher, control_matcher)); | |
916 } | |
917 | |
918 | |
919 Matcher<Node*> IsStoreElement(const Matcher<ElementAccess>& access_matcher, | |
920 const Matcher<Node*>& base_matcher, | |
921 const Matcher<Node*>& index_matcher, | |
922 const Matcher<Node*>& length_matcher, | |
923 const Matcher<Node*>& value_matcher, | |
924 const Matcher<Node*>& effect_matcher, | |
925 const Matcher<Node*>& control_matcher) { | |
926 return MakeMatcher(new IsStoreElementMatcher( | |
927 access_matcher, base_matcher, index_matcher, length_matcher, | |
928 value_matcher, effect_matcher, control_matcher)); | |
929 } | |
930 | |
931 | |
932 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher, | 718 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher, |
933 const Matcher<Node*>& base_matcher, | 719 const Matcher<Node*>& base_matcher, |
934 const Matcher<Node*>& index_matcher, | 720 const Matcher<Node*>& index_matcher, |
935 const Matcher<Node*>& effect_matcher, | 721 const Matcher<Node*>& effect_matcher, |
936 const Matcher<Node*>& control_matcher) { | 722 const Matcher<Node*>& control_matcher) { |
937 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher, | 723 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher, |
938 effect_matcher, control_matcher)); | 724 effect_matcher, control_matcher)); |
939 } | 725 } |
940 | 726 |
941 | 727 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 IS_UNOP_MATCHER(ChangeUint32ToUint64) | 773 IS_UNOP_MATCHER(ChangeUint32ToUint64) |
988 IS_UNOP_MATCHER(TruncateFloat64ToFloat32) | 774 IS_UNOP_MATCHER(TruncateFloat64ToFloat32) |
989 IS_UNOP_MATCHER(TruncateFloat64ToInt32) | 775 IS_UNOP_MATCHER(TruncateFloat64ToInt32) |
990 IS_UNOP_MATCHER(TruncateInt64ToInt32) | 776 IS_UNOP_MATCHER(TruncateInt64ToInt32) |
991 IS_UNOP_MATCHER(Float64Sqrt) | 777 IS_UNOP_MATCHER(Float64Sqrt) |
992 #undef IS_UNOP_MATCHER | 778 #undef IS_UNOP_MATCHER |
993 | 779 |
994 } // namespace compiler | 780 } // namespace compiler |
995 } // namespace internal | 781 } // namespace internal |
996 } // namespace v8 | 782 } // namespace v8 |
OLD | NEW |