5#ifndef V8_COMPILER_TURBOSHAFT_WASM_GC_TYPED_OPTIMIZATION_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_WASM_GC_TYPED_OPTIMIZATION_REDUCER_H_
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
158 const WasmTypeCastOp& cast_op) {
160 return Next::ReduceInputGraphWasmTypeCast(op_idx, cast_op);
165 if (type.is_uninhabited()) {
171 __ TrapIf(1, TrapId::kTrapIllegalCast);
176 CHECK(!type.is_uninhabited());
178 cast_op.config.to.heap_type(),
module_));
179 bool to_nullable = cast_op.config.to.is_nullable();
182 if (to_nullable || type.is_non_nullable()) {
185 return __ MapToNewGraph(cast_op.object());
191 TrapId::kTrapIllegalCast);
195 cast_op.config.to.heap_type(),
module_,
200 type.is_nullable() && to_nullable ?
__ IsNull(
__ MapToNewGraph(
203 :
__ Word32Constant(0);
204 __ TrapIfNot(non_trapping_condition, TrapId::kTrapIllegalCast);
208 return __ MapToNewGraph(cast_op.object());
224 __ MapToNewGraph(cast_op.rtt()), config);
230 V<Word32> op_idx,
const WasmTypeCheckOp& type_check) {
232 return Next::ReduceInputGraphWasmTypeCheck(op_idx, type_check);
237 if (type.is_uninhabited()) {
242 CHECK(!type.is_uninhabited());
244 type.heap_type(), type_check.config.to.heap_type(),
module_));
245 bool to_nullable = type_check.config.to.is_nullable();
247 type_check.config.to.heap_type(),
module_,
249 if (to_nullable || type.is_non_nullable()) {
252 return __ Word32Constant(1);
256 return __ Word32Equal(
257 __ IsNull(
__ MapToNewGraph(type_check.object()), type), 0);
261 type_check.config.to.heap_type(),
module_,
263 if (to_nullable && type.is_nullable()) {
264 return __ IsNull(
__ MapToNewGraph(type_check.object()), type);
266 return __ Word32Constant(0);
275 return __ Word32Constant(0);
287 __ MapToNewGraph(type_check.rtt()), config);
293 V<Object> op_idx,
const AssertNotNullOp& assert_not_null) {
295 return Next::ReduceInputGraphAssertNotNull(op_idx, assert_not_null);
300 if (type.is_uninhabited()) {
306 __ TrapIf(1, assert_not_null.trap_id);
310 if (type.is_non_nullable()) {
311 return __ MapToNewGraph(assert_not_null.object());
317 const IsNullOp& is_null) {
319 return Next::ReduceInputGraphIsNull(op_idx, is_null);
324 if (type.is_uninhabited()) {
328 if (type.is_non_nullable()) {
329 return __ Word32Constant(0);
333 return __ Word32Constant(1);
339 V<Object> op_idx,
const WasmTypeAnnotationOp& type_annotation) {
341 return __ MapToNewGraph(type_annotation.value());
345 const StructGetOp& struct_get) {
347 return Next::ReduceInputGraphStructGet(op_idx, struct_get);
352 if (type.is_uninhabited()) {
358 __ TrapIf(1, TrapId::kTrapNullDereference);
363 if (struct_get.null_check ==
kWithNullCheck && type.is_non_nullable()) {
365 struct_get.type, struct_get.type_index,
366 struct_get.field_index, struct_get.is_signed,
373 const StructSetOp& struct_set) {
375 return Next::ReduceInputGraphStructSet(op_idx, struct_set);
380 if (type.is_uninhabited()) {
386 __ TrapIf(1, TrapId::kTrapNullDereference);
391 if (struct_set.null_check ==
kWithNullCheck && type.is_non_nullable()) {
393 __ MapToNewGraph(struct_set.value()), struct_set.type,
394 struct_set.type_index, struct_set.field_index,
402 const ArrayLengthOp& array_length) {
404 return Next::ReduceInputGraphArrayLength(op_idx, array_length);
410 if (array_length.null_check ==
kWithNullCheck && type.is_non_nullable()) {
420 LABEL_BLOCK(no_change) {
return Next::ReduceAnyConvertExtern(
object); }
423 if (
object.valid()) {
424 const ExternConvertAnyOp* externalize =
426 if (externalize !=
nullptr) {
429 return externalize->object();
#define REDUCE(operation)
#define REDUCE_INPUT_GRAPH(operation)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
uint32_t block_count() const
static constexpr OpIndex Invalid()
bool is_first_loop_header_evaluation_
void ProcessTypeAnnotation(const WasmTypeAnnotationOp &type_annotation)
void ProcessGlobalGet(const GlobalGetOp &global_get)
TypeSnapshotTable::MaybeSnapshot MaybeSnapshot
void ProcessAllocateArray(const WasmAllocateArrayOp &allocate_array)
wasm::ValueType RefineTypeKnowledgeNotNull(OpIndex object, const Operation &op)
void ProcessOperations(const Block &block)
const wasm::WasmModule * module_
bool IsReachable(const Block &block) const
wasm::ValueType GetInputTypeOrSentinelType(OpIndex op) const
void ProcessArrayGet(const ArrayGetOp &array_get)
wasm::ValueType GetTypeForPhiInput(const PhiOp &phi, int input_index)
const wasm::FunctionSig * signature_
ZoneUnorderedMap< OpIndex, wasm::ValueType > input_type_map_
void ProcessTypeCast(const WasmTypeCastOp &type_cast)
void ProcessTypeCheck(const WasmTypeCheckOp &type_check)
void ProcessParameter(const ParameterOp ¶meter)
FixedBlockSidetable< MaybeSnapshot > block_to_snapshot_
void ProcessNull(const NullOp &null)
const Block * current_block_
void CreateMergeSnapshot(const Block &block)
void ProcessStructGet(const StructGetOp &struct_get)
void ProcessBlock(const Block &block)
WasmGCTypeAnalyzer(PipelineData *data, Graph &graph, Zone *zone)
void ProcessAssertNotNull(const AssertNotNullOp &type_cast)
void ProcessRefFunc(const WasmRefFuncOp &ref_func)
wasm::ValueType GetResolvedType(OpIndex object) const
TypeSnapshotTable types_table_
void ProcessAllocateStruct(const WasmAllocateStructOp &allocate_struct)
wasm::ValueType RefineTypeKnowledge(OpIndex object, wasm::ValueType new_type, const Operation &op)
void ProcessStructSet(const StructSetOp &struct_set)
void ProcessIsNull(const IsNullOp &is_null)
OpIndex ResolveAliases(OpIndex object) const
TypeSnapshotTable::Snapshot Snapshot
void ProcessBranchOnTarget(const BranchOp &branch, const Block &target)
void StartNewSnapshotFor(const Block &block)
void ProcessPhi(const PhiOp &phi)
void ProcessArrayLength(const ArrayLengthOp &array_length)
BitVector block_is_unreachable_
WasmGCTypeAnalyzer analyzer_
V< Word32 > REDUCE_INPUT_GRAPH WasmTypeCheck(V< Word32 > op_idx, const WasmTypeCheckOp &type_check)
V< Object > REDUCE_INPUT_GRAPH WasmTypeAnnotation(V< Object > op_idx, const WasmTypeAnnotationOp &type_annotation)
V< Any > REDUCE_INPUT_GRAPH StructGet(V< Any > op_idx, const StructGetOp &struct_get)
const wasm::WasmModule * module_
V< Object > REDUCE_INPUT_GRAPH AssertNotNull(V< Object > op_idx, const AssertNotNullOp &assert_not_null)
V< None > REDUCE_INPUT_GRAPH StructSet(V< None > op_idx, const StructSetOp &struct_set)
V< Object > REDUCE AnyConvertExtern(V< Object > object)
V< Word32 > REDUCE_INPUT_GRAPH ArrayLength(V< Word32 > op_idx, const ArrayLengthOp &array_length)
V< Word32 > REDUCE_INPUT_GRAPH IsNull(V< Word32 > op_idx, const IsNullOp &is_null)
V< Object > REDUCE_INPUT_GRAPH WasmTypeCast(V< Object > op_idx, const WasmTypeCastOp &cast_op)
constexpr Exactness exactness() const
constexpr bool is_uninhabited() const
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
#define LABEL_BLOCK(label)
V8_EXPORT_PRIVATE bool ShouldSkipOptimizationStep()
ValueType ToNullSentinel(TypeInModule type)
bool IsSameTypeHierarchy(HeapType type1, HeapType type2, const WasmModule *module)
V8_INLINE bool IsHeapSubtypeOf(HeapType subtype, HeapType supertype, const WasmModule *sub_module, const WasmModule *super_module)
TypeInModule Intersection(ValueType type1, ValueType type2, const WasmModule *module1, const WasmModule *module2)
V8_INLINE bool HeapTypesUnrelated(HeapType heap1, HeapType heap2, const WasmModule *module1, const WasmModule *module2)
bool TryCast(Tagged< From > value, Tagged< To > *out)
#define DCHECK_NOT_NULL(val)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)