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

Side by Side Diff: test/cctest/compiler/call-tester.h

Issue 1150083006: [turbofan] Tester improvements; use CSignature and simplify ReturnValueTraits. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « test/cctest/compiler/c-signature.h ('k') | test/cctest/compiler/codegen-tester.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef V8_CCTEST_COMPILER_CALL_TESTER_H_ 5 #ifndef V8_CCTEST_COMPILER_CALL_TESTER_H_
6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_ 6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
11 11
12 #include "test/cctest/compiler/c-signature.h"
13
12 #if V8_TARGET_ARCH_IA32 14 #if V8_TARGET_ARCH_IA32
13 #if __GNUC__ 15 #if __GNUC__
14 #define V8_CDECL __attribute__((cdecl)) 16 #define V8_CDECL __attribute__((cdecl))
15 #else 17 #else
16 #define V8_CDECL __cdecl 18 #define V8_CDECL __cdecl
17 #endif 19 #endif
18 #else 20 #else
19 #define V8_CDECL 21 #define V8_CDECL
20 #endif 22 #endif
21 23
22 namespace v8 { 24 namespace v8 {
23 namespace internal { 25 namespace internal {
24 namespace compiler { 26 namespace compiler {
25 27
26 // TODO(titzer): use c-signature.h instead of ReturnValueTraits
27 template <typename R> 28 template <typename R>
28 struct ReturnValueTraits { 29 inline R CastReturnValue(uintptr_t r) {
29 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } 30 return reinterpret_cast<R>(r);
30 static MachineType Representation() { 31 }
31 // TODO(dcarney): detect when R is of a subclass of Object* instead of this
32 // type check.
33 while (false) {
34 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0);
35 }
36 return kMachAnyTagged;
37 }
38 };
39 32
40 template <> 33 template <>
41 struct ReturnValueTraits<int32_t*> { 34 inline void CastReturnValue(uintptr_t r) {}
42 static int32_t* Cast(uintptr_t r) { return reinterpret_cast<int32_t*>(r); }
43 static MachineType Representation() { return kMachPtr; }
44 };
45 35
46 template <> 36 template <>
47 struct ReturnValueTraits<void> { 37 inline bool CastReturnValue(uintptr_t r) {
48 static void Cast(uintptr_t r) {} 38 return static_cast<bool>(r);
49 static MachineType Representation() { return kMachPtr; } 39 }
50 };
51 40
52 template <> 41 template <>
53 struct ReturnValueTraits<bool> { 42 inline int32_t CastReturnValue(uintptr_t r) {
54 static bool Cast(uintptr_t r) { return static_cast<bool>(r); } 43 return static_cast<int32_t>(r);
55 static MachineType Representation() { return kRepBit; } 44 }
56 };
57 45
58 template <> 46 template <>
59 struct ReturnValueTraits<int32_t> { 47 inline uint32_t CastReturnValue(uintptr_t r) {
60 static int32_t Cast(uintptr_t r) { return static_cast<int32_t>(r); } 48 return static_cast<uint32_t>(r);
61 static MachineType Representation() { return kMachInt32; } 49 }
62 };
63 50
64 template <> 51 template <>
65 struct ReturnValueTraits<uint32_t> { 52 inline int64_t CastReturnValue(uintptr_t r) {
66 static uint32_t Cast(uintptr_t r) { return static_cast<uint32_t>(r); } 53 return static_cast<int64_t>(r);
67 static MachineType Representation() { return kMachUint32; } 54 }
68 };
69 55
70 template <> 56 template <>
71 struct ReturnValueTraits<int64_t> { 57 inline uint64_t CastReturnValue(uintptr_t r) {
72 static int64_t Cast(uintptr_t r) { return static_cast<int64_t>(r); } 58 return static_cast<uint64_t>(r);
73 static MachineType Representation() { return kMachInt64; } 59 }
74 };
75 60
76 template <> 61 template <>
77 struct ReturnValueTraits<uint64_t> { 62 inline int16_t CastReturnValue(uintptr_t r) {
78 static uint64_t Cast(uintptr_t r) { return static_cast<uint64_t>(r); } 63 return static_cast<int16_t>(r);
79 static MachineType Representation() { return kMachUint64; } 64 }
80 };
81 65
82 template <> 66 template <>
83 struct ReturnValueTraits<int16_t> { 67 inline uint16_t CastReturnValue(uintptr_t r) {
84 static int16_t Cast(uintptr_t r) { return static_cast<int16_t>(r); } 68 return static_cast<uint16_t>(r);
85 static MachineType Representation() { return kMachInt16; } 69 }
86 };
87 70
88 template <> 71 template <>
89 struct ReturnValueTraits<uint16_t> { 72 inline int8_t CastReturnValue(uintptr_t r) {
90 static uint16_t Cast(uintptr_t r) { return static_cast<uint16_t>(r); } 73 return static_cast<int8_t>(r);
91 static MachineType Representation() { return kMachUint16; } 74 }
92 };
93 75
94 template <> 76 template <>
95 struct ReturnValueTraits<int8_t> { 77 inline uint8_t CastReturnValue(uintptr_t r) {
96 static int8_t Cast(uintptr_t r) { return static_cast<int8_t>(r); } 78 return static_cast<uint8_t>(r);
97 static MachineType Representation() { return kMachInt8; } 79 }
98 };
99 80
100 template <> 81 template <>
101 struct ReturnValueTraits<uint8_t> { 82 inline double CastReturnValue(uintptr_t r) {
102 static uint8_t Cast(uintptr_t r) { return static_cast<uint8_t>(r); } 83 UNREACHABLE();
103 static MachineType Representation() { return kMachUint8; } 84 return 0.0;
104 }; 85 }
105
106 template <>
107 struct ReturnValueTraits<double> {
108 static double Cast(uintptr_t r) {
109 UNREACHABLE();
110 return 0.0;
111 }
112 static MachineType Representation() { return kMachFloat64; }
113 };
114
115 86
116 template <typename R> 87 template <typename R>
117 struct ParameterTraits { 88 struct ParameterTraits {
118 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); } 89 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); }
119 }; 90 };
120 91
121 template <> 92 template <>
122 struct ParameterTraits<int*> { 93 struct ParameterTraits<int*> {
123 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } 94 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); }
124 }; 95 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 private: 177 private:
207 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 178 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64
208 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { 179 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) {
209 Simulator* simulator = Simulator::current(isolate_); 180 Simulator* simulator = Simulator::current(isolate_);
210 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); 181 return static_cast<uintptr_t>(simulator->CallInt64(f, args));
211 } 182 }
212 183
213 template <typename F> 184 template <typename F>
214 R DoCall(F* f) { 185 R DoCall(F* f) {
215 Simulator::CallArgument args[] = {Simulator::CallArgument::End()}; 186 Simulator::CallArgument args[] = {Simulator::CallArgument::End()};
216 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f), args)); 187 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f), args));
217 } 188 }
218 template <typename F, typename P1> 189 template <typename F, typename P1>
219 R DoCall(F* f, P1 p1) { 190 R DoCall(F* f, P1 p1) {
220 Simulator::CallArgument args[] = {Simulator::CallArgument(p1), 191 Simulator::CallArgument args[] = {Simulator::CallArgument(p1),
221 Simulator::CallArgument::End()}; 192 Simulator::CallArgument::End()};
222 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f), args)); 193 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f), args));
223 } 194 }
224 template <typename F, typename P1, typename P2> 195 template <typename F, typename P1, typename P2>
225 R DoCall(F* f, P1 p1, P2 p2) { 196 R DoCall(F* f, P1 p1, P2 p2) {
226 Simulator::CallArgument args[] = {Simulator::CallArgument(p1), 197 Simulator::CallArgument args[] = {Simulator::CallArgument(p1),
227 Simulator::CallArgument(p2), 198 Simulator::CallArgument(p2),
228 Simulator::CallArgument::End()}; 199 Simulator::CallArgument::End()};
229 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f), args)); 200 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f), args));
230 } 201 }
231 template <typename F, typename P1, typename P2, typename P3> 202 template <typename F, typename P1, typename P2, typename P3>
232 R DoCall(F* f, P1 p1, P2 p2, P3 p3) { 203 R DoCall(F* f, P1 p1, P2 p2, P3 p3) {
233 Simulator::CallArgument args[] = { 204 Simulator::CallArgument args[] = {
234 Simulator::CallArgument(p1), Simulator::CallArgument(p2), 205 Simulator::CallArgument(p1), Simulator::CallArgument(p2),
235 Simulator::CallArgument(p3), Simulator::CallArgument::End()}; 206 Simulator::CallArgument(p3), Simulator::CallArgument::End()};
236 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f), args)); 207 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f), args));
237 } 208 }
238 template <typename F, typename P1, typename P2, typename P3, typename P4> 209 template <typename F, typename P1, typename P2, typename P3, typename P4>
239 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) { 210 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) {
240 Simulator::CallArgument args[] = { 211 Simulator::CallArgument args[] = {
241 Simulator::CallArgument(p1), Simulator::CallArgument(p2), 212 Simulator::CallArgument(p1), Simulator::CallArgument(p2),
242 Simulator::CallArgument(p3), Simulator::CallArgument(p4), 213 Simulator::CallArgument(p3), Simulator::CallArgument(p4),
243 Simulator::CallArgument::End()}; 214 Simulator::CallArgument::End()};
244 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f), args)); 215 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f), args));
245 } 216 }
246 #elif USE_SIMULATOR && (V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64) 217 #elif USE_SIMULATOR && (V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64)
247 uintptr_t CallSimulator(byte* f, int64_t p1 = 0, int64_t p2 = 0, 218 uintptr_t CallSimulator(byte* f, int64_t p1 = 0, int64_t p2 = 0,
248 int64_t p3 = 0, int64_t p4 = 0) { 219 int64_t p3 = 0, int64_t p4 = 0) {
249 Simulator* simulator = Simulator::current(isolate_); 220 Simulator* simulator = Simulator::current(isolate_);
250 return static_cast<uintptr_t>(simulator->Call(f, 4, p1, p2, p3, p4)); 221 return static_cast<uintptr_t>(simulator->Call(f, 4, p1, p2, p3, p4));
251 } 222 }
252 223
253 224
254 template <typename F> 225 template <typename F>
255 R DoCall(F* f) { 226 R DoCall(F* f) {
256 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f))); 227 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f)));
257 } 228 }
258 template <typename F, typename P1> 229 template <typename F, typename P1>
259 R DoCall(F* f, P1 p1) { 230 R DoCall(F* f, P1 p1) {
260 return ReturnValueTraits<R>::Cast( 231 return CastReturnValue<R>(
261 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1))); 232 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1)));
262 } 233 }
263 template <typename F, typename P1, typename P2> 234 template <typename F, typename P1, typename P2>
264 R DoCall(F* f, P1 p1, P2 p2) { 235 R DoCall(F* f, P1 p1, P2 p2) {
265 return ReturnValueTraits<R>::Cast( 236 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f),
266 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 237 ParameterTraits<P1>::Cast(p1),
267 ParameterTraits<P2>::Cast(p2))); 238 ParameterTraits<P2>::Cast(p2)));
268 } 239 }
269 template <typename F, typename P1, typename P2, typename P3> 240 template <typename F, typename P1, typename P2, typename P3>
270 R DoCall(F* f, P1 p1, P2 p2, P3 p3) { 241 R DoCall(F* f, P1 p1, P2 p2, P3 p3) {
271 return ReturnValueTraits<R>::Cast(CallSimulator( 242 return CastReturnValue<R>(CallSimulator(
272 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 243 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1),
273 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3))); 244 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3)));
274 } 245 }
275 template <typename F, typename P1, typename P2, typename P3, typename P4> 246 template <typename F, typename P1, typename P2, typename P3, typename P4>
276 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) { 247 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) {
277 return ReturnValueTraits<R>::Cast(CallSimulator( 248 return CastReturnValue<R>(CallSimulator(
278 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 249 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1),
279 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3), 250 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3),
280 ParameterTraits<P4>::Cast(p4))); 251 ParameterTraits<P4>::Cast(p4)));
281 } 252 }
282 #elif USE_SIMULATOR && \ 253 #elif USE_SIMULATOR && \
283 (V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_PPC) 254 (V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_PPC)
284 uintptr_t CallSimulator(byte* f, int32_t p1 = 0, int32_t p2 = 0, 255 uintptr_t CallSimulator(byte* f, int32_t p1 = 0, int32_t p2 = 0,
285 int32_t p3 = 0, int32_t p4 = 0) { 256 int32_t p3 = 0, int32_t p4 = 0) {
286 Simulator* simulator = Simulator::current(isolate_); 257 Simulator* simulator = Simulator::current(isolate_);
287 return static_cast<uintptr_t>(simulator->Call(f, 4, p1, p2, p3, p4)); 258 return static_cast<uintptr_t>(simulator->Call(f, 4, p1, p2, p3, p4));
288 } 259 }
289 template <typename F> 260 template <typename F>
290 R DoCall(F* f) { 261 R DoCall(F* f) {
291 return ReturnValueTraits<R>::Cast(CallSimulator(FUNCTION_ADDR(f))); 262 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f)));
292 } 263 }
293 template <typename F, typename P1> 264 template <typename F, typename P1>
294 R DoCall(F* f, P1 p1) { 265 R DoCall(F* f, P1 p1) {
295 return ReturnValueTraits<R>::Cast( 266 return CastReturnValue<R>(
296 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1))); 267 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1)));
297 } 268 }
298 template <typename F, typename P1, typename P2> 269 template <typename F, typename P1, typename P2>
299 R DoCall(F* f, P1 p1, P2 p2) { 270 R DoCall(F* f, P1 p1, P2 p2) {
300 return ReturnValueTraits<R>::Cast( 271 return CastReturnValue<R>(CallSimulator(FUNCTION_ADDR(f),
301 CallSimulator(FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 272 ParameterTraits<P1>::Cast(p1),
302 ParameterTraits<P2>::Cast(p2))); 273 ParameterTraits<P2>::Cast(p2)));
303 } 274 }
304 template <typename F, typename P1, typename P2, typename P3> 275 template <typename F, typename P1, typename P2, typename P3>
305 R DoCall(F* f, P1 p1, P2 p2, P3 p3) { 276 R DoCall(F* f, P1 p1, P2 p2, P3 p3) {
306 return ReturnValueTraits<R>::Cast(CallSimulator( 277 return CastReturnValue<R>(CallSimulator(
307 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 278 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1),
308 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3))); 279 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3)));
309 } 280 }
310 template <typename F, typename P1, typename P2, typename P3, typename P4> 281 template <typename F, typename P1, typename P2, typename P3, typename P4>
311 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) { 282 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) {
312 return ReturnValueTraits<R>::Cast(CallSimulator( 283 return CastReturnValue<R>(CallSimulator(
313 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1), 284 FUNCTION_ADDR(f), ParameterTraits<P1>::Cast(p1),
314 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3), 285 ParameterTraits<P2>::Cast(p2), ParameterTraits<P3>::Cast(p3),
315 ParameterTraits<P4>::Cast(p4))); 286 ParameterTraits<P4>::Cast(p4)));
316 } 287 }
317 #else 288 #else
318 template <typename F> 289 template <typename F>
319 R DoCall(F* f) { 290 R DoCall(F* f) {
320 return f(); 291 return f();
321 } 292 }
322 template <typename F, typename P1> 293 template <typename F, typename P1>
(...skipping 26 matching lines...) Expand all
349 template <typename P1, typename P2, typename P3> 320 template <typename P1, typename P2, typename P3>
350 void VerifyParameters3() {} 321 void VerifyParameters3() {}
351 322
352 template <typename P1, typename P2, typename P3, typename P4> 323 template <typename P1, typename P2, typename P3, typename P4>
353 void VerifyParameters4() {} 324 void VerifyParameters4() {}
354 #else 325 #else
355 void VerifyParameters0() { VerifyParameters(0, NULL); } 326 void VerifyParameters0() { VerifyParameters(0, NULL); }
356 327
357 template <typename P1> 328 template <typename P1>
358 void VerifyParameters1() { 329 void VerifyParameters1() {
359 MachineType parameters[] = {ReturnValueTraits<P1>::Representation()}; 330 MachineType parameters[] = {MachineTypeForC<P1>()};
360 VerifyParameters(arraysize(parameters), parameters); 331 VerifyParameters(arraysize(parameters), parameters);
361 } 332 }
362 333
363 template <typename P1, typename P2> 334 template <typename P1, typename P2>
364 void VerifyParameters2() { 335 void VerifyParameters2() {
365 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(), 336 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>()};
366 ReturnValueTraits<P2>::Representation()};
367 VerifyParameters(arraysize(parameters), parameters); 337 VerifyParameters(arraysize(parameters), parameters);
368 } 338 }
369 339
370 template <typename P1, typename P2, typename P3> 340 template <typename P1, typename P2, typename P3>
371 void VerifyParameters3() { 341 void VerifyParameters3() {
372 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(), 342 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
373 ReturnValueTraits<P2>::Representation(), 343 MachineTypeForC<P3>()};
374 ReturnValueTraits<P3>::Representation()};
375 VerifyParameters(arraysize(parameters), parameters); 344 VerifyParameters(arraysize(parameters), parameters);
376 } 345 }
377 346
378 template <typename P1, typename P2, typename P3, typename P4> 347 template <typename P1, typename P2, typename P3, typename P4>
379 void VerifyParameters4() { 348 void VerifyParameters4() {
380 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(), 349 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
381 ReturnValueTraits<P2>::Representation(), 350 MachineTypeForC<P3>(), MachineTypeForC<P4>()};
382 ReturnValueTraits<P3>::Representation(),
383 ReturnValueTraits<P4>::Representation()};
384 VerifyParameters(arraysize(parameters), parameters); 351 VerifyParameters(arraysize(parameters), parameters);
385 } 352 }
386 #endif 353 #endif
387 354
388 Isolate* isolate_; 355 Isolate* isolate_;
389 }; 356 };
390 357
391 } // namespace compiler 358 } // namespace compiler
392 } // namespace internal 359 } // namespace internal
393 } // namespace v8 360 } // namespace v8
394 361
395 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ 362 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_
OLDNEW
« no previous file with comments | « test/cctest/compiler/c-signature.h ('k') | test/cctest/compiler/codegen-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698