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/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
9 #include "src/compiler/graph-inl.h" | 9 #include "src/compiler/graph-inl.h" |
10 #include "src/compiler/phi-reducer.h" | 10 #include "src/compiler/phi-reducer.h" |
11 | 11 |
12 using namespace v8::internal; | 12 using namespace v8::internal; |
13 using namespace v8::internal::compiler; | 13 using namespace v8::internal::compiler; |
14 | 14 |
15 class PhiReducerTester : HandleAndZoneScope { | 15 class PhiReducerTester : HandleAndZoneScope { |
16 public: | 16 public: |
17 PhiReducerTester() | 17 explicit PhiReducerTester(int num_parameters = 0) |
18 : isolate(main_isolate()), | 18 : isolate(main_isolate()), |
19 common(main_zone()), | 19 common(main_zone()), |
20 graph(main_zone()), | 20 graph(main_zone()), |
21 self(graph.NewNode(common.Start())), | 21 self(graph.NewNode(common.Start(num_parameters))), |
22 dead(graph.NewNode(common.Dead())) {} | 22 dead(graph.NewNode(common.Dead())) { |
| 23 graph.SetStart(self); |
| 24 } |
23 | 25 |
24 Isolate* isolate; | 26 Isolate* isolate; |
25 CommonOperatorBuilder common; | 27 CommonOperatorBuilder common; |
26 Graph graph; | 28 Graph graph; |
27 Node* self; | 29 Node* self; |
28 Node* dead; | 30 Node* dead; |
29 | 31 |
30 void CheckReduce(Node* expect, Node* phi) { | 32 void CheckReduce(Node* expect, Node* phi) { |
31 PhiReducer reducer; | 33 PhiReducer reducer; |
32 Reduction reduction = reducer.Reduce(phi); | 34 Reduction reduction = reducer.Reduce(phi); |
33 if (expect == phi) { | 35 if (expect == phi) { |
34 CHECK(!reduction.Changed()); | 36 CHECK(!reduction.Changed()); |
35 } else { | 37 } else { |
36 CHECK(reduction.Changed()); | 38 CHECK(reduction.Changed()); |
37 CHECK_EQ(expect, reduction.replacement()); | 39 CHECK_EQ(expect, reduction.replacement()); |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 Node* Int32Constant(int32_t val) { | 43 Node* Int32Constant(int32_t val) { |
42 return graph.NewNode(common.Int32Constant(val)); | 44 return graph.NewNode(common.Int32Constant(val)); |
43 } | 45 } |
44 | 46 |
45 Node* Float64Constant(double val) { | 47 Node* Float64Constant(double val) { |
46 return graph.NewNode(common.Float64Constant(val)); | 48 return graph.NewNode(common.Float64Constant(val)); |
47 } | 49 } |
48 | 50 |
49 Node* Parameter(int32_t index = 0) { | 51 Node* Parameter(int32_t index = 0) { |
50 return graph.NewNode(common.Parameter(index)); | 52 return graph.NewNode(common.Parameter(index), graph.start()); |
51 } | 53 } |
52 | 54 |
53 Node* Phi(Node* a) { | 55 Node* Phi(Node* a) { |
54 return SetSelfReferences(graph.NewNode(common.Phi(1), a)); | 56 return SetSelfReferences(graph.NewNode(common.Phi(1), a)); |
55 } | 57 } |
56 | 58 |
57 Node* Phi(Node* a, Node* b) { | 59 Node* Phi(Node* a, Node* b) { |
58 return SetSelfReferences(graph.NewNode(common.Phi(2), a, b)); | 60 return SetSelfReferences(graph.NewNode(common.Phi(2), a, b)); |
59 } | 61 } |
60 | 62 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Node* oneish = R.Float64Constant(1.1); | 216 Node* oneish = R.Float64Constant(1.1); |
215 Node* param = R.Parameter(); | 217 Node* param = R.Parameter(); |
216 | 218 |
217 Node* singles[] = {zero, one, oneish, param}; | 219 Node* singles[] = {zero, one, oneish, param}; |
218 for (size_t i = 0; i < ARRAY_SIZE(singles); ++i) { | 220 for (size_t i = 0; i < ARRAY_SIZE(singles); ++i) { |
219 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.dead)); | 221 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.dead)); |
220 R.CheckReduce(singles[i], R.PhiWithControl(R.self, singles[i], R.dead)); | 222 R.CheckReduce(singles[i], R.PhiWithControl(R.self, singles[i], R.dead)); |
221 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.self, R.dead)); | 223 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.self, R.dead)); |
222 } | 224 } |
223 } | 225 } |
OLD | NEW |