17#ifdef V8_ENABLE_DIRECT_HANDLE
22#if !(defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI)
36namespace fast_api_call {
41 return UINT8_ELEMENTS;
43 return INT32_ELEMENTS;
45 return UINT32_ELEMENTS;
47 return BIGINT64_ELEMENTS;
49 return BIGUINT64_ELEMENTS;
51 return FLOAT32_ELEMENTS;
53 return FLOAT64_ELEMENTS;
68#if defined(V8_OS_MACOS) && defined(V8_TARGET_ARCH_ARM64)
75#ifndef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
82#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
83 if (!
v8_flags.fast_api_allow_float_in_sim &&
90#ifndef V8_TARGET_ARCH_64_BIT
100#ifdef V8_TARGET_ARCH_X64
102 uint8_t flags = uint8_t(c_signature->
ArgumentInfo(
i).GetFlags());
108#ifndef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
115#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
116 if (!
v8_flags.fast_api_allow_float_in_sim &&
123#ifndef V8_TARGET_ARCH_64_BIT
174 int inputs_size,
Node** inputs,
177 int c_arg_count,
Node* stack_slot) {
179 Node* target_address =
__ IsolateField(IsolateFieldId::kFastApiCallTarget);
182 target_address, 0,
__ BitcastTaggedToWord(target));
185 if (stack_slot !=
nullptr) {
186 inputs[c_arg_count + 1] = stack_slot;
187 inputs[c_arg_count + 2] =
__ effect();
188 inputs[c_arg_count + 3] =
__ control();
190 inputs[c_arg_count + 1] =
__ effect();
191 inputs[c_arg_count + 2] =
__ control();
195 Node* call =
__ Call(call_descriptor, inputs_size, inputs);
213 Node* isolate_root =
__ LoadRootRegister();
215 auto centry_id = Builtin::kWasmCEntry;
219 const int kInputCount = 6;
220 Node* inputs[kInputCount];
222 inputs[
count++] = centry_stub;
227 inputs[
count++] =
__ control();
234 Node* data_argument) {
239 auto if_success =
__ MakeLabel();
240 auto if_error =
__ MakeDeferredLabel();
244 const int kFastTargetAddressInputIndex = 0;
245 const int kFastTargetAddressInputCount = 1;
247 const int kEffectAndControlInputCount = 2;
249 int extra_input_count =
250 kEffectAndControlInputCount + (c_signature->
HasOptions() ? 1 : 0);
253 kFastTargetAddressInputCount + c_arg_count + extra_input_count);
266 inputs[kFastTargetAddressInputIndex] =
__ ExternalConstant(
269 for (
int i = 0;
i < c_arg_count; ++
i) {
275 graph()->zone(), 1, c_arg_count + (c_signature->
HasOptions() ? 1 : 0));
279 for (
int i = 0;
i < c_arg_count; ++
i) {
283 type.GetSequenceType() == CTypeInfo::SequenceType::kScalar
290 Node* stack_slot =
nullptr;
297 static_assert(kSize ==
sizeof(uintptr_t) * 2);
298 stack_slot =
__ StackSlot(kSize, kAlign);
306 Node* data_argument_to_pass =
__ AdaptLocalArgument(data_argument);
312 data_argument_to_pass);
322 Node* c_call_result =
323 WrapFastCall(call_descriptor, c_arg_count + extra_input_count + 1, inputs,
324 inputs[0], c_signature, c_arg_count, stack_slot);
328 IsolateAddressId::kExceptionAddress,
isolate_)),
335 auto throw_label =
__ MakeDeferredLabel();
336 auto done =
__ MakeLabel();
337 __ GotoIfNot(
__ IntPtrEqual(exception, the_hole), &throw_label);
340 __ Bind(&throw_label);
348 __ Goto(&if_success);
353 if (if_error.IsUsed()) {
358 __ Goto(&merge, slow_call_result);
362 __ Bind(&if_success);
363 __ Goto(&merge, fast_call_result);
366 return merge.PhiAt(0);
379 convert_return_value, initialize_options,
380 generate_slow_api_call);
381 return builder.
Build(c_function, data_argument);
387 if (!
v8_flags.turbo_fast_api_calls)
return {0,
nullptr};
393 const size_t overloads_count = signatures.
size();
396 for (
size_t i = 0;
i < overloads_count;
i++) {
399 bool optimize_to_fast_call =
400 (len == arg_count) &&
403 if (optimize_to_fast_call) {
407#if defined(V8_TARGET_ARCH_32_BIT)
408 for (
unsigned int j = 0; j < c_signature->
ArgumentCount(); ++j) {
409 const uint8_t flags =
410 static_cast<uint8_t
>(c_signature->
ArgumentInfo(j).GetFlags());
const CTypeInfo & ReturnInfo() const
const CTypeInfo & ArgumentInfo(unsigned int index) const
unsigned int ArgumentCount() const
static bool IsSupported(CpuFeature f)
static V8_EXPORT_PRIVATE ExternalReference isolate_address()
static ExternalReference Create(const SCTableReference &table_ref)
static constexpr int root_slot_offset(RootIndex root_index)
static constexpr int BuiltinSlotOffset(Builtin id)
static constexpr MachineType Pointer()
static constexpr MachineType AnyTagged()
static MachineType TypeForCType(const CTypeInfo &type)
static constexpr MachineRepresentation PointerRepresentation()
static constexpr MachineType IntPtr()
static V8_EXPORT_PRIVATE const Function * FunctionForId(FunctionId id)
T * AllocateArray(size_t length)
ZoneVector< const CFunctionInfo * > c_signatures(JSHeapBroker *broker) const
ZoneVector< Address > c_functions(JSHeapBroker *broker) const
static CallDescriptor * GetSimplifiedCDescriptor(Zone *zone, const MachineSignature *sig, CallDescriptor::Flags flags=CallDescriptor::kNoFlags, Operator::Properties properties=Operator::kNoThrow)
static CallDescriptor * GetRuntimeCallDescriptor(Zone *zone, Runtime::FunctionId function, int js_parameter_count, Operator::Properties properties, CallDescriptor::Flags flags, LazyDeoptOnThrow lazy_deopt_on_throw=LazyDeoptOnThrow::kNo)
Node * Build(FastApiCallFunction c_function, Node *data_argument)
Isolate * isolate() const
FastApiCallBuilder(Isolate *isolate, TFGraph *graph, GraphAssembler *graph_assembler, const GetParameter &get_parameter, const ConvertReturnValue &convert_return_value, const InitializeOptions &initialize_options, const GenerateSlowApiCall &generate_slow_api_call)
Node * WrapFastCall(const CallDescriptor *call_descriptor, int inputs_size, Node **inputs, Node *target, const CFunctionInfo *c_signature, int c_arg_count, Node *stack_slot)
const ConvertReturnValue & convert_return_value_
GraphAssembler * graph_assembler_
const GetParameter & get_parameter_
const InitializeOptions & initialize_options_
const GenerateSlowApiCall & generate_slow_api_call_
GraphAssembler * gasm() const
void PropagateException()
std::function< Node *(const CFunctionInfo *, Node *)> ConvertReturnValue
ElementsKind GetTypedArrayElementsKind(CTypeInfo::Type type)
std::function< Node *(int, GraphAssemblerLabel< 0 > *)> GetParameter
std::function< void(Node *)> InitializeOptions
std::function< Node *()> GenerateSlowApiCall
FastApiCallFunction GetFastApiCallTarget(JSHeapBroker *broker, FunctionTemplateInfoRef function_template_info, size_t arg_count)
Node * BuildFastApiCall(Isolate *isolate, TFGraph *graph, GraphAssembler *graph_assembler, FastApiCallFunction c_function, Node *data_argument, const GetParameter &get_parameter, const ConvertReturnValue &convert_return_value, const InitializeOptions &initialize_options, const GenerateSlowApiCall &generate_slow_api_call)
bool CanOptimizeFastSignature(const CFunctionInfo *c_signature)
static const Operator * IntPtrConstant(CommonOperatorBuilder *common, intptr_t value)
V8_EXPORT_PRIVATE FlagValues v8_flags
i::Address Load(i::Address address)
#define DCHECK_NOT_NULL(val)
#define DCHECK_EQ(v1, v2)
#define ASSERT_TRIVIALLY_COPYABLE(T)
const CFunctionInfo * signature
#define END_ALLOW_USE_DEPRECATED()
#define START_ALLOW_USE_DEPRECATED()