Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 v12.3 patch #15

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions deps/v8/src/builtins/builtins-collections-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2782,10 +2782,9 @@ TNode<Word32T> WeakCollectionsBuiltinsAssembler::ShouldShrink(

TNode<IntPtrT> WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex(
TNode<IntPtrT> key_index) {
return IntPtrAdd(
key_index,
IntPtrConstant(EphemeronHashTable::TodoShape::kEntryValueIndex -
EphemeronHashTable::kEntryKeyIndex));
return IntPtrAdd(key_index,
IntPtrConstant(EphemeronHashTable::ShapeT::kEntryValueIndex -
EphemeronHashTable::kEntryKeyIndex));
}

TF_BUILTIN(WeakMapConstructor, WeakCollectionsBuiltinsAssembler) {
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/codegen/code-stub-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9505,7 +9505,7 @@ void CodeStubAssembler::NameDictionaryLookup(
CAST(UnsafeLoadFixedArrayElement(dictionary, index));
GotoIf(TaggedEqual(current, undefined), if_not_found_with_insertion_index);
if (mode == kFindExisting) {
if (Dictionary::TodoShape::kMatchNeedsHoleCheck) {
if (Dictionary::ShapeT::kMatchNeedsHoleCheck) {
GotoIf(TaggedEqual(current, TheHoleConstant()), &next_probe);
}
current = LoadName<Dictionary>(current);
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/codegen/code-stub-assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<Smi> LoadFixedArrayBaseLength(TNode<FixedArrayBase> array);
template <typename Array>
TNode<Smi> LoadArrayCapacity(TNode<Array> array) {
return LoadObjectField<Smi>(array, Array::Shape::kCapacityOffset);
return LoadObjectField<Smi>(array, Array::ShapeT::kCapacityOffset);
}
// Load the length of a fixed array base instance.
TNode<IntPtrT> LoadAndUntagFixedArrayBaseLength(TNode<FixedArrayBase> array);
Expand Down
41 changes: 23 additions & 18 deletions deps/v8/src/compiler/turboshaft/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,7 @@ class TurboshaftAssemblerOpInterface

template <typename... Args>
explicit TurboshaftAssemblerOpInterface(Args... args)
: GenericAssemblerOpInterface<Next>(args...),
matcher_(Asm().output_graph()) {}
: matcher_(Asm().output_graph()) {}

const OperationMatcher& matcher() const { return matcher_; }

Expand Down Expand Up @@ -2245,11 +2244,11 @@ class TurboshaftAssemblerOpInterface

// Helpers to read the most common fields.
// TODO(nicohartmann@): Strengthen this to `V<HeapObject>`.
V<Map> LoadMapField(V<Object> object) {
return LoadField<Map>(object, AccessBuilder::ForMap());
V<v8::internal::Map> LoadMapField(V<Object> object) {
return LoadField<v8::internal::Map>(object, AccessBuilder::ForMap());
}

V<Word32> LoadInstanceTypeField(V<Map> map) {
V<Word32> LoadInstanceTypeField(V<v8::internal::Map> map) {
return LoadField<Word32>(map, AccessBuilder::ForMapInstanceType());
}

Expand Down Expand Up @@ -2849,7 +2848,7 @@ class TurboshaftAssemblerOpInterface
V<Object> CallRuntime_TransitionElementsKind(Isolate* isolate,
V<Context> context,
V<HeapObject> object,
V<Map> target_map) {
V<v8::internal::Map> target_map) {
return CallRuntime<typename RuntimeCallDescriptor::TransitionElementsKind>(
isolate, context, {object, target_map});
}
Expand Down Expand Up @@ -3267,8 +3266,8 @@ class TurboshaftAssemblerOpInterface

void TransitionAndStoreArrayElement(
V<Object> array, V<WordPtr> index, OpIndex value,
TransitionAndStoreArrayElementOp::Kind kind, MaybeHandle<Map> fast_map,
MaybeHandle<Map> double_map) {
TransitionAndStoreArrayElementOp::Kind kind, MaybeHandle<v8::internal::Map> fast_map,
MaybeHandle<v8::internal::Map> double_map) {
ReduceIfReachableTransitionAndStoreArrayElement(array, index, value, kind,
fast_map, double_map);
}
Expand All @@ -3281,17 +3280,17 @@ class TurboshaftAssemblerOpInterface
}

V<Word32> CompareMaps(V<HeapObject> heap_object,
const ZoneRefSet<Map>& maps) {
const ZoneRefSet<v8::internal::Map>& maps) {
return ReduceIfReachableCompareMaps(heap_object, maps);
}

void CheckMaps(V<HeapObject> heap_object, OpIndex frame_state,
const ZoneRefSet<Map>& maps, CheckMapsFlags flags,
const ZoneRefSet<v8::internal::Map>& maps, CheckMapsFlags flags,
const FeedbackSource& feedback) {
ReduceIfReachableCheckMaps(heap_object, frame_state, maps, flags, feedback);
}

void AssumeMap(V<HeapObject> heap_object, const ZoneRefSet<Map>& maps) {
void AssumeMap(V<HeapObject> heap_object, const ZoneRefSet<v8::internal::Map>& maps) {
ReduceIfReachableAssumeMap(heap_object, maps);
}

Expand Down Expand Up @@ -3400,16 +3399,16 @@ class TurboshaftAssemblerOpInterface
return ReduceIfReachableAssertNotNull(object, type, trap_id);
}

V<Map> RttCanon(V<FixedArray> rtts, uint32_t type_index) {
V<v8::internal::Map> RttCanon(V<FixedArray> rtts, uint32_t type_index) {
return ReduceIfReachableRttCanon(rtts, type_index);
}

V<Word32> WasmTypeCheck(V<Tagged> object, OptionalV<Map> rtt,
V<Word32> WasmTypeCheck(V<Tagged> object, OptionalV<v8::internal::Map> rtt,
WasmTypeCheckConfig config) {
return ReduceIfReachableWasmTypeCheck(object, rtt, config);
}

V<Tagged> WasmTypeCast(V<Tagged> object, OptionalV<Map> rtt,
V<Tagged> WasmTypeCast(V<Tagged> object, OptionalV<v8::internal::Map> rtt,
WasmTypeCheckConfig config) {
return ReduceIfReachableWasmTypeCast(object, rtt, config);
}
Expand Down Expand Up @@ -3454,12 +3453,12 @@ class TurboshaftAssemblerOpInterface
return ReduceIfReachableArrayLength(array, null_check);
}

V<HeapObject> WasmAllocateArray(V<Map> rtt, ConstOrV<Word32> length,
V<HeapObject> WasmAllocateArray(V<v8::internal::Map> rtt, ConstOrV<Word32> length,
const wasm::ArrayType* array_type) {
return ReduceIfReachableWasmAllocateArray(rtt, resolve(length), array_type);
}

V<HeapObject> WasmAllocateStruct(V<Map> rtt,
V<HeapObject> WasmAllocateStruct(V<v8::internal::Map> rtt,
const wasm::StructType* struct_type) {
return ReduceIfReachableWasmAllocateStruct(rtt, struct_type);
}
Expand Down Expand Up @@ -4044,8 +4043,14 @@ class TSAssembler
: public Assembler<reducer_list<TurboshaftAssemblerOpInterface, Reducers...,
TSReducerBase>> {
public:
using Assembler<reducer_list<TurboshaftAssemblerOpInterface, Reducers...,
TSReducerBase>>::Assembler;
#ifdef _WIN32
explicit TSAssembler(Graph& input_graph, Graph& output_graph,
Zone* phase_zone)
: Assembler(input_graph, output_graph, phase_zone) {}
#else
using Assembler<reducer_list<TurboshaftAssemblerOpInterface, Reducers...,
TSReducerBase>>::Assembler;
#endif
};

#include "src/compiler/turboshaft/undef-assembler-macros.inc"
Expand Down
50 changes: 10 additions & 40 deletions deps/v8/src/compiler/turboshaft/machine-optimization-reducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1349,53 +1349,23 @@ class MachineOptimizationReducer : public Next {
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
left, &x, rep_w, &k1) &&
matcher.MatchIntegralWordConstant(right, rep_w, &k2) &&
CountLeadingSignBits(k2, rep_w) > k1) {
if (matcher.Get(left).saturated_use_count.IsZero()) {
return __ Comparison(
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
rep_w);
} else if constexpr (reducer_list_contains<
ReducerList, ValueNumberingReducer>::value) {
// If the shift has uses, we only apply the transformation if the
// result would be GVNed away.
OpIndex rhs =
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
static_assert(ComparisonOp::input_count == 2);
static_assert(sizeof(ComparisonOp) == 8);
base::SmallVector<OperationStorageSlot, 32> storage;
ComparisonOp* cmp =
CreateOperation<ComparisonOp>(storage, x, rhs, kind, rep_w);
if (__ WillGVNOp(*cmp)) {
return __ Comparison(x, rhs, kind, rep_w);
}
}
CountLeadingSignBits(k2, rep_w) > k1 &&
matcher.Get(left).saturated_use_count.IsZero()) {
return __ Comparison(
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
rep_w);
Comment on lines -1352 to +1356
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems non-trivial. What's the effect of removing the else if branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a revert of this commit. It was also a part of v12.2 fix before.

}
// k2 </<= (x >> k1) => (k2 << k1) </<= x if shifts reversible
// Only perform the transformation if the shift is not used yet, to
// avoid keeping both the shift and x alive.
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
right, &x, rep_w, &k1) &&
matcher.MatchIntegralWordConstant(left, rep_w, &k2) &&
CountLeadingSignBits(k2, rep_w) > k1) {
if (matcher.Get(right).saturated_use_count.IsZero()) {
return __ Comparison(
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
rep_w);
} else if constexpr (reducer_list_contains<
ReducerList, ValueNumberingReducer>::value) {
// If the shift has uses, we only apply the transformation if the
// result would be GVNed away.
OpIndex lhs =
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
static_assert(ComparisonOp::input_count == 2);
static_assert(sizeof(ComparisonOp) == 8);
base::SmallVector<OperationStorageSlot, 32> storage;
ComparisonOp* cmp =
CreateOperation<ComparisonOp>(storage, lhs, x, kind, rep_w);
if (__ WillGVNOp(*cmp)) {
return __ Comparison(lhs, x, kind, rep_w);
}
}
CountLeadingSignBits(k2, rep_w) > k1 &&
matcher.Get(right).saturated_use_count.IsZero()) {
return __ Comparison(
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
rep_w);
}
}
// Map 64bit to 32bit comparisons.
Expand Down
14 changes: 7 additions & 7 deletions deps/v8/src/compiler/turboshaft/simplified-lowering-reducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ class SimplifiedLoweringReducer : public Next {
OpIndex ig_index, const SpeculativeNumberBinopOp& op) {
DCHECK_EQ(op.kind, SpeculativeNumberBinopOp::Kind::kSafeIntegerAdd);

OpIndex frame_state = Map(op.frame_state());
V<Word32> left = ProcessInput(Map(op.left()), Rep::Word32(),
OpIndex frame_state = MapImpl(op.frame_state());
V<Word32> left = ProcessInput(MapImpl(op.left()), Rep::Word32(),
CheckKind::kSigned32, frame_state);
V<Word32> right = ProcessInput(Map(op.right()), Rep::Word32(),
V<Word32> right = ProcessInput(MapImpl(op.right()), Rep::Word32(),
CheckKind::kSigned32, frame_state);

V<Word32> result = __ OverflowCheckedBinop(
left, right, OverflowCheckedBinopOp::Kind::kSignedAdd,
WordRepresentation::Word32());

V<Word32> overflow = __ Projection(result, 1, Rep::Word32());
__ DeoptimizeIf(overflow, Map(op.frame_state()),
__ DeoptimizeIf(overflow, MapImpl(op.frame_state()),
DeoptimizeReason::kOverflow, FeedbackSource{});
return __ Projection(result, 0, Rep::Word32());
}
Expand All @@ -52,10 +52,10 @@ class SimplifiedLoweringReducer : public Next {
base::SmallVector<OpIndex, 8> return_values;
for (OpIndex input : ret.return_values()) {
return_values.push_back(
ProcessInput(Map(input), Rep::Tagged(), CheckKind::kNone, {}));
ProcessInput(MapImpl(input), Rep::Tagged(), CheckKind::kNone, {}));
}

__ Return(Map(ret.pop_count()), base::VectorOf(return_values));
__ Return(MapImpl(ret.pop_count()), base::VectorOf(return_values));
return OpIndex::Invalid();
}

Expand Down Expand Up @@ -94,7 +94,7 @@ class SimplifiedLoweringReducer : public Next {
}
}

inline OpIndex Map(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
inline OpIndex MapImpl(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
};

#include "src/compiler/turboshaft/undef-assembler-macros.inc"
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/compiler/turboshaft/variable-reducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ namespace v8::internal::compiler::turboshaft {
// with constant inputs introduced by `VariableReducer` need to be eliminated.
template <class AfterNext>
class VariableReducer : public RequiredOptimizationReducer<AfterNext> {
protected:
using Next = RequiredOptimizationReducer<AfterNext>;
using Snapshot = SnapshotTable<OpIndex, VariableData>::Snapshot;

private:
struct GetActiveLoopVariablesIndex {
IntrusiveSetIndex& operator()(Variable var) const {
return var.data().active_loop_variables_index;
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3570,7 +3570,7 @@ void Heap::RightTrimArray(Tagged<Array> object, int new_capacity,
}

const int bytes_to_trim =
(old_capacity - new_capacity) * Array::Shape::kElementSize;
(old_capacity - new_capacity) * Array::HotfixShape::kElementSize;

// Calculate location of new array end.
const int old_size = Array::SizeFor(old_capacity);
Expand Down
5 changes: 2 additions & 3 deletions deps/v8/src/objects/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
using DerivedHashTable = HashTable<Derived, Shape>;

public:
using TodoShape = Shape;
using Key = typename TodoShape::Key;
using Key = typename Shape::Key;
inline Tagged<Object> ValueAt(InternalIndex entry);
inline Tagged<Object> ValueAt(PtrComprCageBase cage_base,
InternalIndex entry);
Expand Down Expand Up @@ -126,7 +125,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
Key key, Handle<Object> value,
PropertyDetails details);

OBJECT_CONSTRUCTORS(Dictionary, HashTable<Derived, TodoShape>);
OBJECT_CONSTRUCTORS(Dictionary, HashTable<Derived, Shape>);
};

#define EXTERN_DECLARE_DICTIONARY(DERIVED, SHAPE) \
Expand Down
Loading
Loading