11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/builtins/builtins-descriptors.h"
81cb0ef41Sopenharmony_ci#include "src/ic/ic.h"
91cb0ef41Sopenharmony_ci#include "src/init/bootstrapper.h"
101cb0ef41Sopenharmony_ci#include "src/objects/allocation-site-inl.h"
111cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace v8 {
141cb0ef41Sopenharmony_cinamespace internal {
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// static
171cb0ef41Sopenharmony_ciHandle<CodeT> CodeFactory::RuntimeCEntry(Isolate* isolate, int result_size) {
181cb0ef41Sopenharmony_ci  return CodeFactory::CEntry(isolate, result_size);
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci#define CENTRY_CODE(RS, SD, AM, BE) \
221cb0ef41Sopenharmony_ci  BUILTIN_CODE(isolate, CEntry_##RS##_##SD##_##AM##_##BE)
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// static
251cb0ef41Sopenharmony_ciHandle<CodeT> CodeFactory::CEntry(Isolate* isolate, int result_size,
261cb0ef41Sopenharmony_ci                                  SaveFPRegsMode save_doubles,
271cb0ef41Sopenharmony_ci                                  ArgvMode argv_mode, bool builtin_exit_frame) {
281cb0ef41Sopenharmony_ci  // Aliases for readability below.
291cb0ef41Sopenharmony_ci  const int rs = result_size;
301cb0ef41Sopenharmony_ci  const SaveFPRegsMode sd = save_doubles;
311cb0ef41Sopenharmony_ci  const ArgvMode am = argv_mode;
321cb0ef41Sopenharmony_ci  const bool be = builtin_exit_frame;
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  if (rs == 1 && sd == SaveFPRegsMode::kIgnore && am == ArgvMode::kStack &&
351cb0ef41Sopenharmony_ci      !be) {
361cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return1, DontSaveFPRegs, ArgvOnStack, NoBuiltinExit);
371cb0ef41Sopenharmony_ci  } else if (rs == 1 && sd == SaveFPRegsMode::kIgnore &&
381cb0ef41Sopenharmony_ci             am == ArgvMode::kStack && be) {
391cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return1, DontSaveFPRegs, ArgvOnStack, BuiltinExit);
401cb0ef41Sopenharmony_ci  } else if (rs == 1 && sd == SaveFPRegsMode::kIgnore &&
411cb0ef41Sopenharmony_ci             am == ArgvMode::kRegister && !be) {
421cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return1, DontSaveFPRegs, ArgvInRegister, NoBuiltinExit);
431cb0ef41Sopenharmony_ci  } else if (rs == 1 && sd == SaveFPRegsMode::kSave && am == ArgvMode::kStack &&
441cb0ef41Sopenharmony_ci             !be) {
451cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return1, SaveFPRegs, ArgvOnStack, NoBuiltinExit);
461cb0ef41Sopenharmony_ci  } else if (rs == 1 && sd == SaveFPRegsMode::kSave && am == ArgvMode::kStack &&
471cb0ef41Sopenharmony_ci             be) {
481cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return1, SaveFPRegs, ArgvOnStack, BuiltinExit);
491cb0ef41Sopenharmony_ci  } else if (rs == 2 && sd == SaveFPRegsMode::kIgnore &&
501cb0ef41Sopenharmony_ci             am == ArgvMode::kStack && !be) {
511cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return2, DontSaveFPRegs, ArgvOnStack, NoBuiltinExit);
521cb0ef41Sopenharmony_ci  } else if (rs == 2 && sd == SaveFPRegsMode::kIgnore &&
531cb0ef41Sopenharmony_ci             am == ArgvMode::kStack && be) {
541cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return2, DontSaveFPRegs, ArgvOnStack, BuiltinExit);
551cb0ef41Sopenharmony_ci  } else if (rs == 2 && sd == SaveFPRegsMode::kIgnore &&
561cb0ef41Sopenharmony_ci             am == ArgvMode::kRegister && !be) {
571cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return2, DontSaveFPRegs, ArgvInRegister, NoBuiltinExit);
581cb0ef41Sopenharmony_ci  } else if (rs == 2 && sd == SaveFPRegsMode::kSave && am == ArgvMode::kStack &&
591cb0ef41Sopenharmony_ci             !be) {
601cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return2, SaveFPRegs, ArgvOnStack, NoBuiltinExit);
611cb0ef41Sopenharmony_ci  } else if (rs == 2 && sd == SaveFPRegsMode::kSave && am == ArgvMode::kStack &&
621cb0ef41Sopenharmony_ci             be) {
631cb0ef41Sopenharmony_ci    return CENTRY_CODE(Return2, SaveFPRegs, ArgvOnStack, BuiltinExit);
641cb0ef41Sopenharmony_ci  }
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  UNREACHABLE();
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci#undef CENTRY_CODE
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci// static
721cb0ef41Sopenharmony_ciCallable CodeFactory::ApiGetter(Isolate* isolate) {
731cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallApiGetter);
741cb0ef41Sopenharmony_ci}
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci// static
771cb0ef41Sopenharmony_ciCallable CodeFactory::CallApiCallback(Isolate* isolate) {
781cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallApiCallback);
791cb0ef41Sopenharmony_ci}
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci// static
821cb0ef41Sopenharmony_ciCallable CodeFactory::LoadGlobalIC(Isolate* isolate, TypeofMode typeof_mode) {
831cb0ef41Sopenharmony_ci  return typeof_mode == TypeofMode::kNotInside
841cb0ef41Sopenharmony_ci             ? Builtins::CallableFor(isolate, Builtin::kLoadGlobalICTrampoline)
851cb0ef41Sopenharmony_ci             : Builtins::CallableFor(
861cb0ef41Sopenharmony_ci                   isolate, Builtin::kLoadGlobalICInsideTypeofTrampoline);
871cb0ef41Sopenharmony_ci}
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci// static
901cb0ef41Sopenharmony_ciCallable CodeFactory::LoadGlobalICInOptimizedCode(Isolate* isolate,
911cb0ef41Sopenharmony_ci                                                  TypeofMode typeof_mode) {
921cb0ef41Sopenharmony_ci  return typeof_mode == TypeofMode::kNotInside
931cb0ef41Sopenharmony_ci             ? Builtins::CallableFor(isolate, Builtin::kLoadGlobalIC)
941cb0ef41Sopenharmony_ci             : Builtins::CallableFor(isolate,
951cb0ef41Sopenharmony_ci                                     Builtin::kLoadGlobalICInsideTypeof);
961cb0ef41Sopenharmony_ci}
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ciCallable CodeFactory::DefineNamedOwnIC(Isolate* isolate) {
991cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kDefineNamedOwnICTrampoline);
1001cb0ef41Sopenharmony_ci}
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ciCallable CodeFactory::DefineNamedOwnICInOptimizedCode(Isolate* isolate) {
1031cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kDefineNamedOwnIC);
1041cb0ef41Sopenharmony_ci}
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci// static
1071cb0ef41Sopenharmony_ciCallable CodeFactory::NonPrimitiveToPrimitive(Isolate* isolate,
1081cb0ef41Sopenharmony_ci                                              ToPrimitiveHint hint) {
1091cb0ef41Sopenharmony_ci  return Callable(isolate->builtins()->NonPrimitiveToPrimitive(hint),
1101cb0ef41Sopenharmony_ci                  TypeConversionDescriptor{});
1111cb0ef41Sopenharmony_ci}
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ci// static
1141cb0ef41Sopenharmony_ciCallable CodeFactory::OrdinaryToPrimitive(Isolate* isolate,
1151cb0ef41Sopenharmony_ci                                          OrdinaryToPrimitiveHint hint) {
1161cb0ef41Sopenharmony_ci  return Callable(isolate->builtins()->OrdinaryToPrimitive(hint),
1171cb0ef41Sopenharmony_ci                  TypeConversionDescriptor{});
1181cb0ef41Sopenharmony_ci}
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci// static
1211cb0ef41Sopenharmony_ciCallable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags) {
1221cb0ef41Sopenharmony_ci  switch (flags) {
1231cb0ef41Sopenharmony_ci    case STRING_ADD_CHECK_NONE:
1241cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate, Builtin::kStringAdd_CheckNone);
1251cb0ef41Sopenharmony_ci    case STRING_ADD_CONVERT_LEFT:
1261cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate, Builtin::kStringAddConvertLeft);
1271cb0ef41Sopenharmony_ci    case STRING_ADD_CONVERT_RIGHT:
1281cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate, Builtin::kStringAddConvertRight);
1291cb0ef41Sopenharmony_ci  }
1301cb0ef41Sopenharmony_ci  UNREACHABLE();
1311cb0ef41Sopenharmony_ci}
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci// static
1341cb0ef41Sopenharmony_ciCallable CodeFactory::ResumeGenerator(Isolate* isolate) {
1351cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kResumeGeneratorTrampoline);
1361cb0ef41Sopenharmony_ci}
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci// static
1391cb0ef41Sopenharmony_ciCallable CodeFactory::FastNewFunctionContext(Isolate* isolate,
1401cb0ef41Sopenharmony_ci                                             ScopeType scope_type) {
1411cb0ef41Sopenharmony_ci  switch (scope_type) {
1421cb0ef41Sopenharmony_ci    case ScopeType::EVAL_SCOPE:
1431cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate,
1441cb0ef41Sopenharmony_ci                                   Builtin::kFastNewFunctionContextEval);
1451cb0ef41Sopenharmony_ci    case ScopeType::FUNCTION_SCOPE:
1461cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate,
1471cb0ef41Sopenharmony_ci                                   Builtin::kFastNewFunctionContextFunction);
1481cb0ef41Sopenharmony_ci    default:
1491cb0ef41Sopenharmony_ci      UNREACHABLE();
1501cb0ef41Sopenharmony_ci  }
1511cb0ef41Sopenharmony_ci}
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci// static
1541cb0ef41Sopenharmony_ciCallable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode) {
1551cb0ef41Sopenharmony_ci  return Callable(isolate->builtins()->Call(mode), CallTrampolineDescriptor{});
1561cb0ef41Sopenharmony_ci}
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci// static
1591cb0ef41Sopenharmony_ciCallable CodeFactory::Call_WithFeedback(Isolate* isolate,
1601cb0ef41Sopenharmony_ci                                        ConvertReceiverMode mode) {
1611cb0ef41Sopenharmony_ci  switch (mode) {
1621cb0ef41Sopenharmony_ci    case ConvertReceiverMode::kNullOrUndefined:
1631cb0ef41Sopenharmony_ci      return Builtins::CallableFor(
1641cb0ef41Sopenharmony_ci          isolate, Builtin::kCall_ReceiverIsNullOrUndefined_WithFeedback);
1651cb0ef41Sopenharmony_ci    case ConvertReceiverMode::kNotNullOrUndefined:
1661cb0ef41Sopenharmony_ci      return Builtins::CallableFor(
1671cb0ef41Sopenharmony_ci          isolate, Builtin::kCall_ReceiverIsNotNullOrUndefined_WithFeedback);
1681cb0ef41Sopenharmony_ci    case ConvertReceiverMode::kAny:
1691cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate,
1701cb0ef41Sopenharmony_ci                                   Builtin::kCall_ReceiverIsAny_WithFeedback);
1711cb0ef41Sopenharmony_ci  }
1721cb0ef41Sopenharmony_ci  UNREACHABLE();
1731cb0ef41Sopenharmony_ci}
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_ci// static
1761cb0ef41Sopenharmony_ciCallable CodeFactory::CallWithArrayLike(Isolate* isolate) {
1771cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallWithArrayLike);
1781cb0ef41Sopenharmony_ci}
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci// static
1811cb0ef41Sopenharmony_ciCallable CodeFactory::CallWithSpread(Isolate* isolate) {
1821cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallWithSpread);
1831cb0ef41Sopenharmony_ci}
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_ci// static
1861cb0ef41Sopenharmony_ciCallable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
1871cb0ef41Sopenharmony_ci  return Callable(isolate->builtins()->CallFunction(mode),
1881cb0ef41Sopenharmony_ci                  CallTrampolineDescriptor{});
1891cb0ef41Sopenharmony_ci}
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci// static
1921cb0ef41Sopenharmony_ciCallable CodeFactory::CallVarargs(Isolate* isolate) {
1931cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallVarargs);
1941cb0ef41Sopenharmony_ci}
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci// static
1971cb0ef41Sopenharmony_ciCallable CodeFactory::CallForwardVarargs(Isolate* isolate) {
1981cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallForwardVarargs);
1991cb0ef41Sopenharmony_ci}
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_ci// static
2021cb0ef41Sopenharmony_ciCallable CodeFactory::CallFunctionForwardVarargs(Isolate* isolate) {
2031cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kCallFunctionForwardVarargs);
2041cb0ef41Sopenharmony_ci}
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ci// static
2071cb0ef41Sopenharmony_ciCallable CodeFactory::Construct(Isolate* isolate) {
2081cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kConstruct);
2091cb0ef41Sopenharmony_ci}
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci// static
2121cb0ef41Sopenharmony_ciCallable CodeFactory::ConstructWithSpread(Isolate* isolate) {
2131cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kConstructWithSpread);
2141cb0ef41Sopenharmony_ci}
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci// static
2171cb0ef41Sopenharmony_ciCallable CodeFactory::ConstructFunction(Isolate* isolate) {
2181cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kConstructFunction);
2191cb0ef41Sopenharmony_ci}
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ci// static
2221cb0ef41Sopenharmony_ciCallable CodeFactory::ConstructVarargs(Isolate* isolate) {
2231cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kConstructVarargs);
2241cb0ef41Sopenharmony_ci}
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci// static
2271cb0ef41Sopenharmony_ciCallable CodeFactory::ConstructForwardVarargs(Isolate* isolate) {
2281cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate, Builtin::kConstructForwardVarargs);
2291cb0ef41Sopenharmony_ci}
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci// static
2321cb0ef41Sopenharmony_ciCallable CodeFactory::ConstructFunctionForwardVarargs(Isolate* isolate) {
2331cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate,
2341cb0ef41Sopenharmony_ci                               Builtin::kConstructFunctionForwardVarargs);
2351cb0ef41Sopenharmony_ci}
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci// static
2381cb0ef41Sopenharmony_ciCallable CodeFactory::InterpreterPushArgsThenCall(
2391cb0ef41Sopenharmony_ci    Isolate* isolate, ConvertReceiverMode receiver_mode,
2401cb0ef41Sopenharmony_ci    InterpreterPushArgsMode mode) {
2411cb0ef41Sopenharmony_ci  switch (mode) {
2421cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kArrayFunction:
2431cb0ef41Sopenharmony_ci      // There is no special-case handling of calls to Array. They will all go
2441cb0ef41Sopenharmony_ci      // through the kOther case below.
2451cb0ef41Sopenharmony_ci      UNREACHABLE();
2461cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kWithFinalSpread:
2471cb0ef41Sopenharmony_ci      return Builtins::CallableFor(
2481cb0ef41Sopenharmony_ci          isolate, Builtin::kInterpreterPushArgsThenCallWithFinalSpread);
2491cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kOther:
2501cb0ef41Sopenharmony_ci      switch (receiver_mode) {
2511cb0ef41Sopenharmony_ci        case ConvertReceiverMode::kNullOrUndefined:
2521cb0ef41Sopenharmony_ci          return Builtins::CallableFor(
2531cb0ef41Sopenharmony_ci              isolate, Builtin::kInterpreterPushUndefinedAndArgsThenCall);
2541cb0ef41Sopenharmony_ci        case ConvertReceiverMode::kNotNullOrUndefined:
2551cb0ef41Sopenharmony_ci        case ConvertReceiverMode::kAny:
2561cb0ef41Sopenharmony_ci          return Builtins::CallableFor(isolate,
2571cb0ef41Sopenharmony_ci                                       Builtin::kInterpreterPushArgsThenCall);
2581cb0ef41Sopenharmony_ci      }
2591cb0ef41Sopenharmony_ci  }
2601cb0ef41Sopenharmony_ci  UNREACHABLE();
2611cb0ef41Sopenharmony_ci}
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_ci// static
2641cb0ef41Sopenharmony_ciCallable CodeFactory::InterpreterPushArgsThenConstruct(
2651cb0ef41Sopenharmony_ci    Isolate* isolate, InterpreterPushArgsMode mode) {
2661cb0ef41Sopenharmony_ci  switch (mode) {
2671cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kArrayFunction:
2681cb0ef41Sopenharmony_ci      return Builtins::CallableFor(
2691cb0ef41Sopenharmony_ci          isolate, Builtin::kInterpreterPushArgsThenConstructArrayFunction);
2701cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kWithFinalSpread:
2711cb0ef41Sopenharmony_ci      return Builtins::CallableFor(
2721cb0ef41Sopenharmony_ci          isolate, Builtin::kInterpreterPushArgsThenConstructWithFinalSpread);
2731cb0ef41Sopenharmony_ci    case InterpreterPushArgsMode::kOther:
2741cb0ef41Sopenharmony_ci      return Builtins::CallableFor(isolate,
2751cb0ef41Sopenharmony_ci                                   Builtin::kInterpreterPushArgsThenConstruct);
2761cb0ef41Sopenharmony_ci  }
2771cb0ef41Sopenharmony_ci  UNREACHABLE();
2781cb0ef41Sopenharmony_ci}
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci// static
2811cb0ef41Sopenharmony_ciCallable CodeFactory::InterpreterCEntry(Isolate* isolate, int result_size) {
2821cb0ef41Sopenharmony_ci  // Note: If we ever use fpregs in the interpreter then we will need to
2831cb0ef41Sopenharmony_ci  // save fpregs too.
2841cb0ef41Sopenharmony_ci  Handle<CodeT> code = CodeFactory::CEntry(
2851cb0ef41Sopenharmony_ci      isolate, result_size, SaveFPRegsMode::kIgnore, ArgvMode::kRegister);
2861cb0ef41Sopenharmony_ci  if (result_size == 1) {
2871cb0ef41Sopenharmony_ci    return Callable(code, InterpreterCEntry1Descriptor{});
2881cb0ef41Sopenharmony_ci  } else {
2891cb0ef41Sopenharmony_ci    DCHECK_EQ(result_size, 2);
2901cb0ef41Sopenharmony_ci    return Callable(code, InterpreterCEntry2Descriptor{});
2911cb0ef41Sopenharmony_ci  }
2921cb0ef41Sopenharmony_ci}
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci// static
2951cb0ef41Sopenharmony_ciCallable CodeFactory::InterpreterOnStackReplacement(Isolate* isolate) {
2961cb0ef41Sopenharmony_ci  return Builtins::CallableFor(isolate,
2971cb0ef41Sopenharmony_ci                               Builtin::kInterpreterOnStackReplacement);
2981cb0ef41Sopenharmony_ci}
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci// static
3011cb0ef41Sopenharmony_ciCallable CodeFactory::InterpreterOnStackReplacement_ToBaseline(
3021cb0ef41Sopenharmony_ci    Isolate* isolate) {
3031cb0ef41Sopenharmony_ci  return Builtins::CallableFor(
3041cb0ef41Sopenharmony_ci      isolate, Builtin::kInterpreterOnStackReplacement_ToBaseline);
3051cb0ef41Sopenharmony_ci}
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci// static
3081cb0ef41Sopenharmony_ciCallable CodeFactory::ArrayNoArgumentConstructor(
3091cb0ef41Sopenharmony_ci    Isolate* isolate, ElementsKind kind,
3101cb0ef41Sopenharmony_ci    AllocationSiteOverrideMode override_mode) {
3111cb0ef41Sopenharmony_ci#define CASE(kind_caps, kind_camel, mode_camel) \
3121cb0ef41Sopenharmony_ci  case kind_caps:                               \
3131cb0ef41Sopenharmony_ci    return Builtins::CallableFor(               \
3141cb0ef41Sopenharmony_ci        isolate,                                \
3151cb0ef41Sopenharmony_ci        Builtin::kArrayNoArgumentConstructor_##kind_camel##_##mode_camel);
3161cb0ef41Sopenharmony_ci  if (override_mode == DONT_OVERRIDE && AllocationSite::ShouldTrack(kind)) {
3171cb0ef41Sopenharmony_ci    DCHECK(IsSmiElementsKind(kind));
3181cb0ef41Sopenharmony_ci    switch (kind) {
3191cb0ef41Sopenharmony_ci      CASE(PACKED_SMI_ELEMENTS, PackedSmi, DontOverride);
3201cb0ef41Sopenharmony_ci      CASE(HOLEY_SMI_ELEMENTS, HoleySmi, DontOverride);
3211cb0ef41Sopenharmony_ci      default:
3221cb0ef41Sopenharmony_ci        UNREACHABLE();
3231cb0ef41Sopenharmony_ci    }
3241cb0ef41Sopenharmony_ci  } else {
3251cb0ef41Sopenharmony_ci    DCHECK(override_mode == DISABLE_ALLOCATION_SITES ||
3261cb0ef41Sopenharmony_ci           !AllocationSite::ShouldTrack(kind));
3271cb0ef41Sopenharmony_ci    switch (kind) {
3281cb0ef41Sopenharmony_ci      CASE(PACKED_SMI_ELEMENTS, PackedSmi, DisableAllocationSites);
3291cb0ef41Sopenharmony_ci      CASE(HOLEY_SMI_ELEMENTS, HoleySmi, DisableAllocationSites);
3301cb0ef41Sopenharmony_ci      CASE(PACKED_ELEMENTS, Packed, DisableAllocationSites);
3311cb0ef41Sopenharmony_ci      CASE(HOLEY_ELEMENTS, Holey, DisableAllocationSites);
3321cb0ef41Sopenharmony_ci      CASE(PACKED_DOUBLE_ELEMENTS, PackedDouble, DisableAllocationSites);
3331cb0ef41Sopenharmony_ci      CASE(HOLEY_DOUBLE_ELEMENTS, HoleyDouble, DisableAllocationSites);
3341cb0ef41Sopenharmony_ci      default:
3351cb0ef41Sopenharmony_ci        UNREACHABLE();
3361cb0ef41Sopenharmony_ci    }
3371cb0ef41Sopenharmony_ci  }
3381cb0ef41Sopenharmony_ci#undef CASE
3391cb0ef41Sopenharmony_ci}
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci// static
3421cb0ef41Sopenharmony_ciCallable CodeFactory::ArraySingleArgumentConstructor(
3431cb0ef41Sopenharmony_ci    Isolate* isolate, ElementsKind kind,
3441cb0ef41Sopenharmony_ci    AllocationSiteOverrideMode override_mode) {
3451cb0ef41Sopenharmony_ci#define CASE(kind_caps, kind_camel, mode_camel) \
3461cb0ef41Sopenharmony_ci  case kind_caps:                               \
3471cb0ef41Sopenharmony_ci    return Builtins::CallableFor(               \
3481cb0ef41Sopenharmony_ci        isolate,                                \
3491cb0ef41Sopenharmony_ci        Builtin::kArraySingleArgumentConstructor_##kind_camel##_##mode_camel)
3501cb0ef41Sopenharmony_ci  if (override_mode == DONT_OVERRIDE && AllocationSite::ShouldTrack(kind)) {
3511cb0ef41Sopenharmony_ci    DCHECK(IsSmiElementsKind(kind));
3521cb0ef41Sopenharmony_ci    switch (kind) {
3531cb0ef41Sopenharmony_ci      CASE(PACKED_SMI_ELEMENTS, PackedSmi, DontOverride);
3541cb0ef41Sopenharmony_ci      CASE(HOLEY_SMI_ELEMENTS, HoleySmi, DontOverride);
3551cb0ef41Sopenharmony_ci      default:
3561cb0ef41Sopenharmony_ci        UNREACHABLE();
3571cb0ef41Sopenharmony_ci    }
3581cb0ef41Sopenharmony_ci  } else {
3591cb0ef41Sopenharmony_ci    DCHECK(override_mode == DISABLE_ALLOCATION_SITES ||
3601cb0ef41Sopenharmony_ci           !AllocationSite::ShouldTrack(kind));
3611cb0ef41Sopenharmony_ci    switch (kind) {
3621cb0ef41Sopenharmony_ci      CASE(PACKED_SMI_ELEMENTS, PackedSmi, DisableAllocationSites);
3631cb0ef41Sopenharmony_ci      CASE(HOLEY_SMI_ELEMENTS, HoleySmi, DisableAllocationSites);
3641cb0ef41Sopenharmony_ci      CASE(PACKED_ELEMENTS, Packed, DisableAllocationSites);
3651cb0ef41Sopenharmony_ci      CASE(HOLEY_ELEMENTS, Holey, DisableAllocationSites);
3661cb0ef41Sopenharmony_ci      CASE(PACKED_DOUBLE_ELEMENTS, PackedDouble, DisableAllocationSites);
3671cb0ef41Sopenharmony_ci      CASE(HOLEY_DOUBLE_ELEMENTS, HoleyDouble, DisableAllocationSites);
3681cb0ef41Sopenharmony_ci      default:
3691cb0ef41Sopenharmony_ci        UNREACHABLE();
3701cb0ef41Sopenharmony_ci    }
3711cb0ef41Sopenharmony_ci  }
3721cb0ef41Sopenharmony_ci#undef CASE
3731cb0ef41Sopenharmony_ci}
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_ci#ifdef V8_IS_TSAN
3761cb0ef41Sopenharmony_ci// static
3771cb0ef41Sopenharmony_ciBuiltin CodeFactory::GetTSANStoreStub(SaveFPRegsMode fp_mode, int size,
3781cb0ef41Sopenharmony_ci                                      std::memory_order order) {
3791cb0ef41Sopenharmony_ci  if (order == std::memory_order_relaxed) {
3801cb0ef41Sopenharmony_ci    if (size == kInt8Size) {
3811cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
3821cb0ef41Sopenharmony_ci                 ? Builtin::kTSANRelaxedStore8IgnoreFP
3831cb0ef41Sopenharmony_ci                 : Builtin::kTSANRelaxedStore8SaveFP;
3841cb0ef41Sopenharmony_ci    } else if (size == kInt16Size) {
3851cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
3861cb0ef41Sopenharmony_ci                 ? Builtin::kTSANRelaxedStore16IgnoreFP
3871cb0ef41Sopenharmony_ci                 : Builtin::kTSANRelaxedStore16SaveFP;
3881cb0ef41Sopenharmony_ci    } else if (size == kInt32Size) {
3891cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
3901cb0ef41Sopenharmony_ci                 ? Builtin::kTSANRelaxedStore32IgnoreFP
3911cb0ef41Sopenharmony_ci                 : Builtin::kTSANRelaxedStore32SaveFP;
3921cb0ef41Sopenharmony_ci    } else {
3931cb0ef41Sopenharmony_ci      CHECK_EQ(size, kInt64Size);
3941cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
3951cb0ef41Sopenharmony_ci                 ? Builtin::kTSANRelaxedStore64IgnoreFP
3961cb0ef41Sopenharmony_ci                 : Builtin::kTSANRelaxedStore64SaveFP;
3971cb0ef41Sopenharmony_ci    }
3981cb0ef41Sopenharmony_ci  } else {
3991cb0ef41Sopenharmony_ci    DCHECK_EQ(order, std::memory_order_seq_cst);
4001cb0ef41Sopenharmony_ci    if (size == kInt8Size) {
4011cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
4021cb0ef41Sopenharmony_ci                 ? Builtin::kTSANSeqCstStore8IgnoreFP
4031cb0ef41Sopenharmony_ci                 : Builtin::kTSANSeqCstStore8SaveFP;
4041cb0ef41Sopenharmony_ci    } else if (size == kInt16Size) {
4051cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
4061cb0ef41Sopenharmony_ci                 ? Builtin::kTSANSeqCstStore16IgnoreFP
4071cb0ef41Sopenharmony_ci                 : Builtin::kTSANSeqCstStore16SaveFP;
4081cb0ef41Sopenharmony_ci    } else if (size == kInt32Size) {
4091cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
4101cb0ef41Sopenharmony_ci                 ? Builtin::kTSANSeqCstStore32IgnoreFP
4111cb0ef41Sopenharmony_ci                 : Builtin::kTSANSeqCstStore32SaveFP;
4121cb0ef41Sopenharmony_ci    } else {
4131cb0ef41Sopenharmony_ci      CHECK_EQ(size, kInt64Size);
4141cb0ef41Sopenharmony_ci      return fp_mode == SaveFPRegsMode::kIgnore
4151cb0ef41Sopenharmony_ci                 ? Builtin::kTSANSeqCstStore64IgnoreFP
4161cb0ef41Sopenharmony_ci                 : Builtin::kTSANSeqCstStore64SaveFP;
4171cb0ef41Sopenharmony_ci    }
4181cb0ef41Sopenharmony_ci  }
4191cb0ef41Sopenharmony_ci}
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ci// static
4221cb0ef41Sopenharmony_ciBuiltin CodeFactory::GetTSANRelaxedLoadStub(SaveFPRegsMode fp_mode, int size) {
4231cb0ef41Sopenharmony_ci  if (size == kInt32Size) {
4241cb0ef41Sopenharmony_ci    return fp_mode == SaveFPRegsMode::kIgnore
4251cb0ef41Sopenharmony_ci               ? Builtin::kTSANRelaxedLoad32IgnoreFP
4261cb0ef41Sopenharmony_ci               : Builtin::kTSANRelaxedLoad32SaveFP;
4271cb0ef41Sopenharmony_ci  } else {
4281cb0ef41Sopenharmony_ci    CHECK_EQ(size, kInt64Size);
4291cb0ef41Sopenharmony_ci    return fp_mode == SaveFPRegsMode::kIgnore
4301cb0ef41Sopenharmony_ci               ? Builtin::kTSANRelaxedLoad64IgnoreFP
4311cb0ef41Sopenharmony_ci               : Builtin::kTSANRelaxedLoad64SaveFP;
4321cb0ef41Sopenharmony_ci  }
4331cb0ef41Sopenharmony_ci}
4341cb0ef41Sopenharmony_ci#endif  // V8_IS_TSAN
4351cb0ef41Sopenharmony_ci
4361cb0ef41Sopenharmony_ci}  // namespace internal
4371cb0ef41Sopenharmony_ci}  // namespace v8
438