summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Memory64Lowering.cpp12
-rw-r--r--src/passes/Table64Lowering.cpp12
-rw-r--r--src/wasm-traversal.h10
3 files changed, 23 insertions, 11 deletions
diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp
index 0a58fed13..39ce1869b 100644
--- a/src/passes/Memory64Lowering.cpp
+++ b/src/passes/Memory64Lowering.cpp
@@ -118,6 +118,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
void visitMemory(Memory* memory) {
// This is visited last.
+ seenMemory = true;
if (memory->is64()) {
memory->indexType = Type::i32;
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
@@ -127,8 +128,12 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
}
void visitDataSegment(DataSegment* segment) {
- if (segment->isPassive) {
- // passive segments don't have any offset to adjust
+ // We assume that memories are visited after segments, so assert that here.
+ assert(!seenMemory);
+ auto& module = *getModule();
+
+ // passive segments don't have any offset to adjust
+ if (segment->isPassive || !module.getMemory(segment->memory)->is64()) {
return;
}
@@ -136,7 +141,6 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
c->value = Literal(static_cast<uint32_t>(c->value.geti64()));
c->type = Type::i32;
} else if (auto* get = segment->offset->dynCast<GlobalGet>()) {
- auto& module = *getModule();
auto* g = module.getGlobal(get->name);
if (g->imported() && g->base == MEMORY_BASE) {
ImportInfo info(module);
@@ -170,6 +174,8 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
super::run(module);
module->features.disable(FeatureSet::Memory64);
}
+
+ bool seenMemory = false;
};
Pass* createMemory64LoweringPass() { return new Memory64Lowering(); }
diff --git a/src/passes/Table64Lowering.cpp b/src/passes/Table64Lowering.cpp
index 3c4086a01..b24bea167 100644
--- a/src/passes/Table64Lowering.cpp
+++ b/src/passes/Table64Lowering.cpp
@@ -97,14 +97,19 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
void visitTable(Table* table) {
// This is visited last.
+ seenTable = true;
if (table->is64()) {
table->indexType = Type::i32;
}
}
void visitElementSegment(ElementSegment* segment) {
- if (segment->table.isNull()) {
- // Passive segments don't have any offset to update.
+ // We assume that tables are visited after segments, so assert that here.
+ assert(!seenTable);
+ auto& module = *getModule();
+
+ // Passive segments don't have any offset to update.
+ if (segment->table.isNull() || !module.getTable(segment->table)->is64()) {
return;
}
@@ -112,7 +117,6 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
c->value = Literal(static_cast<uint32_t>(c->value.geti64()));
c->type = Type::i32;
} else if (auto* get = segment->offset->dynCast<GlobalGet>()) {
- auto& module = *getModule();
auto* g = module.getGlobal(get->name);
if (g->imported() && g->base == TABLE_BASE) {
ImportInfo info(module);
@@ -138,6 +142,8 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
WASM_UNREACHABLE("unexpected elem offset");
}
}
+
+ bool seenTable = false;
};
Pass* createTable64LoweringPass() { return new Table64Lowering(); }
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h
index c8078164b..8e99749b6 100644
--- a/src/wasm-traversal.h
+++ b/src/wasm-traversal.h
@@ -256,18 +256,18 @@ struct Walker : public VisitorType {
self->walkTag(curr.get());
}
}
- for (auto& curr : module->tables) {
- self->walkTable(curr.get());
- }
for (auto& curr : module->elementSegments) {
self->walkElementSegment(curr.get());
}
- for (auto& curr : module->memories) {
- self->walkMemory(curr.get());
+ for (auto& curr : module->tables) {
+ self->walkTable(curr.get());
}
for (auto& curr : module->dataSegments) {
self->walkDataSegment(curr.get());
}
+ for (auto& curr : module->memories) {
+ self->walkMemory(curr.get());
+ }
}
// Walks module-level code, that is, code that is not in functions.