Skip to content

Commit 669bc06

Browse files
authored
[Memory64Lowering/Table64Lowering] Avoid dependency in visitation order. NFC (#6600)
Followup to #6599.
1 parent fab6649 commit 669bc06

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/passes/Memory64Lowering.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
116116
wrapAddress64(curr->ptr, curr->memory);
117117
}
118118

119-
void visitMemory(Memory* memory) {
120-
// This is visited last.
121-
seenMemory = true;
122-
if (memory->is64()) {
123-
memory->indexType = Type::i32;
124-
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
125-
memory->max = Memory::kMaxSize32;
126-
}
127-
}
128-
}
129-
130119
void visitDataSegment(DataSegment* segment) {
131-
// We assume that memories are visited after segments, so assert that here.
132-
assert(!seenMemory);
133120
auto& module = *getModule();
134121

135122
// passive segments don't have any offset to adjust
@@ -172,10 +159,19 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
172159
return;
173160
}
174161
super::run(module);
162+
// Don't modify the memories themselves until after the traversal since we
163+
// that would require memories to be the last thing that get visited, and
164+
// we don't want to depend on that specific ordering.
165+
for (auto& memory : module->memories) {
166+
if (memory->is64()) {
167+
memory->indexType = Type::i32;
168+
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
169+
memory->max = Memory::kMaxSize32;
170+
}
171+
}
172+
}
175173
module->features.disable(FeatureSet::Memory64);
176174
}
177-
178-
bool seenMemory = false;
179175
};
180176

181177
Pass* createMemory64LoweringPass() { return new Memory64Lowering(); }

src/passes/Table64Lowering.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,7 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
9595
wrapAddress64(curr->target, curr->table);
9696
}
9797

98-
void visitTable(Table* table) {
99-
// This is visited last.
100-
seenTable = true;
101-
if (table->is64()) {
102-
table->indexType = Type::i32;
103-
}
104-
}
105-
10698
void visitElementSegment(ElementSegment* segment) {
107-
// We assume that tables are visited after segments, so assert that here.
108-
assert(!seenTable);
10999
auto& module = *getModule();
110100

111101
// Passive segments don't have any offset to update.
@@ -143,7 +133,17 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
143133
}
144134
}
145135

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

149149
Pass* createTable64LoweringPass() { return new Table64Lowering(); }

0 commit comments

Comments
 (0)