| 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
| 8 #include "src/compiler/change-lowering.h" | 8 #include "src/compiler/change-lowering.h" |
| 9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
| 10 #include "src/compiler/graph-reducer.h" | 10 #include "src/compiler/graph-reducer.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 template <typename ReturnType> | 30 template <typename ReturnType> |
| 31 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { | 31 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { |
| 32 public: | 32 public: |
| 33 SimplifiedLoweringTester(MachineType p0 = kMachNone, | 33 SimplifiedLoweringTester(MachineType p0 = kMachNone, |
| 34 MachineType p1 = kMachNone, | 34 MachineType p1 = kMachNone, |
| 35 MachineType p2 = kMachNone, | 35 MachineType p2 = kMachNone, |
| 36 MachineType p3 = kMachNone, | 36 MachineType p3 = kMachNone, |
| 37 MachineType p4 = kMachNone) | 37 MachineType p4 = kMachNone) |
| 38 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), | 38 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), |
| 39 typer(this->graph(), MaybeHandle<Context>()), | 39 typer(this->isolate(), this->graph(), MaybeHandle<Context>()), |
| 40 javascript(this->zone()), | 40 javascript(this->zone()), |
| 41 jsgraph(this->graph(), this->common(), &javascript, this->machine()), | 41 jsgraph(this->isolate(), this->graph(), this->common(), &javascript, |
| 42 this->machine()), |
| 42 lowering(&jsgraph, this->zone()) {} | 43 lowering(&jsgraph, this->zone()) {} |
| 43 | 44 |
| 44 Typer typer; | 45 Typer typer; |
| 45 JSOperatorBuilder javascript; | 46 JSOperatorBuilder javascript; |
| 46 JSGraph jsgraph; | 47 JSGraph jsgraph; |
| 47 SimplifiedLowering lowering; | 48 SimplifiedLowering lowering; |
| 48 | 49 |
| 49 void LowerAllNodes() { | 50 void LowerAllNodes() { |
| 50 this->End(); | 51 this->End(); |
| 51 typer.Run(); | 52 typer.Run(); |
| 52 lowering.LowerAllNodes(); | 53 lowering.LowerAllNodes(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void LowerAllNodesAndLowerChanges() { | 56 void LowerAllNodesAndLowerChanges() { |
| 56 this->End(); | 57 this->End(); |
| 57 typer.Run(); | 58 typer.Run(); |
| 58 lowering.LowerAllNodes(); | 59 lowering.LowerAllNodes(); |
| 59 | 60 |
| 60 Zone* zone = this->zone(); | 61 Zone* zone = this->zone(); |
| 61 CompilationInfo info(zone->isolate(), zone); | 62 CompilationInfo info(this->isolate(), zone); |
| 62 Linkage linkage( | 63 Linkage linkage(this->isolate(), zone, Linkage::GetSimplifiedCDescriptor( |
| 63 zone, Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_)); | 64 zone, this->machine_sig_)); |
| 64 ChangeLowering lowering(&jsgraph, &linkage); | 65 ChangeLowering lowering(&jsgraph, &linkage); |
| 65 GraphReducer reducer(this->graph(), this->zone()); | 66 GraphReducer reducer(this->graph(), this->zone()); |
| 66 reducer.AddReducer(&lowering); | 67 reducer.AddReducer(&lowering); |
| 67 reducer.ReduceGraph(); | 68 reducer.ReduceGraph(); |
| 68 Verifier::Run(this->graph()); | 69 Verifier::Run(this->graph()); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void CheckNumberCall(double expected, double input) { | 72 void CheckNumberCall(double expected, double input) { |
| 72 // TODO(titzer): make calls to NewNumber work in cctests. | 73 // TODO(titzer): make calls to NewNumber work in cctests. |
| 73 if (expected <= Smi::kMinValue) return; | 74 if (expected <= Smi::kMinValue) return; |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 Node* p0; | 660 Node* p0; |
| 660 Node* p1; | 661 Node* p1; |
| 661 Node* p2; | 662 Node* p2; |
| 662 Node* start; | 663 Node* start; |
| 663 Node* end; | 664 Node* end; |
| 664 Node* ret; | 665 Node* ret; |
| 665 | 666 |
| 666 explicit TestingGraph(Type* p0_type, Type* p1_type = Type::None(), | 667 explicit TestingGraph(Type* p0_type, Type* p1_type = Type::None(), |
| 667 Type* p2_type = Type::None()) | 668 Type* p2_type = Type::None()) |
| 668 : GraphAndBuilders(main_zone()), | 669 : GraphAndBuilders(main_zone()), |
| 669 typer(graph(), MaybeHandle<Context>()), | 670 typer(main_isolate(), graph(), MaybeHandle<Context>()), |
| 670 javascript(main_zone()), | 671 javascript(main_zone()), |
| 671 jsgraph(graph(), common(), &javascript, machine()) { | 672 jsgraph(main_isolate(), graph(), common(), &javascript, machine()) { |
| 672 start = graph()->NewNode(common()->Start(2)); | 673 start = graph()->NewNode(common()->Start(2)); |
| 673 graph()->SetStart(start); | 674 graph()->SetStart(start); |
| 674 ret = | 675 ret = |
| 675 graph()->NewNode(common()->Return(), jsgraph.Constant(0), start, start); | 676 graph()->NewNode(common()->Return(), jsgraph.Constant(0), start, start); |
| 676 end = graph()->NewNode(common()->End(), ret); | 677 end = graph()->NewNode(common()->End(), ret); |
| 677 graph()->SetEnd(end); | 678 graph()->SetEnd(end); |
| 678 p0 = graph()->NewNode(common()->Parameter(0), start); | 679 p0 = graph()->NewNode(common()->Parameter(0), start); |
| 679 p1 = graph()->NewNode(common()->Parameter(1), start); | 680 p1 = graph()->NewNode(common()->Parameter(1), start); |
| 680 p2 = graph()->NewNode(common()->Parameter(2), start); | 681 p2 = graph()->NewNode(common()->Parameter(2), start); |
| 681 typer.Run(); | 682 typer.Run(); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 t.CheckLoweringBinop(IrOpcode::kFloat64LessThan, | 965 t.CheckLoweringBinop(IrOpcode::kFloat64LessThan, |
| 965 t.simplified()->NumberLessThan()); | 966 t.simplified()->NumberLessThan()); |
| 966 t.CheckLoweringBinop(IrOpcode::kFloat64LessThanOrEqual, | 967 t.CheckLoweringBinop(IrOpcode::kFloat64LessThanOrEqual, |
| 967 t.simplified()->NumberLessThanOrEqual()); | 968 t.simplified()->NumberLessThanOrEqual()); |
| 968 } | 969 } |
| 969 } | 970 } |
| 970 | 971 |
| 971 | 972 |
| 972 TEST(LowerNumberAddSub_to_int32) { | 973 TEST(LowerNumberAddSub_to_int32) { |
| 973 HandleAndZoneScope scope; | 974 HandleAndZoneScope scope; |
| 974 Factory* f = scope.main_zone()->isolate()->factory(); | 975 Factory* f = scope.main_isolate()->factory(); |
| 975 Type* small_range = | 976 Type* small_range = |
| 976 Type::Range(f->NewNumber(1), f->NewNumber(10), scope.main_zone()); | 977 Type::Range(f->NewNumber(1), f->NewNumber(10), scope.main_zone()); |
| 977 Type* large_range = | 978 Type* large_range = |
| 978 Type::Range(f->NewNumber(-1e+13), f->NewNumber(1e+14), scope.main_zone()); | 979 Type::Range(f->NewNumber(-1e+13), f->NewNumber(1e+14), scope.main_zone()); |
| 979 static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range, | 980 static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range, |
| 980 large_range}; | 981 large_range}; |
| 981 | 982 |
| 982 for (size_t i = 0; i < arraysize(types); i++) { | 983 for (size_t i = 0; i < arraysize(types); i++) { |
| 983 for (size_t j = 0; j < arraysize(types); j++) { | 984 for (size_t j = 0; j < arraysize(types); j++) { |
| 984 TestingGraph t(types[i], types[j]); | 985 TestingGraph t(types[i], types[j]); |
| 985 t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Add, | 986 t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Add, |
| 986 t.simplified()->NumberAdd(), | 987 t.simplified()->NumberAdd(), |
| 987 t.simplified()->NumberToInt32()); | 988 t.simplified()->NumberToInt32()); |
| 988 t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Sub, | 989 t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Sub, |
| 989 t.simplified()->NumberSubtract(), | 990 t.simplified()->NumberSubtract(), |
| 990 t.simplified()->NumberToInt32()); | 991 t.simplified()->NumberToInt32()); |
| 991 } | 992 } |
| 992 } | 993 } |
| 993 } | 994 } |
| 994 | 995 |
| 995 | 996 |
| 996 TEST(LowerNumberAddSub_to_uint32) { | 997 TEST(LowerNumberAddSub_to_uint32) { |
| 997 HandleAndZoneScope scope; | 998 HandleAndZoneScope scope; |
| 998 Factory* f = scope.main_zone()->isolate()->factory(); | 999 Factory* f = scope.main_isolate()->factory(); |
| 999 Type* small_range = | 1000 Type* small_range = |
| 1000 Type::Range(f->NewNumber(1), f->NewNumber(10), scope.main_zone()); | 1001 Type::Range(f->NewNumber(1), f->NewNumber(10), scope.main_zone()); |
| 1001 Type* large_range = | 1002 Type* large_range = |
| 1002 Type::Range(f->NewNumber(-1e+13), f->NewNumber(1e+14), scope.main_zone()); | 1003 Type::Range(f->NewNumber(-1e+13), f->NewNumber(1e+14), scope.main_zone()); |
| 1003 static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range, | 1004 static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range, |
| 1004 large_range}; | 1005 large_range}; |
| 1005 | 1006 |
| 1006 for (size_t i = 0; i < arraysize(types); i++) { | 1007 for (size_t i = 0; i < arraysize(types); i++) { |
| 1007 for (size_t j = 0; j < arraysize(types); j++) { | 1008 for (size_t j = 0; j < arraysize(types); j++) { |
| 1008 TestingGraph t(types[i], types[j]); | 1009 TestingGraph t(types[i], types[j]); |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2043 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); | 2044 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); |
| 2044 NodeProperties::SetBounds(phi, phi_bounds); | 2045 NodeProperties::SetBounds(phi, phi_bounds); |
| 2045 | 2046 |
| 2046 Node* use = t.Use(phi, d.use); | 2047 Node* use = t.Use(phi, d.use); |
| 2047 t.Return(use); | 2048 t.Return(use); |
| 2048 t.Lower(); | 2049 t.Lower(); |
| 2049 | 2050 |
| 2050 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); | 2051 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); |
| 2051 } | 2052 } |
| 2052 } | 2053 } |
| OLD | NEW |