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" |
11 #include "src/compiler/graph-visualizer.h" | 11 #include "src/compiler/graph-visualizer.h" |
12 #include "src/compiler/node-properties.h" | 12 #include "src/compiler/node-properties.h" |
13 #include "src/compiler/pipeline.h" | 13 #include "src/compiler/pipeline.h" |
14 #include "src/compiler/representation-change.h" | 14 #include "src/compiler/representation-change.h" |
15 #include "src/compiler/simplified-lowering.h" | 15 #include "src/compiler/simplified-lowering.h" |
16 #include "src/compiler/source-position.h" | 16 #include "src/compiler/source-position.h" |
17 #include "src/compiler/typer.h" | 17 #include "src/compiler/typer.h" |
18 #include "src/compiler/verifier.h" | 18 #include "src/compiler/verifier.h" |
19 #include "src/execution.h" | 19 #include "src/execution.h" |
20 #include "src/parser.h" | 20 #include "src/parser.h" |
21 #include "src/rewriter.h" | 21 #include "src/rewriter.h" |
22 #include "src/scopes.h" | 22 #include "src/scopes.h" |
23 #include "test/cctest/cctest.h" | 23 #include "test/cctest/cctest.h" |
24 #include "test/cctest/compiler/codegen-tester.h" | 24 #include "test/cctest/compiler/codegen-tester.h" |
| 25 #include "test/cctest/compiler/function-tester.h" |
25 #include "test/cctest/compiler/graph-builder-tester.h" | 26 #include "test/cctest/compiler/graph-builder-tester.h" |
26 #include "test/cctest/compiler/value-helper.h" | 27 #include "test/cctest/compiler/value-helper.h" |
27 | 28 |
28 using namespace v8::internal; | 29 using namespace v8::internal; |
29 using namespace v8::internal::compiler; | 30 using namespace v8::internal::compiler; |
30 | 31 |
31 template <typename ReturnType> | 32 template <typename ReturnType> |
32 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { | 33 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { |
33 public: | 34 public: |
34 SimplifiedLoweringTester(MachineType p0 = kMachNone, | 35 SimplifiedLoweringTester(MachineType p0 = kMachNone, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
74 if (expected >= Smi::kMaxValue) return; | 75 if (expected >= Smi::kMaxValue) return; |
75 Handle<Object> num = factory()->NewNumber(input); | 76 Handle<Object> num = factory()->NewNumber(input); |
76 Object* result = this->Call(*num); | 77 Object* result = this->Call(*num); |
77 CHECK(factory()->NewNumber(expected)->SameValue(result)); | 78 CHECK(factory()->NewNumber(expected)->SameValue(result)); |
78 } | 79 } |
79 | 80 |
| 81 template <typename T> |
| 82 T* CallWithPotentialGC() { |
| 83 // TODO(titzer): we wrap the code in a JSFunction here to reuse the |
| 84 // JSEntryStub; that could be done with a special prologue or other stub. |
| 85 Handle<JSFunction> fun = FunctionTester::ForMachineGraph(this->graph()); |
| 86 Handle<Object>* args = NULL; |
| 87 MaybeHandle<Object> result = Execution::Call( |
| 88 this->isolate(), fun, factory()->undefined_value(), 0, args, false); |
| 89 return T::cast(*result.ToHandleChecked()); |
| 90 } |
| 91 |
80 Factory* factory() { return this->isolate()->factory(); } | 92 Factory* factory() { return this->isolate()->factory(); } |
81 Heap* heap() { return this->isolate()->heap(); } | 93 Heap* heap() { return this->isolate()->heap(); } |
82 }; | 94 }; |
83 | 95 |
84 | 96 |
85 // TODO(titzer): factor these tests out to test-run-simplifiedops.cc. | 97 // TODO(titzer): factor these tests out to test-run-simplifiedops.cc. |
86 // TODO(titzer): test tagged representation for input to NumberToInt32. | 98 // TODO(titzer): test tagged representation for input to NumberToInt32. |
87 TEST(RunNumberToInt32_float64) { | 99 TEST(RunNumberToInt32_float64) { |
88 // TODO(titzer): explicit load/stores here are only because of representations | 100 // TODO(titzer): explicit load/stores here are only because of representations |
89 double input; | 101 double input; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 | 655 |
644 | 656 |
645 TEST(RunAccessTests_Smi) { | 657 TEST(RunAccessTests_Smi) { |
646 Smi* data[] = {Smi::FromInt(-1), Smi::FromInt(-9), | 658 Smi* data[] = {Smi::FromInt(-1), Smi::FromInt(-9), |
647 Smi::FromInt(0), Smi::FromInt(666), | 659 Smi::FromInt(0), Smi::FromInt(666), |
648 Smi::FromInt(77777), Smi::FromInt(Smi::kMaxValue)}; | 660 Smi::FromInt(77777), Smi::FromInt(Smi::kMaxValue)}; |
649 RunAccessTest<Smi*>(kMachAnyTagged, data, arraysize(data)); | 661 RunAccessTest<Smi*>(kMachAnyTagged, data, arraysize(data)); |
650 } | 662 } |
651 | 663 |
652 | 664 |
| 665 TEST(RunAllocate) { |
| 666 PretenureFlag flag[] = {NOT_TENURED, TENURED}; |
| 667 |
| 668 for (size_t i = 0; i < arraysize(flag); i++) { |
| 669 SimplifiedLoweringTester<HeapObject*> t; |
| 670 FieldAccess access = AccessBuilder::ForMap(); |
| 671 Node* size = t.jsgraph.Constant(HeapNumber::kSize); |
| 672 Node* alloc = t.NewNode(t.simplified()->Allocate(flag[i]), size); |
| 673 Node* map = t.jsgraph.Constant(t.factory()->heap_number_map()); |
| 674 t.StoreField(access, alloc, map); |
| 675 t.Return(alloc); |
| 676 |
| 677 t.LowerAllNodes(); |
| 678 t.GenerateCode(); |
| 679 |
| 680 if (Pipeline::SupportedTarget()) { |
| 681 HeapObject* result = t.CallWithPotentialGC<HeapObject>(); |
| 682 CHECK(t.heap()->new_space()->Contains(result) || flag[i] == TENURED); |
| 683 CHECK(t.heap()->old_space()->Contains(result) || flag[i] == NOT_TENURED); |
| 684 CHECK(result->IsHeapNumber()); |
| 685 } |
| 686 } |
| 687 } |
| 688 |
| 689 |
653 // Fills in most of the nodes of the graph in order to make tests shorter. | 690 // Fills in most of the nodes of the graph in order to make tests shorter. |
654 class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders { | 691 class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders { |
655 public: | 692 public: |
656 Typer typer; | 693 Typer typer; |
657 JSOperatorBuilder javascript; | 694 JSOperatorBuilder javascript; |
658 JSGraph jsgraph; | 695 JSGraph jsgraph; |
659 Node* p0; | 696 Node* p0; |
660 Node* p1; | 697 Node* p1; |
661 Node* p2; | 698 Node* p2; |
662 Node* start; | 699 Node* start; |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2053 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); | 2090 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); |
2054 NodeProperties::SetBounds(phi, phi_bounds); | 2091 NodeProperties::SetBounds(phi, phi_bounds); |
2055 | 2092 |
2056 Node* use = t.Use(phi, d.use); | 2093 Node* use = t.Use(phi, d.use); |
2057 t.Return(use); | 2094 t.Return(use); |
2058 t.Lower(); | 2095 t.Lower(); |
2059 | 2096 |
2060 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); | 2097 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); |
2061 } | 2098 } |
2062 } | 2099 } |
OLD | NEW |