5#ifndef V8_COMPILER_TURBOSHAFT_FAST_API_CALL_LOWERING_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_FAST_API_CALL_LOWERING_REDUCER_H_
22template <
typename Next>
29 base::Vector<const
OpIndex> arguments,
32 __ data() -> set_graph_has_lowered_fast_api_calls();
35 const auto& c_signature = parameters->c_signature();
36 const int c_arg_count = c_signature->ArgumentCount();
42 c_signature->ReturnInfo(), c_signature->GetInt64Representation()));
48 for (
int i = 0;
i < c_arg_count; ++
i) {
56 if (
V8_LIKELY(!
__ generating_unreachable_operations())) {
59 c_arg_count + (c_signature->HasOptions() ? 1 : 0));
63 for (
int i = 0;
i < c_arg_count; ++
i) {
67 type.GetSequenceType() == CTypeInfo::SequenceType::kScalar
75 if (c_signature->HasOptions()) {
81 static_assert(kSize ==
sizeof(uintptr_t) * 2);
82 stack_slot =
__ StackSlot(kSize, kAlign);
91 OpIndex data_argument_to_pass =
__ AdaptLocalArgument(data_argument);
92 __ StoreOffHeap(stack_slot, data_argument_to_pass,
96 args.push_back(stack_slot);
108 Label<> trigger_exception(
this);
112 IsolateAddressId::kExceptionAddress,
isolate_)),
120 __ SetVariable(
result, fast_call_result);
123 BIND(trigger_exception);
132 if (
BIND(handle_error)) {
144 template <
typename T>
149 return __ template Projection<0>(
result);
156 case CTypeInfo::SequenceType::kScalar: {
157 uint8_t flags =
static_cast<uint8_t
>(arg_type.
GetFlags());
161 auto result =
__ TryTruncateFloat64ToInt32(argument);
165 auto result =
__ TryTruncateFloat64ToUint32(argument);
169 auto result =
__ TryTruncateFloat64ToInt64(argument);
173 auto result =
__ TryTruncateFloat64ToUint64(argument);
186 return __ AdaptLocalArgument(argument);
189 return __ TruncateFloat64ToFloat32(argument);
193 GOTO_IF(
__ ObjectIsSmi(argument), handle_error);
198 argument,
__ HeapConstant(
factory_->null_value()))),
203 __ TaggedEqual(
__ LoadMapField(argument),
207 GOTO(done,
__ template LoadField<WordPtr>(
216 GOTO_IF(
__ ObjectIsSmi(argument), handle_error);
219 V<Map> map =
__ LoadMapField(argument_obj);
220 V<Word32> instance_type =
__ LoadInstanceTypeField(map);
227 V<WordPtr> length_in_bytes =
__ template LoadField<WordPtr>(
234 static_assert(kSize ==
sizeof(uintptr_t) +
sizeof(
size_t),
236 "FastOneByteString isn't equal to the sum of its "
237 "expected members.");
238 OpIndex stack_slot =
__ StackSlot(kSize, kAlign);
239 __ StoreOffHeap(stack_slot, data_ptr,
241 __ StoreOffHeap(stack_slot, length_in_bytes,
243 static_assert(
sizeof(uintptr_t) ==
sizeof(
size_t),
244 "The string length can't "
245 "fit the PointerRepresentation used to store it.");
254 case CTypeInfo::SequenceType::kIsSequence: {
258 GOTO_IF(
__ ObjectIsSmi(argument), handle_error);
261 V<Map> map =
__ LoadMapField(argument);
262 V<Word32> instance_type =
__ LoadInstanceTypeField(map);
263 GOTO_IF_NOT(
__ Word32Equal(instance_type, JS_ARRAY_TYPE), handle_error);
265 return __ AdaptLocalArgument(argument);
277 switch (scalar_type) {
279 min = std::numeric_limits<int32_t>::min();
280 max = std::numeric_limits<int32_t>::max();
284 max = std::numeric_limits<uint32_t>::max();
301 argument,
__ Float64Constant(max)),
302 __ Float64Constant(min));
306 GOTO_IF(
__ Float64IsNaN(rounded), done, 0.0);
309 BIND(done, rounded_result);
310 switch (scalar_type) {
312 return __ ReversibleFloat64ToInt32(rounded_result);
314 return __ ReversibleFloat64ToUint32(rounded_result);
316 return __ ReversibleFloat64ToInt64(rounded_result);
318 return __ ReversibleFloat64ToUint64(rounded_result);
325 switch (c_signature->
ReturnInfo().GetType()) {
327 return __ HeapConstant(
factory_->undefined_value());
331 return __ Word32Constant(0);
337 return __ Word64Constant(int64_t{0});
340 return __ Float64Constant(0);
343 return __ Float32Constant(0);
345 return __ Float64Constant(0);
347 return __ HeapConstant(
factory_->undefined_value());
358 switch (c_signature->
ReturnInfo().GetType()) {
360 return __ HeapConstant(
factory_->undefined_value());
362 static_assert(
sizeof(
bool) == 1,
"unsupported bool size");
363 return __ Word32BitwiseAnd(
result,
__ Word32Constant(0xFF));
376 return __ ChangeInt64ToFloat64(
result);
385 return __ ChangeUint64ToFloat64(
result);
403 GOTO_IF(
__ WordPtrEqual(pointer, 0), done,
411 __ HeapConstant(
factory_->empty_fixed_array());
417#ifdef V8_ENABLE_SANDBOX
424 OpIndex allocate_and_initialize_young_external_pointer_table_entry =
427 allocate_and_initialize_young_external_pointer_table_entry());
428 auto call_descriptor =
431 allocate_and_initialize_young_external_pointer_table_entry,
432 {isolate_ptr, pointer},
436 external, AccessBuilder::ForJSExternalObjectPointerHandle(),
handle);
441 GOTO(done,
__ FinishInitialization(std::move(external)));
452 __ IsolateField(IsolateFieldId::kFastApiCallTarget);
453 __ StoreOffHeap(target_address,
__ BitcastHeapObjectToWordPtr(callee),
456 OpIndex context_address =
__ ExternalConstant(
459 __ StoreOffHeap(context_address,
__ BitcastHeapObjectToWordPtr(context),
472 __ StoreOffHeap(context_address,
#define REDUCE(operation)
#define GOTO_IF_NOT(cond, label,...)
#define GOTO_IF(cond, label,...)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Int64Representation GetInt64Representation() const
const CTypeInfo & ReturnInfo() const
constexpr Type GetType() const
constexpr Flags GetFlags() const
constexpr SequenceType GetSequenceType() const
static const int kInvalidContext
static V8_EXPORT_PRIVATE ExternalReference isolate_address()
static ExternalReference Create(const SCTableReference &table_ref)
v8::internal::Factory * factory()
static constexpr MachineType Pointer()
static constexpr MachineType AnyTagged()
static constexpr MachineType Uint32()
static MachineType TypeForCType(const CTypeInfo &type)
static FieldAccess ForMap(WriteBarrierKind write_barrier=kMapWriteBarrier)
static FieldAccess ForJSExternalObjectValue()
static ElementAccess ForSeqOneByteStringCharacter()
static FieldAccess ForStringLength()
static FieldAccess ForJSObjectPropertiesOrHash()
static FieldAccess ForJSObjectElements()
static CallDescriptor * GetSimplifiedCDescriptor(Zone *zone, const MachineSignature *sig, CallDescriptor::Flags flags=CallDescriptor::kNoFlags, Operator::Properties properties=Operator::kNoThrow)
V< HeapObject > BuildAllocateJSExternalObject(V< WordPtr > pointer)
V< T > Checked(V< Tuple< T, Word32 > > result, Label<> &otherwise)
OpIndex AdaptFastCallArgument(OpIndex argument, CTypeInfo arg_type, Label<> &handle_error)
V< Any > DefaultReturnValue(const CFunctionInfo *c_signature)
OpIndex WrapFastCall(const TSCallDescriptor *descriptor, OpIndex callee, V< FrameState > frame_state, V< Context > context, base::Vector< const OpIndex > arguments)
OpIndex REDUCE FastApiCall(V< FrameState > frame_state, V< Object > data_argument, V< Context > context, base::Vector< const OpIndex > arguments, const FastApiCallParameters *parameters, base::Vector< const RegisterRepresentation > out_reps)
V< Any > ConvertReturnValue(const CFunctionInfo *c_signature, OpIndex result)
OpIndex ClampFastCallArgument(V< Float64 > argument, CTypeInfo::Type scalar_type)
static constexpr MemoryRepresentation Uint32()
static constexpr MemoryRepresentation UintPtr()
static constexpr RegisterRepresentation FromCTypeInfo(CTypeInfo t, CFunctionInfo::Int64Representation int64_repr)
static V< T > Cast(V< U > index)
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
constexpr Vector< T > VectorOf(T *start, size_t size)
template const Signature< wasm::ValueType > bool
static const Operator * IntPtrConstant(CommonOperatorBuilder *common, intptr_t value)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
constexpr double kMaxSafeInteger
constexpr uint32_t kStringRepresentationAndEncodingMask
constexpr uint32_t kSeqOneByteStringTag
constexpr double kMinSafeInteger
i::Address Load(i::Address address)
#define CHECK_EQ(lhs, rhs)
#define DCHECK_EQ(v1, v2)
static constexpr uint32_t kSuccessValue
static constexpr uint32_t kFailureValue
static constexpr Kind RawAligned()
static const TSCallDescriptor * Create(const CallDescriptor *descriptor, CanThrow can_throw, LazyDeoptOnThrow lazy_deopt_on_throw, Zone *graph_zone, const JSWasmCallParameters *js_wasm_call_parameters=nullptr)
static constexpr uint32_t kSuccessValue
#define END_ALLOW_USE_DEPRECATED()
#define V8_LIKELY(condition)
#define START_ALLOW_USE_DEPRECATED()