Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/unittests/compiler/tail-call-optimization-unittest.cc

Issue 1513543003: [turbofan] Make MachineType a pair of enums. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moar rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/compiler/linkage.h" 5 #include "src/compiler/linkage.h"
6 #include "src/compiler/tail-call-optimization.h" 6 #include "src/compiler/tail-call-optimization.h"
7 #include "test/unittests/compiler/graph-unittest.h" 7 #include "test/unittests/compiler/graph-unittest.h"
8 #include "test/unittests/compiler/node-test-utils.h" 8 #include "test/unittests/compiler/node-test-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 class TailCallOptimizationTest : public GraphTest { 14 class TailCallOptimizationTest : public GraphTest {
15 public: 15 public:
16 explicit TailCallOptimizationTest(int num_parameters = 1) 16 explicit TailCallOptimizationTest(int num_parameters = 1)
17 : GraphTest(num_parameters) {} 17 : GraphTest(num_parameters) {}
18 ~TailCallOptimizationTest() override {} 18 ~TailCallOptimizationTest() override {}
19 19
20 protected: 20 protected:
21 Reduction Reduce(Node* node) { 21 Reduction Reduce(Node* node) {
22 TailCallOptimization tco(common(), graph()); 22 TailCallOptimization tco(common(), graph());
23 return tco.Reduce(node); 23 return tco.Reduce(node);
24 } 24 }
25 }; 25 };
26 26
27 27
28 TEST_F(TailCallOptimizationTest, CallCodeObject0) { 28 TEST_F(TailCallOptimizationTest, CallCodeObject0) {
29 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 29 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
30 MachineType::AnyTagged()};
30 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 31 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
31 LinkageLocation::ForRegister(1)}; 32 LinkageLocation::ForRegister(1)};
32 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 33 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
33 CallDescriptor::kCallCodeObject, kMachAnyTagged, 34 CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
34 LinkageLocation::ForRegister(0), 35 LinkageLocation::ForRegister(0),
35 new (zone()) MachineSignature(1, 1, kMachineSignature), 36 new (zone()) MachineSignature(1, 1, kMachineSignature),
36 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 37 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
37 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags); 38 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags);
38 Node* p0 = Parameter(0); 39 Node* p0 = Parameter(0);
39 Node* p1 = Parameter(1); 40 Node* p1 = Parameter(1);
40 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 41 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
41 graph()->start(), graph()->start()); 42 graph()->start(), graph()->start());
42 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 43 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
43 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 44 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
44 Reduction r = Reduce(ret); 45 Reduction r = Reduce(ret);
45 ASSERT_FALSE(r.Changed()); 46 ASSERT_FALSE(r.Changed());
46 } 47 }
47 48
48 49
49 TEST_F(TailCallOptimizationTest, CallCodeObject1) { 50 TEST_F(TailCallOptimizationTest, CallCodeObject1) {
50 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 51 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
52 MachineType::AnyTagged()};
51 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 53 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
52 LinkageLocation::ForRegister(1)}; 54 LinkageLocation::ForRegister(1)};
53 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 55 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
54 CallDescriptor::kCallCodeObject, kMachAnyTagged, 56 CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
55 LinkageLocation::ForRegister(0), 57 LinkageLocation::ForRegister(0),
56 new (zone()) MachineSignature(1, 1, kMachineSignature), 58 new (zone()) MachineSignature(1, 1, kMachineSignature),
57 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 59 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
58 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); 60 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
59 Node* p0 = Parameter(0); 61 Node* p0 = Parameter(0);
60 Node* p1 = Parameter(1); 62 Node* p1 = Parameter(1);
61 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 63 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
62 graph()->start(), graph()->start()); 64 graph()->start(), graph()->start());
63 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 65 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
64 Node* if_exception = graph()->NewNode( 66 Node* if_exception = graph()->NewNode(
65 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); 67 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call);
66 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 68 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
67 Node* end = graph()->NewNode(common()->End(1), if_exception); 69 Node* end = graph()->NewNode(common()->End(1), if_exception);
68 graph()->SetEnd(end); 70 graph()->SetEnd(end);
69 Reduction r = Reduce(ret); 71 Reduction r = Reduce(ret);
70 ASSERT_FALSE(r.Changed()); 72 ASSERT_FALSE(r.Changed());
71 } 73 }
72 74
73 75
74 TEST_F(TailCallOptimizationTest, CallCodeObject2) { 76 TEST_F(TailCallOptimizationTest, CallCodeObject2) {
75 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 77 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
78 MachineType::AnyTagged()};
76 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 79 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
77 LinkageLocation::ForRegister(1)}; 80 LinkageLocation::ForRegister(1)};
78 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 81 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
79 CallDescriptor::kCallCodeObject, kMachAnyTagged, 82 CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
80 LinkageLocation::ForRegister(0), 83 LinkageLocation::ForRegister(0),
81 new (zone()) MachineSignature(1, 1, kMachineSignature), 84 new (zone()) MachineSignature(1, 1, kMachineSignature),
82 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 85 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
83 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); 86 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
84 Node* p0 = Parameter(0); 87 Node* p0 = Parameter(0);
85 Node* p1 = Parameter(1); 88 Node* p1 = Parameter(1);
86 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 89 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
87 graph()->start(), graph()->start()); 90 graph()->start(), graph()->start());
88 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 91 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
89 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 92 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
90 Reduction r = Reduce(ret); 93 Reduction r = Reduce(ret);
91 ASSERT_TRUE(r.Changed()); 94 ASSERT_TRUE(r.Changed());
92 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, 95 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1,
93 graph()->start(), graph()->start())); 96 graph()->start(), graph()->start()));
94 } 97 }
95 98
96 99
97 TEST_F(TailCallOptimizationTest, CallJSFunction0) { 100 TEST_F(TailCallOptimizationTest, CallJSFunction0) {
98 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 101 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
102 MachineType::AnyTagged()};
99 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 103 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
100 LinkageLocation::ForRegister(1)}; 104 LinkageLocation::ForRegister(1)};
101 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 105 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
102 CallDescriptor::kCallJSFunction, kMachAnyTagged, 106 CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
103 LinkageLocation::ForRegister(0), 107 LinkageLocation::ForRegister(0),
104 new (zone()) MachineSignature(1, 1, kMachineSignature), 108 new (zone()) MachineSignature(1, 1, kMachineSignature),
105 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 109 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
106 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags); 110 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags);
107 Node* p0 = Parameter(0); 111 Node* p0 = Parameter(0);
108 Node* p1 = Parameter(1); 112 Node* p1 = Parameter(1);
109 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 113 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
110 graph()->start(), graph()->start()); 114 graph()->start(), graph()->start());
111 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 115 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
112 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 116 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
113 Reduction r = Reduce(ret); 117 Reduction r = Reduce(ret);
114 ASSERT_FALSE(r.Changed()); 118 ASSERT_FALSE(r.Changed());
115 } 119 }
116 120
117 121
118 TEST_F(TailCallOptimizationTest, CallJSFunction1) { 122 TEST_F(TailCallOptimizationTest, CallJSFunction1) {
119 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 123 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
124 MachineType::AnyTagged()};
120 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 125 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
121 LinkageLocation::ForRegister(1)}; 126 LinkageLocation::ForRegister(1)};
122 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 127 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
123 CallDescriptor::kCallJSFunction, kMachAnyTagged, 128 CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
124 LinkageLocation::ForRegister(0), 129 LinkageLocation::ForRegister(0),
125 new (zone()) MachineSignature(1, 1, kMachineSignature), 130 new (zone()) MachineSignature(1, 1, kMachineSignature),
126 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 131 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
127 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); 132 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
128 Node* p0 = Parameter(0); 133 Node* p0 = Parameter(0);
129 Node* p1 = Parameter(1); 134 Node* p1 = Parameter(1);
130 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 135 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
131 graph()->start(), graph()->start()); 136 graph()->start(), graph()->start());
132 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 137 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
133 Node* if_exception = graph()->NewNode( 138 Node* if_exception = graph()->NewNode(
134 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); 139 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call);
135 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 140 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
136 Node* end = graph()->NewNode(common()->End(1), if_exception); 141 Node* end = graph()->NewNode(common()->End(1), if_exception);
137 graph()->SetEnd(end); 142 graph()->SetEnd(end);
138 Reduction r = Reduce(ret); 143 Reduction r = Reduce(ret);
139 ASSERT_FALSE(r.Changed()); 144 ASSERT_FALSE(r.Changed());
140 } 145 }
141 146
142 147
143 TEST_F(TailCallOptimizationTest, CallJSFunction2) { 148 TEST_F(TailCallOptimizationTest, CallJSFunction2) {
144 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; 149 MachineType kMachineSignature[] = {MachineType::AnyTagged(),
150 MachineType::AnyTagged()};
145 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0), 151 LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
146 LinkageLocation::ForRegister(1)}; 152 LinkageLocation::ForRegister(1)};
147 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( 153 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
148 CallDescriptor::kCallJSFunction, kMachAnyTagged, 154 CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
149 LinkageLocation::ForRegister(0), 155 LinkageLocation::ForRegister(0),
150 new (zone()) MachineSignature(1, 1, kMachineSignature), 156 new (zone()) MachineSignature(1, 1, kMachineSignature),
151 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, 157 new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
152 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); 158 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
153 Node* p0 = Parameter(0); 159 Node* p0 = Parameter(0);
154 Node* p1 = Parameter(1); 160 Node* p1 = Parameter(1);
155 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, 161 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1,
156 graph()->start(), graph()->start()); 162 graph()->start(), graph()->start());
157 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); 163 Node* if_success = graph()->NewNode(common()->IfSuccess(), call);
158 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); 164 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success);
159 Reduction r = Reduce(ret); 165 Reduction r = Reduce(ret);
160 ASSERT_TRUE(r.Changed()); 166 ASSERT_TRUE(r.Changed());
161 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, 167 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1,
162 graph()->start(), graph()->start())); 168 graph()->start(), graph()->start()));
163 } 169 }
164 170
165 171
166 } // namespace compiler 172 } // namespace compiler
167 } // namespace internal 173 } // namespace internal
168 } // namespace v8 174 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698