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/compilation-dependencies.h" | 5 #include "src/compilation-dependencies.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-typed-lowering.h" | 7 #include "src/compiler/js-typed-lowering.h" |
8 #include "src/compiler/machine-operator.h" | 8 #include "src/compiler/machine-operator.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const Operator* unop; | 44 const Operator* unop; |
45 JSOperatorBuilder javascript; | 45 JSOperatorBuilder javascript; |
46 MachineOperatorBuilder machine; | 46 MachineOperatorBuilder machine; |
47 SimplifiedOperatorBuilder simplified; | 47 SimplifiedOperatorBuilder simplified; |
48 CommonOperatorBuilder common; | 48 CommonOperatorBuilder common; |
49 CompilationDependencies deps; | 49 CompilationDependencies deps; |
50 Graph graph; | 50 Graph graph; |
51 Typer typer; | 51 Typer typer; |
52 Node* context_node; | 52 Node* context_node; |
53 JSTypedLowering::Flags flags; | 53 JSTypedLowering::Flags flags; |
54 BinaryOperationHints const binop_hints = BinaryOperationHints::Any(); | 54 BinaryOperationHint const binop_hints = BinaryOperationHint::kAny; |
55 CompareOperationHints const compare_hints = CompareOperationHints::Any(); | 55 CompareOperationHint const compare_hints = CompareOperationHint::kAny; |
56 | 56 |
57 Node* Parameter(Type* t, int32_t index = 0) { | 57 Node* Parameter(Type* t, int32_t index = 0) { |
58 Node* n = graph.NewNode(common.Parameter(index), graph.start()); | 58 Node* n = graph.NewNode(common.Parameter(index), graph.start()); |
59 NodeProperties::SetType(n, t); | 59 NodeProperties::SetType(n, t); |
60 return n; | 60 return n; |
61 } | 61 } |
62 | 62 |
63 Node* UndefinedConstant() { | 63 Node* UndefinedConstant() { |
64 Handle<HeapObject> value = isolate->factory()->undefined_value(); | 64 Handle<HeapObject> value = isolate->factory()->undefined_value(); |
65 return graph.NewNode(common.HeapConstant(value)); | 65 return graph.NewNode(common.HeapConstant(value)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 #endif | 243 #endif |
244 | 244 |
245 TEST(AddNumber1) { | 245 TEST(AddNumber1) { |
246 JSTypedLoweringTester R; | 246 JSTypedLoweringTester R; |
247 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) { | 247 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) { |
248 Node* p0 = R.Parameter(kNumberTypes[i], 0); | 248 Node* p0 = R.Parameter(kNumberTypes[i], 0); |
249 Node* p1 = R.Parameter(kNumberTypes[i], 1); | 249 Node* p1 = R.Parameter(kNumberTypes[i], 1); |
250 Node* add = R.Binop(R.javascript.Add(BinaryOperationHints::Any()), p0, p1); | 250 Node* add = R.Binop(R.javascript.Add(BinaryOperationHint::kAny), p0, p1); |
251 Node* r = R.reduce(add); | 251 Node* r = R.reduce(add); |
252 | 252 |
253 R.CheckBinop(IrOpcode::kNumberAdd, r); | 253 R.CheckBinop(IrOpcode::kNumberAdd, r); |
254 CHECK_EQ(p0, r->InputAt(0)); | 254 CHECK_EQ(p0, r->InputAt(0)); |
255 CHECK_EQ(p1, r->InputAt(1)); | 255 CHECK_EQ(p1, r->InputAt(1)); |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 TEST(NumberBinops) { | 259 TEST(NumberBinops) { |
260 JSTypedLoweringTester R; | 260 JSTypedLoweringTester R; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 CHECK_EQ(n, add->InputAt(0)); | 568 CHECK_EQ(n, add->InputAt(0)); |
569 CHECK_EQ(r, add->InputAt(1)); | 569 CHECK_EQ(r, add->InputAt(1)); |
570 R.CheckEffectInput(R.start(), effect_use); | 570 R.CheckEffectInput(R.start(), effect_use); |
571 } | 571 } |
572 } | 572 } |
573 | 573 |
574 TEST(StringComparison) { | 574 TEST(StringComparison) { |
575 JSTypedLoweringTester R; | 575 JSTypedLoweringTester R; |
576 | 576 |
577 const Operator* ops[] = { | 577 const Operator* ops[] = { |
578 R.javascript.LessThan(CompareOperationHints::Any()), | 578 R.javascript.LessThan(CompareOperationHint::kAny), |
579 R.simplified.StringLessThan(), | 579 R.simplified.StringLessThan(), |
580 R.javascript.LessThanOrEqual(CompareOperationHints::Any()), | 580 R.javascript.LessThanOrEqual(CompareOperationHint::kAny), |
581 R.simplified.StringLessThanOrEqual(), | 581 R.simplified.StringLessThanOrEqual(), |
582 R.javascript.GreaterThan(CompareOperationHints::Any()), | 582 R.javascript.GreaterThan(CompareOperationHint::kAny), |
583 R.simplified.StringLessThan(), | 583 R.simplified.StringLessThan(), |
584 R.javascript.GreaterThanOrEqual(CompareOperationHints::Any()), | 584 R.javascript.GreaterThanOrEqual(CompareOperationHint::kAny), |
585 R.simplified.StringLessThanOrEqual()}; | 585 R.simplified.StringLessThanOrEqual()}; |
586 | 586 |
587 for (size_t i = 0; i < arraysize(kStringTypes); i++) { | 587 for (size_t i = 0; i < arraysize(kStringTypes); i++) { |
588 Node* p0 = R.Parameter(kStringTypes[i], 0); | 588 Node* p0 = R.Parameter(kStringTypes[i], 0); |
589 for (size_t j = 0; j < arraysize(kStringTypes); j++) { | 589 for (size_t j = 0; j < arraysize(kStringTypes); j++) { |
590 Node* p1 = R.Parameter(kStringTypes[j], 1); | 590 Node* p1 = R.Parameter(kStringTypes[j], 1); |
591 | 591 |
592 for (size_t k = 0; k < arraysize(ops); k += 2) { | 592 for (size_t k = 0; k < arraysize(ops); k += 2) { |
593 Node* cmp = R.Binop(ops[k], p0, p1); | 593 Node* cmp = R.Binop(ops[k], p0, p1); |
594 Node* r = R.reduce(cmp); | 594 Node* r = R.reduce(cmp); |
(...skipping 21 matching lines...) Expand all Loading... |
616 if (converted->opcode() == IrOpcode::kNumberConstant) return; | 616 if (converted->opcode() == IrOpcode::kNumberConstant) return; |
617 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode()); | 617 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode()); |
618 CHECK_EQ(val, converted->InputAt(0)); | 618 CHECK_EQ(val, converted->InputAt(0)); |
619 } | 619 } |
620 } | 620 } |
621 | 621 |
622 TEST(NumberComparison) { | 622 TEST(NumberComparison) { |
623 JSTypedLoweringTester R; | 623 JSTypedLoweringTester R; |
624 | 624 |
625 const Operator* ops[] = { | 625 const Operator* ops[] = { |
626 R.javascript.LessThan(CompareOperationHints::Any()), | 626 R.javascript.LessThan(CompareOperationHint::kAny), |
627 R.simplified.NumberLessThan(), | 627 R.simplified.NumberLessThan(), |
628 R.javascript.LessThanOrEqual(CompareOperationHints::Any()), | 628 R.javascript.LessThanOrEqual(CompareOperationHint::kAny), |
629 R.simplified.NumberLessThanOrEqual(), | 629 R.simplified.NumberLessThanOrEqual(), |
630 R.javascript.GreaterThan(CompareOperationHints::Any()), | 630 R.javascript.GreaterThan(CompareOperationHint::kAny), |
631 R.simplified.NumberLessThan(), | 631 R.simplified.NumberLessThan(), |
632 R.javascript.GreaterThanOrEqual(CompareOperationHints::Any()), | 632 R.javascript.GreaterThanOrEqual(CompareOperationHint::kAny), |
633 R.simplified.NumberLessThanOrEqual()}; | 633 R.simplified.NumberLessThanOrEqual()}; |
634 | 634 |
635 Node* const p0 = R.Parameter(Type::Number(), 0); | 635 Node* const p0 = R.Parameter(Type::Number(), 0); |
636 Node* const p1 = R.Parameter(Type::Number(), 1); | 636 Node* const p1 = R.Parameter(Type::Number(), 1); |
637 | 637 |
638 for (size_t k = 0; k < arraysize(ops); k += 2) { | 638 for (size_t k = 0; k < arraysize(ops); k += 2) { |
639 Node* cmp = R.Binop(ops[k], p0, p1); | 639 Node* cmp = R.Binop(ops[k], p0, p1); |
640 Node* r = R.reduce(cmp); | 640 Node* r = R.reduce(cmp); |
641 | 641 |
642 R.CheckBinop(ops[k + 1], r); | 642 R.CheckBinop(ops[k + 1], r); |
(...skipping 15 matching lines...) Expand all Loading... |
658 Type* types[] = {Type::Number(), Type::String(), | 658 Type* types[] = {Type::Number(), Type::String(), |
659 Type::Union(Type::Number(), Type::String(), R.main_zone())}; | 659 Type::Union(Type::Number(), Type::String(), R.main_zone())}; |
660 | 660 |
661 for (size_t i = 0; i < arraysize(types); i++) { | 661 for (size_t i = 0; i < arraysize(types); i++) { |
662 Node* p0 = R.Parameter(types[i], 0); | 662 Node* p0 = R.Parameter(types[i], 0); |
663 | 663 |
664 for (size_t j = 0; j < arraysize(types); j++) { | 664 for (size_t j = 0; j < arraysize(types); j++) { |
665 Node* p1 = R.Parameter(types[j], 1); | 665 Node* p1 = R.Parameter(types[j], 1); |
666 { | 666 { |
667 const Operator* less_than = | 667 const Operator* less_than = |
668 R.javascript.LessThan(CompareOperationHints::Any()); | 668 R.javascript.LessThan(CompareOperationHint::kAny); |
669 Node* cmp = R.Binop(less_than, p0, p1); | 669 Node* cmp = R.Binop(less_than, p0, p1); |
670 Node* r = R.reduce(cmp); | 670 Node* r = R.reduce(cmp); |
671 if (types[i]->Is(Type::String()) && types[j]->Is(Type::String())) { | 671 if (types[i]->Is(Type::String()) && types[j]->Is(Type::String())) { |
672 R.CheckBinop(R.simplified.StringLessThan(), r); | 672 R.CheckBinop(R.simplified.StringLessThan(), r); |
673 } else if ((types[i]->Is(Type::Number()) && | 673 } else if ((types[i]->Is(Type::Number()) && |
674 types[j]->Is(Type::Number())) || | 674 types[j]->Is(Type::Number())) || |
675 (!types[i]->Maybe(Type::String()) || | 675 (!types[i]->Maybe(Type::String()) || |
676 !types[j]->Maybe(Type::String()))) { | 676 !types[j]->Maybe(Type::String()))) { |
677 R.CheckBinop(R.simplified.NumberLessThan(), r); | 677 R.CheckBinop(R.simplified.NumberLessThan(), r); |
678 } else { | 678 } else { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 | 804 |
805 // Helper function for strict and non-strict equality reductions. | 805 // Helper function for strict and non-strict equality reductions. |
806 void CheckEqualityReduction(JSTypedLoweringTester* R, bool strict, Node* l, | 806 void CheckEqualityReduction(JSTypedLoweringTester* R, bool strict, Node* l, |
807 Node* r, IrOpcode::Value expected) { | 807 Node* r, IrOpcode::Value expected) { |
808 for (int j = 0; j < 2; j++) { | 808 for (int j = 0; j < 2; j++) { |
809 Node* p0 = j == 0 ? l : r; | 809 Node* p0 = j == 0 ? l : r; |
810 Node* p1 = j == 1 ? l : r; | 810 Node* p1 = j == 1 ? l : r; |
811 | 811 |
812 { | 812 { |
813 const Operator* op = | 813 const Operator* op = |
814 strict ? R->javascript.StrictEqual(CompareOperationHints::Any()) | 814 strict ? R->javascript.StrictEqual(CompareOperationHint::kAny) |
815 : R->javascript.Equal(CompareOperationHints::Any()); | 815 : R->javascript.Equal(CompareOperationHint::kAny); |
816 Node* eq = R->Binop(op, p0, p1); | 816 Node* eq = R->Binop(op, p0, p1); |
817 Node* r = R->reduce(eq); | 817 Node* r = R->reduce(eq); |
818 R->CheckBinop(expected, r); | 818 R->CheckBinop(expected, r); |
819 } | 819 } |
820 | 820 |
821 { | 821 { |
822 const Operator* op = | 822 const Operator* op = |
823 strict ? R->javascript.StrictNotEqual(CompareOperationHints::Any()) | 823 strict ? R->javascript.StrictNotEqual(CompareOperationHint::kAny) |
824 : R->javascript.NotEqual(CompareOperationHints::Any()); | 824 : R->javascript.NotEqual(CompareOperationHint::kAny); |
825 Node* ne = R->Binop(op, p0, p1); | 825 Node* ne = R->Binop(op, p0, p1); |
826 Node* n = R->reduce(ne); | 826 Node* n = R->reduce(ne); |
827 CHECK_EQ(IrOpcode::kBooleanNot, n->opcode()); | 827 CHECK_EQ(IrOpcode::kBooleanNot, n->opcode()); |
828 Node* r = n->InputAt(0); | 828 Node* r = n->InputAt(0); |
829 R->CheckBinop(expected, r); | 829 R->CheckBinop(expected, r); |
830 } | 830 } |
831 } | 831 } |
832 } | 832 } |
833 | 833 |
834 | 834 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 CHECK_EQ(p1, r->InputAt(1)); | 1236 CHECK_EQ(p1, r->InputAt(1)); |
1237 } | 1237 } |
1238 } | 1238 } |
1239 } | 1239 } |
1240 } | 1240 } |
1241 } | 1241 } |
1242 | 1242 |
1243 } // namespace compiler | 1243 } // namespace compiler |
1244 } // namespace internal | 1244 } // namespace internal |
1245 } // namespace v8 | 1245 } // namespace v8 |
OLD | NEW |