5#ifndef V8_WASM_CANONICAL_TYPES_H_
6#define V8_WASM_CANONICAL_TYPES_H_
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
12#include <unordered_map>
21class CanonicalTypeNamesProvider;
212 uint32_t is_relative =
recgroup.Contains(index) ? 1 : 0;
213 uint32_t relative = index.index - is_relative *
recgroup.first.index;
214 return (relative << 1) | is_relative;
223 (supertype_index << 2) | (type.is_shared << 1) | (type.is_final << 0);
227 Add(*type.function_sig);
236 uint32_t desc = (descriptor_index << 11) ^ (describes_index);
238 Add(*type.struct_type);
242 Add(*type.array_type);
245 Add(*type.cont_type);
287 if (
recgroup.Contains(cont_index)) {
311 const bool relative_index =
recgroup1.Contains(index1);
312 if (relative_index !=
recgroup2.Contains(index2))
return false;
313 if (relative_index) {
317 if (rel_type1 != rel_type2)
return false;
318 }
else if (index1 != index2) {
329 switch (type1.
kind) {
349 return std::equal(types1.
begin(), types1.
end(), types2.
begin(),
357 if (indexed != type2.
has_index())
return false;
361 return type1 == type2;
367 sig1.
all().begin(), sig1.
all().end(), sig2.
all().begin(),
407 static_cast<uint32_t
>(
types.size() - 1)};
409 other.first.index +
static_cast<uint32_t
>(other.types.size() - 1)};
416 static_cast<uint32_t
>(
types.size()) - 1};
421 return hasher.
hash();
432 return equality.
EqualType(type, other.type);
438 return hasher.hash();
454 "Reconsider this data structures when increasing kMaxCanonicalTypes");
471 return (*
this)[type.ref_index()];
478 while (!
segments_[segment_idx].load(std::memory_order_relaxed)) {
480 std::memory_order_relaxed);
481 if (segment_idx-- == 0)
break;
494 if (
segments_[
i].load(std::memory_order_relaxed) ==
nullptr)
break;
495 segments_[
i].store(
nullptr, std::memory_order_relaxed);
512 type->function_sig ==
sig) {
#define SBXCHECK_GT(lhs, rhs)
Hasher & AddRange(Iterator first, Iterator last)
constexpr size_t hash() const
constexpr T * begin() const
constexpr T * end() const
size_t parameter_count() const
base::Vector< const T > all() const
CanonicalValueType element_type() const
CanonicalTypeIndex contfun_typeindex() const
base::iterator_range< const CanonicalValueType * > fields() const
constexpr CanonicalTypeIndex ref_index() const
base::iterator_range< const bool * > mutabilities() const
const CanonicalType * operator[](uint32_t index) const
std::atomic< const CanonicalType * > content_[kSegmentSize]
void set(uint32_t index, const CanonicalType *type)
const CanonicalTypeIndex FindIndex_Slow(const CanonicalSig *sig) const
void set(CanonicalTypeIndex index, const CanonicalType *type)
const CanonicalType * operator[](CanonicalValueType type) const
const CanonicalType * operator[](CanonicalTypeIndex index) const
static constexpr uint32_t kNumSegments
void reserve(uint32_t size, Zone *zone)
static constexpr uint32_t kSegmentSize
std::atomic< Segment * > segments_[kNumSegments]
V8_EXPORT_PRIVATE bool IsCanonicalSubtype(CanonicalTypeIndex sub_index, CanonicalTypeIndex super_index)
V8_EXPORT_PRIVATE void AddRecursiveSingletonGroup(WasmModule *module)
V8_EXPORT_PRIVATE const CanonicalStructType * LookupStruct(CanonicalTypeIndex index) const
V8_EXPORT_PRIVATE bool IsFunctionSignature(CanonicalTypeIndex index) const
bool IsCanonicalSubtype_Locked(CanonicalTypeIndex sub_index, CanonicalTypeIndex super_index) const
void AddPredefinedArrayTypes()
static constexpr uint32_t kNumberOfPredefinedTypes
CanonicalType CanonicalizeTypeDef(const WasmModule *module, ModuleTypeIndex module_type_idx, ModuleTypeIndex recgroup_start, CanonicalTypeIndex canonical_recgroup_start)
CanonicalTypeIndex FindIndex_Slow(const CanonicalSig *sig) const
TypeCanonicalizer(const TypeCanonicalizer &other)=delete
V8_EXPORT_PRIVATE const CanonicalArrayType * LookupArray(CanonicalTypeIndex index) const
static V8_EXPORT_PRIVATE void ClearWasmCanonicalTypesForTesting(Isolate *isolate)
V8_EXPORT_PRIVATE size_t GetCurrentNumberOfTypes() const
V8_EXPORT_PRIVATE bool IsStruct(CanonicalTypeIndex index) const
void CheckMaxCanonicalIndex() const
static constexpr CanonicalTypeIndex kPredefinedArrayI16Index
CanonicalTypeIndex FindCanonicalGroup(const CanonicalGroup &) const
AccountingAllocator allocator_
bool IsHeapSubtype(CanonicalTypeIndex sub, CanonicalTypeIndex super) const
V8_EXPORT_PRIVATE bool IsArray(CanonicalTypeIndex index) const
TypeCanonicalizer & operator=(const TypeCanonicalizer &other)=delete
V8_EXPORT_PRIVATE const CanonicalSig * LookupFunctionSignature(CanonicalTypeIndex index) const
V8_EXPORT_PRIVATE void AddRecursiveGroup(WasmModule *module, uint32_t size)
static V8_EXPORT_PRIVATE void PrepareForCanonicalTypeId(Isolate *isolate, CanonicalTypeIndex id)
std::unordered_set< CanonicalSingletonGroup > canonical_singleton_groups_
TypeCanonicalizer & operator=(TypeCanonicalizer &&other)=delete
CanonicalTypeVector canonical_types_
std::vector< CanonicalTypeIndex > canonical_supertypes_
static constexpr CanonicalTypeIndex kPredefinedArrayI8Index
std::unordered_set< CanonicalGroup > canonical_groups_
size_t EstimateCurrentMemoryConsumption() const
V8_EXPORT_PRIVATE void EmptyStorageForTesting()
TypeCanonicalizer(TypeCanonicalizer &&other)=delete
constexpr bool has_index() const
constexpr bool is_nullable() const
static const int kNumIndexBits
constexpr bool is_exact() const
constexpr ModuleTypeIndex ref_index() const
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
static ValueType value_type()
static constexpr size_t kMaxCanonicalTypes
TypeCanonicalizer * GetTypeCanonicalizer()
constexpr uint32_t kInvalidCanonicalIndex
constexpr ModuleTypeIndex kNoType
constexpr size_t kV8MaxWasmTypes
constexpr ModuleTypeIndex kNoSuperType
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
constexpr uint32_t kMaxUInt32
#define DCHECK_LE(v1, v2)
#define DCHECK_NOT_NULL(val)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_GT(v1, v2)
#define V8_EXPORT_PRIVATE
const RecursionGroupRange recgroup1
bool EqualTypeIndex(CanonicalTypeIndex index1, CanonicalTypeIndex index2) const
bool EqualType(const CanonicalType &type1, const CanonicalType &type2) const
bool EqualSig(const CanonicalSig &sig1, const CanonicalSig &sig2) const
bool EqualArrayType(const CanonicalArrayType &type1, const CanonicalArrayType &type2) const
CanonicalEquality(RecursionGroupRange recgroup1, RecursionGroupRange recgroup2)
bool EqualTypes(base::Vector< const CanonicalType > types1, base::Vector< const CanonicalType > types2) const
bool EqualStructType(const CanonicalStructType &type1, const CanonicalStructType &type2) const
bool EqualContType(const CanonicalContType &type1, const CanonicalContType &type2) const
const RecursionGroupRange recgroup2
bool EqualValueType(CanonicalValueType type1, CanonicalValueType type2) const
const base::Vector< CanonicalType > types
CanonicalGroup(Zone *zone, size_t size, CanonicalTypeIndex first)
const CanonicalTypeIndex first
size_t hash_value() const
bool operator==(const CanonicalGroup &other) const
CanonicalHashing(RecursionGroupRange recgroup)
void Add(const CanonicalStructType &struct_type)
void Add(CanonicalType type)
uint32_t MakeGroupRelative(CanonicalTypeIndex index)
void Add(CanonicalValueType value_type)
const RecursionGroupRange recgroup
void Add(const CanonicalContType &cont_type)
void Add(const CanonicalArrayType &array_type)
void Add(const CanonicalSig &sig)
bool operator==(const CanonicalSingletonGroup &other) const
size_t hash_value() const
CanonicalTypeIndex supertype
const CanonicalArrayType * array_type
const CanonicalContType * cont_type
constexpr CanonicalType(const CanonicalSig *sig, CanonicalTypeIndex supertype, bool is_final, bool is_shared)
constexpr CanonicalType(const CanonicalContType *type, CanonicalTypeIndex supertype, bool is_final, bool is_shared)
const CanonicalStructType * struct_type
const CanonicalSig * function_sig
constexpr CanonicalType()=default
constexpr CanonicalType(const CanonicalArrayType *type, CanonicalTypeIndex supertype, bool is_final, bool is_shared)
constexpr CanonicalType(const CanonicalStructType *type, CanonicalTypeIndex supertype, CanonicalTypeIndex descriptor, CanonicalTypeIndex describes, bool is_final, bool is_shared)
CanonicalTypeIndex describes
CanonicalTypeIndex descriptor
bool Contains(CanonicalTypeIndex index) const
const CanonicalTypeIndex first
const CanonicalTypeIndex last