Skip to content

Commit f82e708

Browse files
authored
Loosen conditions on MemoryPacking (#2205)
Allow MemoryPacking to run when there are no passive segments, even if bulk memory is enabled.
1 parent a5547a5 commit f82e708

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/passes/MemoryPacking.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ struct MemoryPacking : public Pass {
2828
bool modifiesBinaryenIR() override { return false; }
2929

3030
void run(PassRunner* runner, Module* module) override {
31-
// Conservatively refuse to change segments if bulk memory is enabled to
32-
// avoid invalidating segment indices or segment contents referenced from
31+
if (!module->memory.exists) {
32+
return;
33+
}
34+
35+
// Conservatively refuse to change segments if any are passive to avoid
36+
// invalidating segment indices or segment contents referenced from
3337
// memory.init instructions.
3438
// TODO: optimize in the presence of memory.init instructions
35-
if (!module->memory.exists || module->features.hasBulkMemory()) {
36-
return;
39+
if (module->features.hasBulkMemory()) {
40+
for (auto segment : module->memory.segments) {
41+
if (segment.isPassive) {
42+
return;
43+
}
44+
}
3745
}
3846

3947
std::vector<Memory::Segment> packed;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)