5#ifndef V8_CODEGEN_TURBOSHAFT_BUILTINS_ASSEMBLER_INL_H_
6#define V8_CODEGEN_TURBOSHAFT_BUILTINS_ASSEMBLER_INL_H_
20#define DEFINE_TURBOSHAFT_ALIASES() \
21 template <typename T> \
22 using V = compiler::turboshaft::V<T>; \
23 template <typename T> \
24 using ConstOrV = compiler::turboshaft::ConstOrV<T>; \
25 template <typename T> \
26 using OptionalV = compiler::turboshaft::OptionalV<T>; \
27 template <typename... Ts> \
28 using Label = compiler::turboshaft::Label<Ts...>; \
29 template <typename... Ts> \
30 using LoopLabel = compiler::turboshaft::LoopLabel<Ts...>; \
31 using Block = compiler::turboshaft::Block; \
32 using OpIndex = compiler::turboshaft::OpIndex; \
33 using Word32 = compiler::turboshaft::Word32; \
34 using Word64 = compiler::turboshaft::Word64; \
35 using WordPtr = compiler::turboshaft::WordPtr; \
36 using Float32 = compiler::turboshaft::Float32; \
37 using Float64 = compiler::turboshaft::Float64; \
38 using RegisterRepresentation = compiler::turboshaft::RegisterRepresentation; \
39 using MemoryRepresentation = compiler::turboshaft::MemoryRepresentation; \
40 using BuiltinCallDescriptor = compiler::turboshaft::BuiltinCallDescriptor; \
41 using AccessBuilderTS = compiler::turboshaft::AccessBuilderTS;
43#define BUILTIN_REDUCER(name) \
44 TURBOSHAFT_REDUCER_BOILERPLATE(name) \
45 DEFINE_TURBOSHAFT_ALIASES()
56template <
typename Assembler>
68 if constexpr (std::is_same_v<T, WordPtr>) {
71 if constexpr (std::is_same_v<T, Word32>) {
72 DCHECK((std::is_same_v<WordPtr, Word64>));
75 static_assert(std::is_same_v<T, Word64>);
76 DCHECK((std::is_same_v<WordPtr, Word32>));
83 fp_ = __ FramePointer();
115 template <
typename A>
123 template <
typename A>
126 return assembler.UintPtrLessThanOrEqual(
end_offset_, current_iterator);
129 template <
typename A>
131 return assembler.WordPtrAdd(
135 template <
typename A>
175template <
typename Next>
184 __ CodeComment(
"CombineFeedback");
190 __ CodeComment(
"OverwriteFeedback");
220 int additional_offset = 0) {
221 __ CodeComment(
"LoadFeedbackVectorSlot");
222 int32_t header_size =
223 FeedbackVector::kRawFeedbackSlotsOffset + additional_offset;
228 FeedbackVector::kHeaderSize));
238 int additional_offset = 0) {
239 __ CodeComment(
"StoreFeedbackVectorSlot");
242 FeedbackVector::kRawFeedbackSlotsOffset + additional_offset;
247 FeedbackVector::kHeaderSize));
248 switch (barrier_mode) {
250 __ Store(feedback_vector,
offset, value,
292 __ CodeComment(
"UpdateFeedback");
329 return __ BitcastWord32ToSmi(
330 __ Word32BitwiseOr(
__ BitcastSmiToWord32(a),
__ BitcastSmiToWord32(b)));
334 return __ Word32Equal(
__ BitcastSmiToWord32(a),
__ BitcastSmiToWord32(b));
339 return __ ChangeUint32ToUintPtr(input);
343 V<Map> map =
__ LoadMapField(heap_object);
344 return __ IsFeedbackVectorMap(map);
352 int correction = header_size - element_size;
354 __ ElementOffsetFromIndex(length,
kind, correction);
355 return __ IntPtrLessThanOrEqual(
offset, last_offset);
366template <
typename Next>
383template <
typename Next>
392 __ Bind(
__ NewBlock());
396 __ data() -> builtin_call_descriptor();
397 for (
int i = 0; i < static_cast<int>(desc->ParameterCount()); ++
i) {
399 desc->GetParameterType(
i)));
409 DCHECK_EQ(
__ HasFeedbackCollector(), catch_block !=
nullptr);
413 if (
__ Bind(catch_block)) {
415 __ CombineExceptionFeedback();
419 __ data()->isolate(),
__ NoContextConstant(), {exception});
426 return __ template Parameter<Context>(
432 __ JSStackCheck(context,
454 CHECK_EQ(
__ data()->builtin_call_descriptor()->ParameterSlotCount(), 0);
455 V<WordPtr> pop_count = arguments.GetLengthWithReceiver();
456 std::initializer_list<const OpIndex> temp{return_value};
465 BIND(is_number, number);
475 return __ Word32Equal(instance_type, other_instance_type);
484 intptr_t base_size) {
487 return __ WordPtrConstant(base_size +
488 (1 << element_size_shift) * (*constant_index));
490 if (element_size_shift == 0) {
491 return __ WordPtrAdd(base_size, index);
494 return __ WordPtrAdd(base_size,
495 __ WordPtrShiftLeft(index, element_size_shift));
500 if (index.is_constant())
return index.constant_value();
508 template <Object::Conversion Conversion>
515 if_bigint !=
nullptr);
526 V<Map> map =
__ LoadMapField(value_heap_object);
528 IF (
__ IsHeapNumberMap(map)) {
532 GOTO(if_number,
__ JSTruncateFloat64ToWord32(value_float64));
535 V<Word32> instance_type =
__ LoadInstanceTypeField(map);
539 if (
Is64() && if_bigint64) {
542 GOTO(*if_bigint64, value_bigint);
546 GOTO(*if_bigint, value_bigint);
551 if (
__ HasFeedbackCollector()) {
561 AccessBuilderTS::ForHeapNumberOrOddballOrHoleValue());
562 GOTO(if_number,
__ JSTruncateFloat64ToWord32(oddball_value));
575 converted_value =
__ template CallBuiltin<Builtin>(
591template <
template <
typename>
typename Reducer,
592 template <
typename>
typename FeedbackReducer>
595 Reducer, BuiltinsReducer, FeedbackReducer,
596 compiler::turboshaft::MachineLoweringReducer,
597 compiler::turboshaft::VariableReducer> {
#define TSA_SLOW_DCHECK(assembler,...)
#define TSA_DCHECK(assembler, condition)
#define GOTO_IF(cond, label,...)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
V< Word32 > TruncateTaggedToWord32(V< Context > context, V< Object > value)
compiler::turboshaft::OperationMatcher matcher_
void TaggedToWord32OrBigIntImpl(V< Context > context, V< Object > value, IsKnownTaggedPointer is_known_tagged_pointer, Label< Word32 > &if_number, Label< BigInt > *if_bigint=nullptr, Label< BigInt > *if_bigint64=nullptr)
std::optional< intptr_t > TryToIntPtrConstant(ConstOrV< WordPtr > index)
V< WordPtr > ElementOffsetFromIndex(ConstOrV< WordPtr > index, ElementsKind kind, intptr_t base_size)
void PopAndReturn(BuiltinArgumentsTS &arguments, compiler::turboshaft::V< Object > return_value)
void EmitBuiltinProlog(Builtin builtin_id)
void EmitEpilog(Block *catch_block)
V< Word32 > IsSmallBigInt(V< BigInt > value)
void PerformStackCheck(V< Context > context)
V< Word32 > InstanceTypeEqual(ConstOrV< Word32 > instance_type, ConstOrV< Word32 > other_instance_type)
V< Word32 > IsBigIntInstanceType(ConstOrV< Word32 > instance_type)
V< WordPtr > AlignTagged(V< WordPtr > size)
V< Context > JSContextParameter()
static V8_EXPORT_PRIVATE Kind KindOf(Builtin builtin)
static constexpr int kFixedSlotCountAboveFp
V< Smi > SmiBitwiseOr(V< Smi > a, V< Smi > b)
void CombineFeedback(int additional_feedback)
static constexpr bool HasFeedbackCollector()
V< FeedbackVectorOrUndefined > maybe_feedback_vector_
static constexpr UpdateFeedbackMode DefaultUpdateFeedbackMode()
void CombineFeedbackOnException(int additional_feedback)
compiler::turboshaft::Var< Smi, assembler_t > feedback_
V< Word32 > SmiEqual(V< Smi > a, V< Smi > b)
void LoadFeedbackVectorOrUndefinedIfJitless()
void CombineExceptionFeedback()
compiler::turboshaft::Var< Smi, assembler_t > feedback_on_exception_
V< MaybeObject > LoadFeedbackVectorSlot(V< FeedbackVector > feedback_vector, V< WordPtr > slot, int additional_offset=0)
void OverwriteFeedback(int new_feedback)
void SetFeedbackVector(V< FeedbackVector > feedback_vector)
V< Word32 > IsFeedbackVector(V< HeapObject > heap_object)
V< WordPtr > ChangePositiveInt32ToIntPtr(V< Word32 > input)
V< FeedbackVectorOrUndefined > LoadFeedbackVector()
void SetFeedbackSlot(V< WordPtr > slot_id)
void StoreFeedbackVectorSlot(V< FeedbackVector > feedback_vector, V< WordPtr > slot, V< Object > value, WriteBarrierMode barrier_mode=UPDATE_WRITE_BARRIER, int additional_offset=0)
V< Word32 > IsOffsetInBounds(V< WordPtr > offset, V< WordPtr > length, int header_size, ElementsKind kind=HOLEY_ELEMENTS)
V< WordPtr > LoadFeedbackVectorLength(V< FeedbackVector > feedback_vector)
V< Word32 > FeedbackIs(int checked_feedback)
void CombineExceptionFeedback()
void CombineFeedback(int additional_feedback)
static constexpr bool HasFeedbackCollector()
void OverwriteFeedback(int new_feedback)
V< Word32 > FeedbackIs(int checked_feedback)
static constexpr Tagged< Smi > FromInt(int value)
TurboshaftBuiltinsAssembler(compiler::turboshaft::PipelineData *data, compiler::turboshaft::Graph &graph, Zone *phase_zone)
static constexpr int GetJSCallContextParamIndex(int parameter_count)
static FieldAccessTS< FeedbackVector, Word32 > ForFeedbackVectorLength()
static constexpr MemoryRepresentation AnyTagged()
constexpr bool valid() const
bool MatchIntegralWordPtrConstant(V< Any > matched, T *constant) const
static constexpr RegisterRepresentation FromMachineType(MachineType type)
static V< T > Cast(V< U > index)
ConstOrV< WordPtr > begin_index_
Iterator(const BuiltinArgumentsTS *args, ConstOrV< WordPtr > begin_index, ConstOrV< WordPtr > end_index)
ConstOrV< WordPtr > end_index_
const BuiltinArgumentsTS * args_
iterator_type Advance(A &assembler, iterator_type current_iterator) const
iterator_type Begin(A &assembler)
OptionalV< Word32 > IsEnd(A &assembler, iterator_type current_iterator) const
value_type Dereference(A &assembler, iterator_type current_iterator) const
V< WordPtr > AtIndexPtr(ConstOrV< WordPtr > index) const
V< WordPtr > GetLengthWithoutReceiver() const
Iterator Range(ConstOrV< WordPtr > begin, ConstOrV< WordPtr > end) const
V< Object > AtIndex(ConstOrV< WordPtr > index) const
V< WordPtr > GetLengthWithReceiver() const
BuiltinArgumentsTS(Assembler *assembler, V< T > argc, OptionalV< WordPtr > fp={})
Iterator Range(ConstOrV< WordPtr > begin) const
static constexpr Register feedback_vector()
base::Vector< const DirectHandle< Object > > args
constexpr Vector< T > VectorOf(T *start, size_t size)
constexpr int kTaggedSize
@ UPDATE_EPHEMERON_KEY_WRITE_BARRIER
@ UNSAFE_SKIP_WRITE_BARRIER
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
@ SYSTEM_POINTER_ELEMENTS
constexpr int kJSArgcReceiverSlots
constexpr int kSystemPointerSize
constexpr int ElementsKindToShiftSize(ElementsKind elements_kind)
constexpr intptr_t kObjectAlignmentMask
DONT_OVERRIDE DISABLE_ALLOCATION_SITES HOLEY_ELEMENTS
constexpr int JSParameterCount(int param_count_without_receiver)
constexpr int ElementsKindToByteSize(ElementsKind elements_kind)
i::Address Load(i::Address address)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
constexpr bool IsAligned(T value, U alignment)
static constexpr Kind TaggedBase()
#define BUILTIN_REDUCER(name)
#define DEFINE_TURBOSHAFT_ALIASES()