interface-descriptors.cc 18.1 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/interface-descriptors.h"

namespace v8 {
namespace internal {

10 11
namespace {
// Constructors for common combined semantic and representation types.
12 13
Type* SmiType(Zone* zone) {
  return Type::Intersect(Type::SignedSmall(), Type::TaggedSigned(), zone);
14 15 16
}


17 18
Type* UntaggedSigned32(Zone* zone) {
  return Type::Intersect(Type::Signed32(), Type::UntaggedSigned32(), zone);
19 20 21
}


22
Type* AnyTagged(Zone* zone) {
23
  return Type::Intersect(
24 25
      Type::Any(),
      Type::Union(Type::TaggedPointer(), Type::TaggedSigned(), zone), zone);
26 27 28
}


29 30
Type* ExternalPointer(Zone* zone) {
  return Type::Intersect(Type::Internal(), Type::UntaggedPointer(), zone);
31
}
32
}  // namespace
33 34 35 36


Type::FunctionType* CallInterfaceDescriptor::BuildDefaultFunctionType(
    Isolate* isolate, int parameter_count) {
37 38 39
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function = Type::FunctionType::New(
      AnyTagged(zone), Type::Undefined(), parameter_count, zone);
40
  while (parameter_count-- != 0) {
41
    function->InitParameter(parameter_count, AnyTagged(zone));
42 43 44 45 46 47
  }
  return function;
}


void CallInterfaceDescriptorData::InitializePlatformSpecific(
48 49 50 51 52 53 54 55 56 57 58 59
    int register_parameter_count, Register* registers,
    PlatformInterfaceDescriptor* platform_descriptor) {
  platform_specific_descriptor_ = platform_descriptor;
  register_param_count_ = register_parameter_count;

  // InterfaceDescriptor owns a copy of the registers array.
  register_params_.Reset(NewArray<Register>(register_parameter_count));
  for (int i = 0; i < register_parameter_count; i++) {
    register_params_[i] = registers[i];
  }
}

60
const char* CallInterfaceDescriptor::DebugName(Isolate* isolate) const {
61
  CallInterfaceDescriptorData* start = isolate->call_descriptor_data(0);
62
  size_t index = data_ - start;
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  DCHECK(index < CallDescriptors::NUMBER_OF_DESCRIPTORS);
  CallDescriptors::Key key = static_cast<CallDescriptors::Key>(index);
  switch (key) {
#define DEF_CASE(NAME)        \
  case CallDescriptors::NAME: \
    return #NAME " Descriptor";
    INTERFACE_DESCRIPTOR_LIST(DEF_CASE)
#undef DEF_CASE
    case CallDescriptors::NUMBER_OF_DESCRIPTORS:
      break;
  }
  return "";
}


78 79
Type::FunctionType* LoadDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
80 81 82 83 84 85
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, AnyTagged(zone));
  function->InitParameter(2, SmiType(zone));
86 87 88 89 90
  return function;
}

void LoadDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
91
  Register registers[] = {ReceiverRegister(), NameRegister(), SlotRegister()};
92
  data->InitializePlatformSpecific(arraysize(registers), registers);
93 94 95
}


96 97
void StoreDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
98
  Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister()};
99
  data->InitializePlatformSpecific(arraysize(registers), registers);
100 101 102
}


103 104 105 106 107 108 109 110 111
void StoreTransitionDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
  Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
                          MapRegister()};

  data->InitializePlatformSpecific(arraysize(registers), registers);
}


112 113 114
Type::FunctionType*
StoreTransitionDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
115 116 117 118 119 120 121
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 4, zone);
  function->InitParameter(0, AnyTagged(zone));  // Receiver
  function->InitParameter(1, AnyTagged(zone));  // Name
  function->InitParameter(2, AnyTagged(zone));  // Value
  function->InitParameter(3, AnyTagged(zone));  // Map
122
  return function;
123 124 125
}


126 127 128
Type::FunctionType*
LoadGlobalViaContextDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
129 130 131 132
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 1, zone);
  function->InitParameter(0, UntaggedSigned32(zone));
133 134 135 136 137 138
  return function;
}


void LoadGlobalViaContextDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
139
  Register registers[] = {SlotRegister()};
140 141 142 143 144 145 146
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


Type::FunctionType*
StoreGlobalViaContextDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
147 148 149 150 151
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 2, zone);
  function->InitParameter(0, UntaggedSigned32(zone));
  function->InitParameter(1, AnyTagged(zone));
152 153 154 155 156 157
  return function;
}


void StoreGlobalViaContextDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
158
  Register registers[] = {SlotRegister(), ValueRegister()};
159 160 161 162
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


163
void InstanceOfDescriptor::InitializePlatformSpecific(
164
    CallInterfaceDescriptorData* data) {
165
  Register registers[] = {LeftRegister(), RightRegister()};
166
  data->InitializePlatformSpecific(arraysize(registers), registers);
167 168 169
}


170 171 172 173 174 175 176
void StringCompareDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
  Register registers[] = {LeftRegister(), RightRegister()};
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


177 178 179 180 181 182 183
void ToStringDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
  Register registers[] = {ReceiverRegister()};
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


184 185 186 187 188 189 190
void ToObjectDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
  Register registers[] = {ReceiverRegister()};
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


191 192
void MathPowTaggedDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
193
  Register registers[] = {exponent()};
194
  data->InitializePlatformSpecific(arraysize(registers), registers);
195 196 197
}


198 199
void MathPowIntegerDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
200
  Register registers[] = {exponent()};
201 202 203 204 205 206 207
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


Type::FunctionType*
LoadWithVectorDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
208 209 210 211 212 213 214
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 4, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, AnyTagged(zone));
  function->InitParameter(2, SmiType(zone));
  function->InitParameter(3, AnyTagged(zone));
215
  return function;
216 217 218
}


219 220
void LoadWithVectorDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
221 222
  Register registers[] = {ReceiverRegister(), NameRegister(), SlotRegister(),
                          VectorRegister()};
223 224 225 226
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


227 228 229
Type::FunctionType*
VectorStoreTransitionDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
230 231 232 233 234 235 236 237 238
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 6, zone);
  function->InitParameter(0, AnyTagged(zone));  // receiver
  function->InitParameter(1, AnyTagged(zone));  // name
  function->InitParameter(2, AnyTagged(zone));  // value
  function->InitParameter(3, SmiType(zone));    // slot
  function->InitParameter(4, AnyTagged(zone));  // vector
  function->InitParameter(5, AnyTagged(zone));  // map
239 240 241 242
  return function;
}


243 244 245
Type::FunctionType*
VectorStoreICDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
246 247 248 249 250 251 252 253
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 5, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, AnyTagged(zone));
  function->InitParameter(2, AnyTagged(zone));
  function->InitParameter(3, SmiType(zone));
  function->InitParameter(4, AnyTagged(zone));
254
  return function;
255 256 257
}


258 259
void VectorStoreICDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
260 261
  Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
                          SlotRegister(), VectorRegister()};
262
  data->InitializePlatformSpecific(arraysize(registers), registers);
263 264 265
}


266 267 268
Type::FunctionType*
VectorStoreICTrampolineDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
269 270 271 272 273 274 275
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 4, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, AnyTagged(zone));
  function->InitParameter(2, AnyTagged(zone));
  function->InitParameter(3, SmiType(zone));
276 277 278 279 280
  return function;
}


void VectorStoreICTrampolineDescriptor::InitializePlatformSpecific(
281
    CallInterfaceDescriptorData* data) {
282 283
  Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
                          SlotRegister()};
284
  data->InitializePlatformSpecific(arraysize(registers), registers);
285 286 287
}


288 289 290
Type::FunctionType*
ApiGetterDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
291 292 293 294
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 1, zone);
  function->InitParameter(0, ExternalPointer(zone));
295 296 297 298 299 300
  return function;
}


void ApiGetterDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
301
  Register registers[] = {function_address()};
302
  data->InitializePlatformSpecific(arraysize(registers), registers);
303 304 305
}


306
void ArgumentsAccessReadDescriptor::InitializePlatformSpecific(
307
    CallInterfaceDescriptorData* data) {
308
  Register registers[] = {index(), parameter_count()};
309
  data->InitializePlatformSpecific(arraysize(registers), registers);
310 311 312
}


313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
Type::FunctionType*
ArgumentsAccessNewDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, ExternalPointer(zone));
  return function;
}


void ArgumentsAccessNewDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
  Register registers[] = {function(), parameter_count(), parameter_pointer()};
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


333 334
void ContextOnlyDescriptor::InitializePlatformSpecific(
    CallInterfaceDescriptorData* data) {
335
  data->InitializePlatformSpecific(0, nullptr);
336 337
}

338

339
void GrowArrayElementsDescriptor::InitializePlatformSpecific(
340
    CallInterfaceDescriptorData* data) {
341
  Register registers[] = {ObjectRegister(), KeyRegister()};
342 343 344 345 346 347 348
  data->InitializePlatformSpecific(arraysize(registers), registers);
}


Type::FunctionType*
FastCloneShallowArrayDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
349 350 351 352 353 354
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, AnyTagged(zone));
355 356 357 358 359 360 361
  return function;
}


Type::FunctionType*
CreateAllocationSiteDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
362 363 364 365 366
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 2, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, SmiType(zone));
367
  return function;
368
}
369 370 371 372 373


Type::FunctionType*
CreateWeakCellDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
374 375 376 377 378 379
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
  function->InitParameter(0, AnyTagged(zone));
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, AnyTagged(zone));
380 381 382 383
  return function;
}


384 385 386 387 388 389 390 391 392 393 394 395 396
Type::FunctionType*
CallTrampolineDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 2, zone);
  function->InitParameter(0, AnyTagged(zone));  // target
  function->InitParameter(
      1, UntaggedSigned32(zone));  // actual number of arguments
  return function;
}


397 398 399
Type::FunctionType*
CallFunctionWithFeedbackDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
400 401 402
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 2, zone);
403
  function->InitParameter(0, Type::Receiver());  // JSFunction
404
  function->InitParameter(1, SmiType(zone));
405 406 407 408 409 410 411
  return function;
}


Type::FunctionType* CallFunctionWithFeedbackAndVectorDescriptor::
    BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
                                             int paramater_count) {
412 413 414
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
415
  function->InitParameter(0, Type::Receiver());  // JSFunction
416 417
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, AnyTagged(zone));
418 419 420 421 422 423 424
  return function;
}


Type::FunctionType*
ArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
425 426 427
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
428
  function->InitParameter(0, Type::Receiver());  // JSFunction
429 430
  function->InitParameter(1, AnyTagged(zone));
  function->InitParameter(2, UntaggedSigned32(zone));
431 432 433 434 435 436 437
  return function;
}


Type::FunctionType*
InternalArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
438 439 440
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 2, zone);
441
  function->InitParameter(0, Type::Receiver());  // JSFunction
442
  function->InitParameter(1, UntaggedSigned32(zone));
443 444 445 446 447 448 449
  return function;
}


Type::FunctionType*
ArgumentAdaptorDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
450 451 452
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 3, zone);
453
  function->InitParameter(0, Type::Receiver());    // JSFunction
454 455 456 457 458
  function->InitParameter(
      1, UntaggedSigned32(zone));  // actual number of arguments
  function->InitParameter(
      2,
      UntaggedSigned32(zone));  // expected number of arguments
459 460 461 462 463 464 465
  return function;
}


Type::FunctionType*
ApiFunctionDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
466 467 468 469 470 471 472 473 474
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 5, zone);
  function->InitParameter(0, AnyTagged(zone));        // callee
  function->InitParameter(1, AnyTagged(zone));        // call_data
  function->InitParameter(2, AnyTagged(zone));        // holder
  function->InitParameter(3, ExternalPointer(zone));  // api_function_address
  function->InitParameter(
      4, UntaggedSigned32(zone));  // actual number of arguments
475 476 477 478 479 480 481
  return function;
}


Type::FunctionType*
ApiAccessorDescriptor::BuildCallInterfaceDescriptorFunctionType(
    Isolate* isolate, int paramater_count) {
482 483 484 485 486 487 488
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 4, zone);
  function->InitParameter(0, AnyTagged(zone));        // callee
  function->InitParameter(1, AnyTagged(zone));        // call_data
  function->InitParameter(2, AnyTagged(zone));        // holder
  function->InitParameter(3, ExternalPointer(zone));  // api_function_address
489 490 491 492
  return function;
}


493 494 495
Type::FunctionType* MathRoundVariantCallFromUnoptimizedCodeDescriptor::
    BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
                                             int paramater_count) {
496 497 498
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 4, zone);
499
  function->InitParameter(0, Type::Receiver());
500 501 502
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, AnyTagged(zone));
  function->InitParameter(3, AnyTagged(zone));
503 504 505 506
  return function;
}


507 508 509
Type::FunctionType* MathRoundVariantCallFromOptimizedCodeDescriptor::
    BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
                                             int paramater_count) {
510 511 512
  Zone* zone = isolate->interface_descriptor_zone();
  Type::FunctionType* function =
      Type::FunctionType::New(AnyTagged(zone), Type::Undefined(), 5, zone);
513
  function->InitParameter(0, Type::Receiver());
514 515 516 517
  function->InitParameter(1, SmiType(zone));
  function->InitParameter(2, AnyTagged(zone));
  function->InitParameter(3, AnyTagged(zone));
  function->InitParameter(4, AnyTagged(zone));
518 519
  return function;
}
520 521
}  // namespace internal
}  // namespace v8