Skip to content

Commit

Permalink
[Memory64Lowering/Table64Lowering] Avoid dependency in visitation ord…
Browse files Browse the repository at this point in the history
…er. NFC (#6600)

Followup to #6599.
  • Loading branch information
sbc100 committed May 16, 2024
1 parent fab6649 commit 669bc06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
26 changes: 11 additions & 15 deletions src/passes/Memory64Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
wrapAddress64(curr->ptr, curr->memory);
}

void visitMemory(Memory* memory) {
// This is visited last.
seenMemory = true;
if (memory->is64()) {
memory->indexType = Type::i32;
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
memory->max = Memory::kMaxSize32;
}
}
}

void visitDataSegment(DataSegment* segment) {
// 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
Expand Down Expand Up @@ -172,10 +159,19 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
return;
}
super::run(module);
// Don't modify the memories themselves until after the traversal since we
// that would require memories to be the last thing that get visited, and
// we don't want to depend on that specific ordering.
for (auto& memory : module->memories) {
if (memory->is64()) {
memory->indexType = Type::i32;
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
memory->max = Memory::kMaxSize32;
}
}
}
module->features.disable(FeatureSet::Memory64);
}

bool seenMemory = false;
};

Pass* createMemory64LoweringPass() { return new Memory64Lowering(); }
Expand Down
22 changes: 11 additions & 11 deletions src/passes/Table64Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,7 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
wrapAddress64(curr->target, curr->table);
}

void visitTable(Table* table) {
// This is visited last.
seenTable = true;
if (table->is64()) {
table->indexType = Type::i32;
}
}

void visitElementSegment(ElementSegment* segment) {
// 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.
Expand Down Expand Up @@ -143,7 +133,17 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
}
}

bool seenTable = false;
void run(Module* module) override {
super::run(module);
// Don't modify the tables themselves until after the traversal since we
// that would require tables to be the last thing that get visited, and
// we don't want to depend on that specific ordering.
for (auto& table : module->tables) {
if (table->is64()) {
table->indexType = Type::i32;
}
}
}
};

Pass* createTable64LoweringPass() { return new Table64Lowering(); }
Expand Down

0 comments on commit 669bc06

Please sign in to comment.