diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-01-14 11:50:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-14 11:50:52 -0800 |
commit | 8e8284e6464d524bd9091f21a62982ed54df0093 (patch) | |
tree | 13b88033d4e5d2f8d53289807efdd6b88055e0be /src/wasm/wasm-binary.cpp | |
parent | 80329023c30ca108b0a8ce1b3939f5e9a96250bb (diff) | |
download | binaryen-8e8284e6464d524bd9091f21a62982ed54df0093.tar.gz binaryen-8e8284e6464d524bd9091f21a62982ed54df0093.tar.bz2 binaryen-8e8284e6464d524bd9091f21a62982ed54df0093.zip |
Refactor ModuleUtils::collectHeapTypes (#4455)
Update the API to make both the type indices and optimized sorting optional.
It will become more important to avoid unnecessary sorting once isorecursive
types have been implemented because they will make the sorting more complicated.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5ebc4d864..36cb0fd1a 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -34,7 +34,7 @@ namespace wasm { void WasmBinaryWriter::prepare() { // Collect function types and their frequencies. Collect information in each // function in parallel, then merge. - ModuleUtils::collectHeapTypes(*wasm, types, typeIndices); + indexedTypes = ModuleUtils::getOptimizedIndexedHeapTypes(*wasm); importInfo = wasm::make_unique<ImportInfo>(*wasm); } @@ -216,14 +216,14 @@ void WasmBinaryWriter::writeMemory() { } void WasmBinaryWriter::writeTypes() { - if (types.size() == 0) { + if (indexedTypes.types.size() == 0) { return; } BYN_TRACE("== writeTypes\n"); auto start = startSection(BinaryConsts::Section::Type); - o << U32LEB(types.size()); - for (Index i = 0; i < types.size(); ++i) { - auto type = types[i]; + o << U32LEB(indexedTypes.types.size()); + for (Index i = 0; i < indexedTypes.types.size(); ++i) { + auto type = indexedTypes.types[i]; bool nominal = type.isNominal() || getTypeSystem() == TypeSystem::Nominal; BYN_TRACE("write " << type << std::endl); if (type.isSignature()) { @@ -539,9 +539,9 @@ uint32_t WasmBinaryWriter::getTagIndex(Name name) const { } uint32_t WasmBinaryWriter::getTypeIndex(HeapType type) const { - auto it = typeIndices.find(type); + auto it = indexedTypes.indices.find(type); #ifndef NDEBUG - if (it == typeIndices.end()) { + if (it == indexedTypes.indices.end()) { std::cout << "Missing type: " << type << '\n'; assert(0); } @@ -774,7 +774,7 @@ void WasmBinaryWriter::writeNames() { // type names { std::vector<HeapType> namedTypes; - for (auto& [type, _] : typeIndices) { + for (auto& [type, _] : indexedTypes.indices) { if (wasm->typeNames.count(type) && wasm->typeNames[type].name.is()) { namedTypes.push_back(type); } @@ -784,7 +784,7 @@ void WasmBinaryWriter::writeNames() { startSubsection(BinaryConsts::UserSections::Subsection::NameType); o << U32LEB(namedTypes.size()); for (auto type : namedTypes) { - o << U32LEB(typeIndices[type]); + o << U32LEB(indexedTypes.indices[type]); writeEscapedName(wasm->typeNames[type].name.str); } finishSubsection(substart); @@ -909,7 +909,7 @@ void WasmBinaryWriter::writeNames() { // GC field names if (wasm->features.hasGC()) { std::vector<HeapType> relevantTypes; - for (auto& type : types) { + for (auto& type : indexedTypes.types) { if (type.isStruct() && wasm->typeNames.count(type) && !wasm->typeNames[type].fieldNames.empty()) { relevantTypes.push_back(type); @@ -921,7 +921,7 @@ void WasmBinaryWriter::writeNames() { o << U32LEB(relevantTypes.size()); for (Index i = 0; i < relevantTypes.size(); i++) { auto type = relevantTypes[i]; - o << U32LEB(typeIndices[type]); + o << U32LEB(indexedTypes.indices[type]); std::unordered_map<Index, Name>& fieldNames = wasm->typeNames.at(type).fieldNames; o << U32LEB(fieldNames.size()); |