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/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/graph.h" | 6 #include "src/compiler/graph.h" |
7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 }; | 49 }; |
50 | 50 |
51 | 51 |
52 TEST_F(LinkageTailCall, EmptyToEmpty) { | 52 TEST_F(LinkageTailCall, EmptyToEmpty) { |
53 LocationSignature locations(0, 0, nullptr); | 53 LocationSignature locations(0, 0, nullptr); |
54 CallDescriptor* desc = NewStandardCallDescriptor(&locations); | 54 CallDescriptor* desc = NewStandardCallDescriptor(&locations); |
55 CommonOperatorBuilder common(zone()); | 55 CommonOperatorBuilder common(zone()); |
56 const Operator* op = common.Call(desc); | 56 const Operator* op = common.Call(desc); |
57 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 57 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
58 EXPECT_TRUE(desc->CanTailCall(node)); | 58 int stack_param_delta = 0; |
| 59 EXPECT_TRUE(desc->CanTailCall(node, &stack_param_delta)); |
| 60 EXPECT_EQ(0, stack_param_delta); |
59 } | 61 } |
60 | 62 |
61 | 63 |
62 TEST_F(LinkageTailCall, SameReturn) { | 64 TEST_F(LinkageTailCall, SameReturn) { |
63 // Caller | 65 // Caller |
64 LinkageLocation location_array[] = {RegisterLocation(0)}; | 66 LinkageLocation location_array[] = {RegisterLocation(0)}; |
65 LocationSignature locations1(1, 0, location_array); | 67 LocationSignature locations1(1, 0, location_array); |
66 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 68 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
67 | 69 |
68 // Callee | 70 // Callee |
69 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); | 71 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); |
70 | 72 |
71 CommonOperatorBuilder common(zone()); | 73 CommonOperatorBuilder common(zone()); |
72 const Operator* op = common.Call(desc2); | 74 const Operator* op = common.Call(desc2); |
73 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 75 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
74 EXPECT_TRUE(desc1->CanTailCall(node)); | 76 int stack_param_delta = 0; |
| 77 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 78 EXPECT_EQ(0, stack_param_delta); |
75 } | 79 } |
76 | 80 |
77 | 81 |
78 TEST_F(LinkageTailCall, DifferingReturn) { | 82 TEST_F(LinkageTailCall, DifferingReturn) { |
79 // Caller | 83 // Caller |
80 LinkageLocation location_array1[] = {RegisterLocation(0)}; | 84 LinkageLocation location_array1[] = {RegisterLocation(0)}; |
81 LocationSignature locations1(1, 0, location_array1); | 85 LocationSignature locations1(1, 0, location_array1); |
82 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 86 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
83 | 87 |
84 // Callee | 88 // Callee |
85 LinkageLocation location_array2[] = {RegisterLocation(1)}; | 89 LinkageLocation location_array2[] = {RegisterLocation(1)}; |
86 LocationSignature locations2(1, 0, location_array2); | 90 LocationSignature locations2(1, 0, location_array2); |
87 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 91 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
88 | 92 |
89 CommonOperatorBuilder common(zone()); | 93 CommonOperatorBuilder common(zone()); |
90 const Operator* op = common.Call(desc2); | 94 const Operator* op = common.Call(desc2); |
91 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 95 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
92 EXPECT_FALSE(desc1->CanTailCall(node)); | 96 int stack_param_delta = 0; |
| 97 EXPECT_FALSE(desc1->CanTailCall(node, &stack_param_delta)); |
| 98 EXPECT_EQ(0, stack_param_delta); |
93 } | 99 } |
94 | 100 |
95 | 101 |
96 TEST_F(LinkageTailCall, MoreRegisterParametersCallee) { | 102 TEST_F(LinkageTailCall, MoreRegisterParametersCallee) { |
97 // Caller | 103 // Caller |
98 LinkageLocation location_array1[] = {RegisterLocation(0)}; | 104 LinkageLocation location_array1[] = {RegisterLocation(0)}; |
99 LocationSignature locations1(1, 0, location_array1); | 105 LocationSignature locations1(1, 0, location_array1); |
100 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 106 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
101 | 107 |
102 // Callee | 108 // Callee |
103 LinkageLocation location_array2[] = {RegisterLocation(0), | 109 LinkageLocation location_array2[] = {RegisterLocation(0), |
104 RegisterLocation(0)}; | 110 RegisterLocation(0)}; |
105 LocationSignature locations2(1, 1, location_array2); | 111 LocationSignature locations2(1, 1, location_array2); |
106 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 112 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
107 | 113 |
108 CommonOperatorBuilder common(zone()); | 114 CommonOperatorBuilder common(zone()); |
109 const Operator* op = common.Call(desc2); | 115 const Operator* op = common.Call(desc2); |
110 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 116 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
111 EXPECT_TRUE(desc1->CanTailCall(node)); | 117 int stack_param_delta = 0; |
| 118 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 119 EXPECT_EQ(0, stack_param_delta); |
112 } | 120 } |
113 | 121 |
114 | 122 |
115 TEST_F(LinkageTailCall, MoreRegisterParametersCaller) { | 123 TEST_F(LinkageTailCall, MoreRegisterParametersCaller) { |
116 // Caller | 124 // Caller |
117 LinkageLocation location_array1[] = {RegisterLocation(0), | 125 LinkageLocation location_array1[] = {RegisterLocation(0), |
118 RegisterLocation(0)}; | 126 RegisterLocation(0)}; |
119 LocationSignature locations1(1, 1, location_array1); | 127 LocationSignature locations1(1, 1, location_array1); |
120 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 128 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
121 | 129 |
122 // Callee | 130 // Callee |
123 LinkageLocation location_array2[] = {RegisterLocation(0)}; | 131 LinkageLocation location_array2[] = {RegisterLocation(0)}; |
124 LocationSignature locations2(1, 0, location_array2); | 132 LocationSignature locations2(1, 0, location_array2); |
125 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 133 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
126 | 134 |
127 CommonOperatorBuilder common(zone()); | 135 CommonOperatorBuilder common(zone()); |
128 const Operator* op = common.Call(desc2); | 136 const Operator* op = common.Call(desc2); |
129 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 137 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
130 EXPECT_TRUE(desc1->CanTailCall(node)); | 138 int stack_param_delta = 0; |
| 139 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 140 EXPECT_EQ(0, stack_param_delta); |
131 } | 141 } |
132 | 142 |
133 | 143 |
134 TEST_F(LinkageTailCall, MoreRegisterAndStackParametersCallee) { | 144 TEST_F(LinkageTailCall, MoreRegisterAndStackParametersCallee) { |
135 // Caller | 145 // Caller |
136 LinkageLocation location_array1[] = {RegisterLocation(0)}; | 146 LinkageLocation location_array1[] = {RegisterLocation(0)}; |
137 LocationSignature locations1(1, 0, location_array1); | 147 LocationSignature locations1(1, 0, location_array1); |
138 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 148 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
139 | 149 |
140 // Callee | 150 // Callee |
141 LinkageLocation location_array2[] = {RegisterLocation(0), RegisterLocation(0), | 151 LinkageLocation location_array2[] = {RegisterLocation(0), RegisterLocation(0), |
142 RegisterLocation(1), StackLocation(1)}; | 152 RegisterLocation(1), StackLocation(1)}; |
143 LocationSignature locations2(1, 3, location_array2); | 153 LocationSignature locations2(1, 3, location_array2); |
144 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 154 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
145 | 155 |
146 CommonOperatorBuilder common(zone()); | 156 CommonOperatorBuilder common(zone()); |
147 const Operator* op = common.Call(desc2); | 157 const Operator* op = common.Call(desc2); |
148 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 158 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
149 EXPECT_FALSE(desc1->CanTailCall(node)); | 159 int stack_param_delta = 0; |
| 160 EXPECT_FALSE(desc1->CanTailCall(node, &stack_param_delta)); |
| 161 EXPECT_EQ(1, stack_param_delta); |
150 } | 162 } |
151 | 163 |
152 | 164 |
153 TEST_F(LinkageTailCall, MoreRegisterAndStackParametersCaller) { | 165 TEST_F(LinkageTailCall, MoreRegisterAndStackParametersCaller) { |
154 // Caller | 166 // Caller |
155 LinkageLocation location_array[] = {RegisterLocation(0), RegisterLocation(0), | 167 LinkageLocation location_array[] = {RegisterLocation(0), RegisterLocation(0), |
156 RegisterLocation(1), StackLocation(1)}; | 168 RegisterLocation(1), StackLocation(1)}; |
157 LocationSignature locations1(1, 3, location_array); | 169 LocationSignature locations1(1, 3, location_array); |
158 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 170 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
159 | 171 |
160 // Callee | 172 // Callee |
161 LinkageLocation location_array2[] = {RegisterLocation(0)}; | 173 LinkageLocation location_array2[] = {RegisterLocation(0)}; |
162 LocationSignature locations2(1, 0, location_array2); | 174 LocationSignature locations2(1, 0, location_array2); |
163 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 175 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
164 | 176 |
165 CommonOperatorBuilder common(zone()); | 177 CommonOperatorBuilder common(zone()); |
166 const Operator* op = common.Call(desc2); | 178 const Operator* op = common.Call(desc2); |
167 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); | 179 Node* const node = Node::New(zone(), 1, op, 0, nullptr, false); |
168 EXPECT_FALSE(desc1->CanTailCall(node)); | 180 int stack_param_delta = 0; |
| 181 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 182 EXPECT_EQ(-1, stack_param_delta); |
169 } | 183 } |
170 | 184 |
171 | 185 |
172 TEST_F(LinkageTailCall, MatchingStackParameters) { | 186 TEST_F(LinkageTailCall, MatchingStackParameters) { |
173 // Caller | 187 // Caller |
174 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 188 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
175 StackLocation(2), StackLocation(1)}; | 189 StackLocation(2), StackLocation(1)}; |
176 LocationSignature locations1(1, 3, location_array); | 190 LocationSignature locations1(1, 3, location_array); |
177 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 191 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
178 | 192 |
179 // Caller | 193 // Caller |
180 LocationSignature locations2(1, 3, location_array); | 194 LocationSignature locations2(1, 3, location_array); |
181 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); | 195 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); |
182 | 196 |
183 CommonOperatorBuilder common(zone()); | 197 CommonOperatorBuilder common(zone()); |
184 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 198 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
185 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 199 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
186 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 200 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
187 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 201 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
188 Node* parameters[] = {p0, p1, p2, p3}; | 202 Node* parameters[] = {p0, p1, p2, p3}; |
189 const Operator* op = common.Call(desc2); | 203 const Operator* op = common.Call(desc2); |
190 Node* const node = | 204 Node* const node = |
191 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 205 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
192 EXPECT_TRUE(desc1->CanTailCall(node)); | 206 int stack_param_delta = 0; |
| 207 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 208 EXPECT_EQ(0, stack_param_delta); |
193 } | 209 } |
194 | 210 |
195 | 211 |
196 TEST_F(LinkageTailCall, NonMatchingStackParameters) { | 212 TEST_F(LinkageTailCall, NonMatchingStackParameters) { |
197 // Caller | 213 // Caller |
198 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 214 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
199 StackLocation(2), StackLocation(1)}; | 215 StackLocation(2), StackLocation(1)}; |
200 LocationSignature locations1(1, 3, location_array); | 216 LocationSignature locations1(1, 3, location_array); |
201 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 217 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
202 | 218 |
203 // Caller | 219 // Caller |
204 LocationSignature locations2(1, 3, location_array); | 220 LocationSignature locations2(1, 3, location_array); |
205 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); | 221 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); |
206 | 222 |
207 CommonOperatorBuilder common(zone()); | 223 CommonOperatorBuilder common(zone()); |
208 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 224 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
209 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 225 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
210 Node* p2 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 226 Node* p2 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
211 Node* p3 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 227 Node* p3 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
212 Node* parameters[] = {p0, p1, p2, p3}; | 228 Node* parameters[] = {p0, p1, p2, p3}; |
213 const Operator* op = common.Call(desc2); | 229 const Operator* op = common.Call(desc2); |
214 Node* const node = | 230 Node* const node = |
215 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 231 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
216 EXPECT_FALSE(desc1->CanTailCall(node)); | 232 int stack_param_delta = 0; |
| 233 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 234 EXPECT_EQ(0, stack_param_delta); |
217 } | 235 } |
218 | 236 |
219 | 237 |
220 TEST_F(LinkageTailCall, MatchingStackParametersExtraCallerRegisters) { | 238 TEST_F(LinkageTailCall, MatchingStackParametersExtraCallerRegisters) { |
221 // Caller | 239 // Caller |
222 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 240 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
223 StackLocation(2), StackLocation(1), | 241 StackLocation(2), StackLocation(1), |
224 RegisterLocation(0), RegisterLocation(1)}; | 242 RegisterLocation(0), RegisterLocation(1)}; |
225 LocationSignature locations1(1, 5, location_array); | 243 LocationSignature locations1(1, 5, location_array); |
226 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 244 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
227 | 245 |
228 // Caller | 246 // Caller |
229 LocationSignature locations2(1, 3, location_array); | 247 LocationSignature locations2(1, 3, location_array); |
230 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); | 248 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); |
231 | 249 |
232 CommonOperatorBuilder common(zone()); | 250 CommonOperatorBuilder common(zone()); |
233 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 251 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
234 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 252 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
235 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 253 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
236 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 254 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
237 Node* parameters[] = {p0, p1, p2, p3}; | 255 Node* parameters[] = {p0, p1, p2, p3}; |
238 const Operator* op = common.Call(desc2); | 256 const Operator* op = common.Call(desc2); |
239 Node* const node = | 257 Node* const node = |
240 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 258 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
241 EXPECT_TRUE(desc1->CanTailCall(node)); | 259 int stack_param_delta = 0; |
| 260 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 261 EXPECT_EQ(0, stack_param_delta); |
242 } | 262 } |
243 | 263 |
244 | 264 |
245 TEST_F(LinkageTailCall, MatchingStackParametersExtraCalleeRegisters) { | 265 TEST_F(LinkageTailCall, MatchingStackParametersExtraCalleeRegisters) { |
246 // Caller | 266 // Caller |
247 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 267 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
248 StackLocation(2), StackLocation(1), | 268 StackLocation(2), StackLocation(1), |
249 RegisterLocation(0), RegisterLocation(1)}; | 269 RegisterLocation(0), RegisterLocation(1)}; |
250 LocationSignature locations1(1, 3, location_array); | 270 LocationSignature locations1(1, 3, location_array); |
251 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 271 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
252 | 272 |
253 // Caller | 273 // Caller |
254 LocationSignature locations2(1, 5, location_array); | 274 LocationSignature locations2(1, 5, location_array); |
255 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); | 275 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations1); |
256 | 276 |
257 CommonOperatorBuilder common(zone()); | 277 CommonOperatorBuilder common(zone()); |
258 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 278 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
259 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 279 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
260 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 280 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
261 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 281 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
262 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); | 282 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); |
263 Node* parameters[] = {p0, p1, p2, p3, p4}; | 283 Node* parameters[] = {p0, p1, p2, p3, p4}; |
264 const Operator* op = common.Call(desc2); | 284 const Operator* op = common.Call(desc2); |
265 Node* const node = | 285 Node* const node = |
266 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 286 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
267 EXPECT_TRUE(desc1->CanTailCall(node)); | 287 int stack_param_delta = 0; |
| 288 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 289 EXPECT_EQ(0, stack_param_delta); |
268 } | 290 } |
269 | 291 |
270 | 292 |
271 TEST_F(LinkageTailCall, MatchingStackParametersExtraCallerRegistersAndStack) { | 293 TEST_F(LinkageTailCall, MatchingStackParametersExtraCallerRegistersAndStack) { |
272 // Caller | 294 // Caller |
273 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 295 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
274 StackLocation(2), StackLocation(1), | 296 StackLocation(2), StackLocation(1), |
275 RegisterLocation(0), StackLocation(4)}; | 297 RegisterLocation(0), StackLocation(4)}; |
276 LocationSignature locations1(1, 5, location_array); | 298 LocationSignature locations1(1, 5, location_array); |
277 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 299 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
278 | 300 |
279 // Caller | 301 // Caller |
280 LocationSignature locations2(1, 3, location_array); | 302 LocationSignature locations2(1, 3, location_array); |
281 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 303 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
282 | 304 |
283 CommonOperatorBuilder common(zone()); | 305 CommonOperatorBuilder common(zone()); |
284 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 306 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
285 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 307 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
286 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 308 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
287 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 309 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
288 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); | 310 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); |
289 Node* parameters[] = {p0, p1, p2, p3, p4}; | 311 Node* parameters[] = {p0, p1, p2, p3, p4}; |
290 const Operator* op = common.Call(desc2); | 312 const Operator* op = common.Call(desc2); |
291 Node* const node = | 313 Node* const node = |
292 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 314 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
293 EXPECT_FALSE(desc1->CanTailCall(node)); | 315 int stack_param_delta = 0; |
| 316 EXPECT_TRUE(desc1->CanTailCall(node, &stack_param_delta)); |
| 317 EXPECT_EQ(-1, stack_param_delta); |
294 } | 318 } |
295 | 319 |
296 | 320 |
297 TEST_F(LinkageTailCall, MatchingStackParametersExtraCalleeRegistersAndStack) { | 321 TEST_F(LinkageTailCall, MatchingStackParametersExtraCalleeRegistersAndStack) { |
298 // Caller | 322 // Caller |
299 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), | 323 LinkageLocation location_array[] = {RegisterLocation(0), StackLocation(3), |
300 StackLocation(2), RegisterLocation(0), | 324 StackLocation(2), RegisterLocation(0), |
301 RegisterLocation(1), StackLocation(4)}; | 325 RegisterLocation(1), StackLocation(4)}; |
302 LocationSignature locations1(1, 3, location_array); | 326 LocationSignature locations1(1, 3, location_array); |
303 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); | 327 CallDescriptor* desc1 = NewStandardCallDescriptor(&locations1); |
304 | 328 |
305 // Caller | 329 // Caller |
306 LocationSignature locations2(1, 5, location_array); | 330 LocationSignature locations2(1, 5, location_array); |
307 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); | 331 CallDescriptor* desc2 = NewStandardCallDescriptor(&locations2); |
308 | 332 |
309 CommonOperatorBuilder common(zone()); | 333 CommonOperatorBuilder common(zone()); |
310 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); | 334 Node* p0 = Node::New(zone(), 0, nullptr, 0, nullptr, false); |
311 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); | 335 Node* p1 = Node::New(zone(), 0, common.Parameter(0), 0, nullptr, false); |
312 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); | 336 Node* p2 = Node::New(zone(), 0, common.Parameter(1), 0, nullptr, false); |
313 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); | 337 Node* p3 = Node::New(zone(), 0, common.Parameter(2), 0, nullptr, false); |
314 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); | 338 Node* p4 = Node::New(zone(), 0, common.Parameter(3), 0, nullptr, false); |
315 Node* parameters[] = {p0, p1, p2, p3, p4}; | 339 Node* parameters[] = {p0, p1, p2, p3, p4}; |
316 const Operator* op = common.Call(desc2); | 340 const Operator* op = common.Call(desc2); |
317 Node* const node = | 341 Node* const node = |
318 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); | 342 Node::New(zone(), 1, op, arraysize(parameters), parameters, false); |
319 EXPECT_FALSE(desc1->CanTailCall(node)); | 343 int stack_param_delta = 0; |
| 344 EXPECT_FALSE(desc1->CanTailCall(node, &stack_param_delta)); |
| 345 EXPECT_EQ(1, stack_param_delta); |
320 } | 346 } |
321 | 347 |
322 } // namespace compiler | 348 } // namespace compiler |
323 } // namespace internal | 349 } // namespace internal |
324 } // namespace v8 | 350 } // namespace v8 |
OLD | NEW |