Skip to content
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
60 changes: 20 additions & 40 deletions src/passes/MinimizeRecGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,27 @@ struct TypeSCCs
// provides an infinite sequence of possible brand types, prioritizing those
// with the most compact encoding.
struct BrandTypeIterator {
// See `initFieldOptions` for the 18 options.
static constexpr Index optionCount = 18;
static std::array<Field, optionCount> fieldOptions;
static void initFieldOptions();
static constexpr std::array<Field, optionCount> fieldOptions = {{
Field(Field::i8, Mutable),
Field(Field::i16, Mutable),
Field(Type::i32, Mutable),
Field(Type::i64, Mutable),
Field(Type::f32, Mutable),
Field(Type::f64, Mutable),
Field(Type(HeapType::any, Nullable), Mutable),
Field(Type(HeapType::func, Nullable), Mutable),
Field(Type(HeapType::ext, Nullable), Mutable),
Field(Type(HeapType::none, Nullable), Mutable),
Field(Type(HeapType::nofunc, Nullable), Mutable),
Field(Type(HeapType::noext, Nullable), Mutable),
Field(Type(HeapType::any, NonNullable), Mutable),
Field(Type(HeapType::func, NonNullable), Mutable),
Field(Type(HeapType::ext, NonNullable), Mutable),
Field(Type(HeapType::none, NonNullable), Mutable),
Field(Type(HeapType::nofunc, NonNullable), Mutable),
Field(Type(HeapType::noext, NonNullable), Mutable),
}};

struct FieldInfo {
uint8_t index = 0;
Expand Down Expand Up @@ -316,32 +333,6 @@ void GroupClassInfo::permute(RecGroupInfo& info) {
}
}

std::array<Field, BrandTypeIterator::optionCount>
BrandTypeIterator::fieldOptions = {{}};

void BrandTypeIterator::initFieldOptions() {
BrandTypeIterator::fieldOptions = {{
Field(Field::i8, Mutable),
Field(Field::i16, Mutable),
Field(Type::i32, Mutable),
Field(Type::i64, Mutable),
Field(Type::f32, Mutable),
Field(Type::f64, Mutable),
Field(Type(HeapType::any, Nullable), Mutable),
Field(Type(HeapType::func, Nullable), Mutable),
Field(Type(HeapType::ext, Nullable), Mutable),
Field(Type(HeapType::none, Nullable), Mutable),
Field(Type(HeapType::nofunc, Nullable), Mutable),
Field(Type(HeapType::noext, Nullable), Mutable),
Field(Type(HeapType::any, NonNullable), Mutable),
Field(Type(HeapType::func, NonNullable), Mutable),
Field(Type(HeapType::ext, NonNullable), Mutable),
Field(Type(HeapType::none, NonNullable), Mutable),
Field(Type(HeapType::nofunc, NonNullable), Mutable),
Field(Type(HeapType::noext, NonNullable), Mutable),
}};
}

struct MinimizeRecGroups : Pass {
// The types we are optimizing and their indices in this list.
std::vector<HeapType> types;
Expand Down Expand Up @@ -387,8 +378,6 @@ struct MinimizeRecGroups : Pass {
return;
}

initBrandOptions();

auto typeInfo = ModuleUtils::collectHeapTypeInfo(
*module,
ModuleUtils::TypeInclusion::AllTypes,
Expand Down Expand Up @@ -445,15 +434,6 @@ struct MinimizeRecGroups : Pass {
rewriteTypes(*module);
}

void initBrandOptions() {
// Initialize the field options for brand types lazily here to avoid
// depending on global constructor ordering.
[[maybe_unused]] static bool fieldsInitialized = []() {
BrandTypeIterator::initFieldOptions();
return true;
}();
}

void updateShapes() {
while (!shapesToUpdate.empty()) {
auto index = shapesToUpdate.back();
Expand Down
13 changes: 8 additions & 5 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Type {
constexpr Type(BasicType id) : id(id) {}

// But converting raw TypeID is more dangerous, so make it explicit
explicit Type(TypeID id) : id(id) {}
explicit constexpr Type(TypeID id) : id(id) {}

// Construct tuple from a list of single types
Type(std::initializer_list<Type>);
Expand All @@ -335,7 +335,9 @@ class Type {

// Construct from a heap type description. Also covers construction from
// Signature, Struct or Array via implicit conversion to HeapType.
Type(HeapType heapType, Nullability nullable, Exactness exact = Inexact)
constexpr Type(HeapType heapType,
Nullability nullable,
Exactness exact = Inexact)
: Type(heapType.getID() | (nullable == Nullable ? NullMask : 0) |
(exact == Exact ? ExactMask : 0)) {
assert(!(heapType.getID() &
Expand Down Expand Up @@ -659,10 +661,11 @@ struct Field {
Mutability mutable_;

// Arbitrary defaults for convenience.
Field() : type(Type::i32), packedType(not_packed), mutable_(Mutable) {}
Field(Type type, Mutability mutable_)
constexpr Field()
: type(Type::i32), packedType(not_packed), mutable_(Mutable) {}
constexpr Field(Type type, Mutability mutable_)
: type(type), packedType(not_packed), mutable_(mutable_) {}
Field(PackedType packedType, Mutability mutable_)
constexpr Field(PackedType packedType, Mutability mutable_)
: type(Type::i32), packedType(packedType), mutable_(mutable_) {}

constexpr bool isPacked() const {
Expand Down
Loading