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