summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2024-05-16 14:00:06 -0700
committerGitHub <noreply@github.com>2024-05-16 14:00:06 -0700
commit669bc06d0566041bfdbae97f87e60130945b557f (patch)
tree619d50553509158bbd41e4e0f39dab0792d25ab8 /src
parentfab6649590b086f990286408d8715373be3eda66 (diff)
downloadbinaryen-669bc06d0566041bfdbae97f87e60130945b557f.tar.gz
binaryen-669bc06d0566041bfdbae97f87e60130945b557f.tar.bz2
binaryen-669bc06d0566041bfdbae97f87e60130945b557f.zip
[Memory64Lowering/Table64Lowering] Avoid dependency in visitation order. NFC (#6600)
Followup to #6599.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Memory64Lowering.cpp26
-rw-r--r--src/passes/Table64Lowering.cpp22
2 files changed, 22 insertions, 26 deletions
diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp
index 39ce1869b..c1ce3dd91 100644
--- a/src/passes/Memory64Lowering.cpp
+++ b/src/passes/Memory64Lowering.cpp
@@ -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
@@ -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(); }
diff --git a/src/passes/Table64Lowering.cpp b/src/passes/Table64Lowering.cpp
index b24bea167..65c9a2a63 100644
--- a/src/passes/Table64Lowering.cpp
+++ b/src/passes/Table64Lowering.cpp
@@ -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.
@@ -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(); }