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

Side by Side Diff: src/compiler/linkage.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
« no previous file with comments | « src/compiler/linkage.h ('k') | src/compiler/live-range-separator.cc » ('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 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 #include "src/code-stubs.h" 6 #include "src/code-stubs.h"
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/common-operator.h" 8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/frame.h" 9 #include "src/compiler/frame.h"
10 #include "src/compiler/linkage.h" 10 #include "src/compiler/linkage.h"
11 #include "src/compiler/node.h" 11 #include "src/compiler/node.h"
12 #include "src/compiler/osr.h" 12 #include "src/compiler/osr.h"
13 #include "src/compiler/pipeline.h" 13 #include "src/compiler/pipeline.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 namespace compiler { 17 namespace compiler {
18 18
19 namespace { 19 namespace {
20 LinkageLocation regloc(Register reg) { 20 LinkageLocation regloc(Register reg) {
21 return LinkageLocation::ForRegister(reg.code()); 21 return LinkageLocation::ForRegister(reg.code());
22 } 22 }
23 23
24 24
25 MachineType reptyp(Representation representation) { 25 MachineType reptyp(Representation representation) {
26 switch (representation.kind()) { 26 switch (representation.kind()) {
27 case Representation::kInteger8: 27 case Representation::kInteger8:
28 return kMachInt8; 28 return MachineType::Int8();
29 case Representation::kUInteger8: 29 case Representation::kUInteger8:
30 return kMachUint8; 30 return MachineType::Uint8();
31 case Representation::kInteger16: 31 case Representation::kInteger16:
32 return kMachInt16; 32 return MachineType::Int16();
33 case Representation::kUInteger16: 33 case Representation::kUInteger16:
34 return kMachUint16; 34 return MachineType::Uint16();
35 case Representation::kInteger32: 35 case Representation::kInteger32:
36 return kMachInt32; 36 return MachineType::Int32();
37 case Representation::kSmi: 37 case Representation::kSmi:
38 case Representation::kTagged: 38 case Representation::kTagged:
39 case Representation::kHeapObject: 39 case Representation::kHeapObject:
40 return kMachAnyTagged; 40 return MachineType::AnyTagged();
41 case Representation::kDouble: 41 case Representation::kDouble:
42 return kMachFloat64; 42 return MachineType::Float64();
43 case Representation::kExternal: 43 case Representation::kExternal:
44 return kMachPtr; 44 return MachineType::Pointer();
45 case Representation::kNone: 45 case Representation::kNone:
46 case Representation::kNumRepresentations: 46 case Representation::kNumRepresentations:
47 break; 47 break;
48 } 48 }
49 UNREACHABLE(); 49 UNREACHABLE();
50 return kMachNone; 50 return MachineType::None();
51 } 51 }
52 } // namespace 52 } // namespace
53 53
54 54
55 std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) { 55 std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) {
56 switch (k) { 56 switch (k) {
57 case CallDescriptor::kCallCodeObject: 57 case CallDescriptor::kCallCodeObject:
58 os << "Code"; 58 os << "Code";
59 break; 59 break;
60 case CallDescriptor::kCallJSFunction: 60 case CallDescriptor::kCallJSFunction:
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 MachineSignature::Builder types(zone, return_count, parameter_count); 235 MachineSignature::Builder types(zone, return_count, parameter_count);
236 236
237 // Add returns. 237 // Add returns.
238 if (locations.return_count_ > 0) { 238 if (locations.return_count_ > 0) {
239 locations.AddReturn(regloc(kReturnRegister0)); 239 locations.AddReturn(regloc(kReturnRegister0));
240 } 240 }
241 if (locations.return_count_ > 1) { 241 if (locations.return_count_ > 1) {
242 locations.AddReturn(regloc(kReturnRegister1)); 242 locations.AddReturn(regloc(kReturnRegister1));
243 } 243 }
244 for (size_t i = 0; i < return_count; i++) { 244 for (size_t i = 0; i < return_count; i++) {
245 types.AddReturn(kMachAnyTagged); 245 types.AddReturn(MachineType::AnyTagged());
246 } 246 }
247 247
248 // All parameters to the runtime call go on the stack. 248 // All parameters to the runtime call go on the stack.
249 for (int i = 0; i < js_parameter_count; i++) { 249 for (int i = 0; i < js_parameter_count; i++) {
250 locations.AddParam( 250 locations.AddParam(
251 LinkageLocation::ForCallerFrameSlot(i - js_parameter_count)); 251 LinkageLocation::ForCallerFrameSlot(i - js_parameter_count));
252 types.AddParam(kMachAnyTagged); 252 types.AddParam(MachineType::AnyTagged());
253 } 253 }
254 // Add runtime function itself. 254 // Add runtime function itself.
255 locations.AddParam(regloc(kRuntimeCallFunctionRegister)); 255 locations.AddParam(regloc(kRuntimeCallFunctionRegister));
256 types.AddParam(kMachAnyTagged); 256 types.AddParam(MachineType::AnyTagged());
257 257
258 // Add runtime call argument count. 258 // Add runtime call argument count.
259 locations.AddParam(regloc(kRuntimeCallArgCountRegister)); 259 locations.AddParam(regloc(kRuntimeCallArgCountRegister));
260 types.AddParam(kMachPtr); 260 types.AddParam(MachineType::Pointer());
261 261
262 // Add context. 262 // Add context.
263 locations.AddParam(regloc(kContextRegister)); 263 locations.AddParam(regloc(kContextRegister));
264 types.AddParam(kMachAnyTagged); 264 types.AddParam(MachineType::AnyTagged());
265 265
266 if (Linkage::FrameStateInputCount(function_id) == 0) { 266 if (Linkage::FrameStateInputCount(function_id) == 0) {
267 flags = static_cast<CallDescriptor::Flags>( 267 flags = static_cast<CallDescriptor::Flags>(
268 flags & ~CallDescriptor::kNeedsFrameState); 268 flags & ~CallDescriptor::kNeedsFrameState);
269 } 269 }
270 270
271 // The target for runtime calls is a code object. 271 // The target for runtime calls is a code object.
272 MachineType target_type = kMachAnyTagged; 272 MachineType target_type = MachineType::AnyTagged();
273 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); 273 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
274 return new (zone) CallDescriptor( // -- 274 return new (zone) CallDescriptor( // --
275 CallDescriptor::kCallCodeObject, // kind 275 CallDescriptor::kCallCodeObject, // kind
276 target_type, // target MachineType 276 target_type, // target MachineType
277 target_loc, // target location 277 target_loc, // target location
278 types.Build(), // machine_sig 278 types.Build(), // machine_sig
279 locations.Build(), // location_sig 279 locations.Build(), // location_sig
280 js_parameter_count, // stack_parameter_count 280 js_parameter_count, // stack_parameter_count
281 properties, // properties 281 properties, // properties
282 kNoCalleeSaved, // callee-saved 282 kNoCalleeSaved, // callee-saved
283 kNoCalleeSaved, // callee-saved fp 283 kNoCalleeSaved, // callee-saved fp
284 flags, // flags 284 flags, // flags
285 function->name); // debug name 285 function->name); // debug name
286 } 286 }
287 287
288 288
289 CallDescriptor* Linkage::GetLazyBailoutDescriptor(Zone* zone) { 289 CallDescriptor* Linkage::GetLazyBailoutDescriptor(Zone* zone) {
290 const size_t return_count = 0; 290 const size_t return_count = 0;
291 const size_t parameter_count = 0; 291 const size_t parameter_count = 0;
292 292
293 LocationSignature::Builder locations(zone, return_count, parameter_count); 293 LocationSignature::Builder locations(zone, return_count, parameter_count);
294 MachineSignature::Builder types(zone, return_count, parameter_count); 294 MachineSignature::Builder types(zone, return_count, parameter_count);
295 295
296 // The target is ignored, but we need to give some values here. 296 // The target is ignored, but we need to give some values here.
297 MachineType target_type = kMachAnyTagged; 297 MachineType target_type = MachineType::AnyTagged();
298 LinkageLocation target_loc = regloc(kJSFunctionRegister); 298 LinkageLocation target_loc = regloc(kJSFunctionRegister);
299 return new (zone) CallDescriptor( // -- 299 return new (zone) CallDescriptor( // --
300 CallDescriptor::kLazyBailout, // kind 300 CallDescriptor::kLazyBailout, // kind
301 target_type, // target MachineType 301 target_type, // target MachineType
302 target_loc, // target location 302 target_loc, // target location
303 types.Build(), // machine_sig 303 types.Build(), // machine_sig
304 locations.Build(), // location_sig 304 locations.Build(), // location_sig
305 0, // stack_parameter_count 305 0, // stack_parameter_count
306 Operator::kNoThrow, // properties 306 Operator::kNoThrow, // properties
307 kNoCalleeSaved, // callee-saved 307 kNoCalleeSaved, // callee-saved
(...skipping 11 matching lines...) Expand all
319 const size_t new_target_count = 1; 319 const size_t new_target_count = 1;
320 const size_t num_args_count = 1; 320 const size_t num_args_count = 1;
321 const size_t parameter_count = 321 const size_t parameter_count =
322 js_parameter_count + new_target_count + num_args_count + context_count; 322 js_parameter_count + new_target_count + num_args_count + context_count;
323 323
324 LocationSignature::Builder locations(zone, return_count, parameter_count); 324 LocationSignature::Builder locations(zone, return_count, parameter_count);
325 MachineSignature::Builder types(zone, return_count, parameter_count); 325 MachineSignature::Builder types(zone, return_count, parameter_count);
326 326
327 // All JS calls have exactly one return value. 327 // All JS calls have exactly one return value.
328 locations.AddReturn(regloc(kReturnRegister0)); 328 locations.AddReturn(regloc(kReturnRegister0));
329 types.AddReturn(kMachAnyTagged); 329 types.AddReturn(MachineType::AnyTagged());
330 330
331 // All parameters to JS calls go on the stack. 331 // All parameters to JS calls go on the stack.
332 for (int i = 0; i < js_parameter_count; i++) { 332 for (int i = 0; i < js_parameter_count; i++) {
333 int spill_slot_index = i - js_parameter_count; 333 int spill_slot_index = i - js_parameter_count;
334 locations.AddParam(LinkageLocation::ForCallerFrameSlot(spill_slot_index)); 334 locations.AddParam(LinkageLocation::ForCallerFrameSlot(spill_slot_index));
335 types.AddParam(kMachAnyTagged); 335 types.AddParam(MachineType::AnyTagged());
336 } 336 }
337 337
338 // Add JavaScript call new target value. 338 // Add JavaScript call new target value.
339 locations.AddParam(regloc(kJavaScriptCallNewTargetRegister)); 339 locations.AddParam(regloc(kJavaScriptCallNewTargetRegister));
340 types.AddParam(kMachAnyTagged); 340 types.AddParam(MachineType::AnyTagged());
341 341
342 // Add JavaScript call argument count. 342 // Add JavaScript call argument count.
343 locations.AddParam(regloc(kJavaScriptCallArgCountRegister)); 343 locations.AddParam(regloc(kJavaScriptCallArgCountRegister));
344 types.AddParam(kMachInt32); 344 types.AddParam(MachineType::Int32());
345 345
346 // Add context. 346 // Add context.
347 locations.AddParam(regloc(kContextRegister)); 347 locations.AddParam(regloc(kContextRegister));
348 types.AddParam(kMachAnyTagged); 348 types.AddParam(MachineType::AnyTagged());
349 349
350 // The target for JS function calls is the JSFunction object. 350 // The target for JS function calls is the JSFunction object.
351 MachineType target_type = kMachAnyTagged; 351 MachineType target_type = MachineType::AnyTagged();
352 // TODO(titzer): When entering into an OSR function from unoptimized code, 352 // TODO(titzer): When entering into an OSR function from unoptimized code,
353 // the JSFunction is not in a register, but it is on the stack in an 353 // the JSFunction is not in a register, but it is on the stack in an
354 // unaddressable spill slot. We hack this in the OSR prologue. Fix. 354 // unaddressable spill slot. We hack this in the OSR prologue. Fix.
355 LinkageLocation target_loc = regloc(kJSFunctionRegister); 355 LinkageLocation target_loc = regloc(kJSFunctionRegister);
356 return new (zone) CallDescriptor( // -- 356 return new (zone) CallDescriptor( // --
357 CallDescriptor::kCallJSFunction, // kind 357 CallDescriptor::kCallJSFunction, // kind
358 target_type, // target MachineType 358 target_type, // target MachineType
359 target_loc, // target location 359 target_loc, // target location
360 types.Build(), // machine_sig 360 types.Build(), // machine_sig
361 locations.Build(), // location_sig 361 locations.Build(), // location_sig
362 js_parameter_count, // stack_parameter_count 362 js_parameter_count, // stack_parameter_count
363 Operator::kNoProperties, // properties 363 Operator::kNoProperties, // properties
364 kNoCalleeSaved, // callee-saved 364 kNoCalleeSaved, // callee-saved
365 kNoCalleeSaved, // callee-saved fp 365 kNoCalleeSaved, // callee-saved fp
366 CallDescriptor::kCanUseRoots | // flags 366 CallDescriptor::kCanUseRoots | // flags
367 flags, // flags 367 flags, // flags
368 "js-call"); 368 "js-call");
369 } 369 }
370 370
371 371
372 CallDescriptor* Linkage::GetInterpreterDispatchDescriptor(Zone* zone) { 372 CallDescriptor* Linkage::GetInterpreterDispatchDescriptor(Zone* zone) {
373 MachineSignature::Builder types(zone, 0, 6); 373 MachineSignature::Builder types(zone, 0, 6);
374 LocationSignature::Builder locations(zone, 0, 6); 374 LocationSignature::Builder locations(zone, 0, 6);
375 375
376 // Add registers for fixed parameters passed via interpreter dispatch. 376 // Add registers for fixed parameters passed via interpreter dispatch.
377 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter); 377 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter);
378 types.AddParam(kMachAnyTagged); 378 types.AddParam(MachineType::AnyTagged());
379 locations.AddParam(regloc(kInterpreterAccumulatorRegister)); 379 locations.AddParam(regloc(kInterpreterAccumulatorRegister));
380 380
381 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter); 381 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter);
382 types.AddParam(kMachPtr); 382 types.AddParam(MachineType::Pointer());
383 locations.AddParam(regloc(kInterpreterRegisterFileRegister)); 383 locations.AddParam(regloc(kInterpreterRegisterFileRegister));
384 384
385 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter); 385 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter);
386 types.AddParam(kMachIntPtr); 386 types.AddParam(MachineType::IntPtr());
387 locations.AddParam(regloc(kInterpreterBytecodeOffsetRegister)); 387 locations.AddParam(regloc(kInterpreterBytecodeOffsetRegister));
388 388
389 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter); 389 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter);
390 types.AddParam(kMachAnyTagged); 390 types.AddParam(MachineType::AnyTagged());
391 locations.AddParam(regloc(kInterpreterBytecodeArrayRegister)); 391 locations.AddParam(regloc(kInterpreterBytecodeArrayRegister));
392 392
393 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter); 393 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter);
394 types.AddParam(kMachPtr); 394 types.AddParam(MachineType::Pointer());
395 #if defined(V8_TARGET_ARCH_IA32) || defined(V8_TARGET_ARCH_X87) 395 #if defined(V8_TARGET_ARCH_IA32) || defined(V8_TARGET_ARCH_X87)
396 // TODO(rmcilroy): Make the context param the one spilled to the stack once 396 // TODO(rmcilroy): Make the context param the one spilled to the stack once
397 // Turbofan supports modified stack arguments in tail calls. 397 // Turbofan supports modified stack arguments in tail calls.
398 locations.AddParam( 398 locations.AddParam(
399 LinkageLocation::ForCallerFrameSlot(kInterpreterDispatchTableSpillSlot)); 399 LinkageLocation::ForCallerFrameSlot(kInterpreterDispatchTableSpillSlot));
400 #else 400 #else
401 locations.AddParam(regloc(kInterpreterDispatchTableRegister)); 401 locations.AddParam(regloc(kInterpreterDispatchTableRegister));
402 #endif 402 #endif
403 403
404 STATIC_ASSERT(5 == Linkage::kInterpreterContextParameter); 404 STATIC_ASSERT(5 == Linkage::kInterpreterContextParameter);
405 types.AddParam(kMachAnyTagged); 405 types.AddParam(MachineType::AnyTagged());
406 locations.AddParam(regloc(kContextRegister)); 406 locations.AddParam(regloc(kContextRegister));
407 407
408 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); 408 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
409 return new (zone) CallDescriptor( // -- 409 return new (zone) CallDescriptor( // --
410 CallDescriptor::kCallCodeObject, // kind 410 CallDescriptor::kCallCodeObject, // kind
411 kMachNone, // target MachineType 411 MachineType::None(), // target MachineType
412 target_loc, // target location 412 target_loc, // target location
413 types.Build(), // machine_sig 413 types.Build(), // machine_sig
414 locations.Build(), // location_sig 414 locations.Build(), // location_sig
415 0, // stack_parameter_count 415 0, // stack_parameter_count
416 Operator::kNoProperties, // properties 416 Operator::kNoProperties, // properties
417 kNoCalleeSaved, // callee-saved registers 417 kNoCalleeSaved, // callee-saved registers
418 kNoCalleeSaved, // callee-saved fp regs 418 kNoCalleeSaved, // callee-saved fp regs
419 CallDescriptor::kSupportsTailCalls | // flags 419 CallDescriptor::kSupportsTailCalls | // flags
420 CallDescriptor::kCanUseRoots, // flags 420 CallDescriptor::kCanUseRoots, // flags
421 "interpreter-dispatch"); 421 "interpreter-dispatch");
(...skipping 28 matching lines...) Expand all
450 // The first parameters go in registers. 450 // The first parameters go in registers.
451 Register reg = descriptor.GetRegisterParameter(i); 451 Register reg = descriptor.GetRegisterParameter(i);
452 Representation rep = 452 Representation rep =
453 RepresentationFromType(descriptor.GetParameterType(i)); 453 RepresentationFromType(descriptor.GetParameterType(i));
454 locations.AddParam(regloc(reg)); 454 locations.AddParam(regloc(reg));
455 types.AddParam(reptyp(rep)); 455 types.AddParam(reptyp(rep));
456 } else { 456 } else {
457 // The rest of the parameters go on the stack. 457 // The rest of the parameters go on the stack.
458 int stack_slot = i - register_parameter_count - stack_parameter_count; 458 int stack_slot = i - register_parameter_count - stack_parameter_count;
459 locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot)); 459 locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot));
460 types.AddParam(kMachAnyTagged); 460 types.AddParam(MachineType::AnyTagged());
461 } 461 }
462 } 462 }
463 // Add context. 463 // Add context.
464 locations.AddParam(regloc(kContextRegister)); 464 locations.AddParam(regloc(kContextRegister));
465 types.AddParam(kMachAnyTagged); 465 types.AddParam(MachineType::AnyTagged());
466 466
467 // The target for stub calls is a code object. 467 // The target for stub calls is a code object.
468 MachineType target_type = kMachAnyTagged; 468 MachineType target_type = MachineType::AnyTagged();
469 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); 469 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
470 return new (zone) CallDescriptor( // -- 470 return new (zone) CallDescriptor( // --
471 CallDescriptor::kCallCodeObject, // kind 471 CallDescriptor::kCallCodeObject, // kind
472 target_type, // target MachineType 472 target_type, // target MachineType
473 target_loc, // target location 473 target_loc, // target location
474 types.Build(), // machine_sig 474 types.Build(), // machine_sig
475 locations.Build(), // location_sig 475 locations.Build(), // location_sig
476 stack_parameter_count, // stack_parameter_count 476 stack_parameter_count, // stack_parameter_count
477 properties, // properties 477 properties, // properties
478 kNoCalleeSaved, // callee-saved registers 478 kNoCalleeSaved, // callee-saved registers
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } else { 522 } else {
523 DCHECK(loc == regloc(kContextRegister)); 523 DCHECK(loc == regloc(kContextRegister));
524 return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot); 524 return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot);
525 } 525 }
526 } 526 }
527 527
528 528
529 } // namespace compiler 529 } // namespace compiler
530 } // namespace internal 530 } // namespace internal
531 } // namespace v8 531 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/linkage.h ('k') | src/compiler/live-range-separator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698