summaryrefslogtreecommitdiff
path: root/src/passes/Memory64Lowering.cpp
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2020-10-30 09:41:25 -0700
committerGitHub <noreply@github.com>2020-10-30 09:41:25 -0700
commit253c6a50130a16a1a1aae80bba4885fe99d3f625 (patch)
treed32303853fcf84fd460e4f71d6a96e37fe155463 /src/passes/Memory64Lowering.cpp
parent5fc27e20479edfef0674c89e9bb7888ee25cb054 (diff)
downloadbinaryen-253c6a50130a16a1a1aae80bba4885fe99d3f625.tar.gz
binaryen-253c6a50130a16a1a1aae80bba4885fe99d3f625.tar.bz2
binaryen-253c6a50130a16a1a1aae80bba4885fe99d3f625.zip
[Memory64] (#3302)
Fixed bug in memory64-lowering pass for memory.size/grow
Diffstat (limited to 'src/passes/Memory64Lowering.cpp')
-rw-r--r--src/passes/Memory64Lowering.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp
index 7905c944f..cee174b63 100644
--- a/src/passes/Memory64Lowering.cpp
+++ b/src/passes/Memory64Lowering.cpp
@@ -35,7 +35,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
}
}
- void WrapAddress64(Expression*& ptr) {
+ void wrapAddress64(Expression*& ptr) {
if (ptr->type == Type::unreachable) {
return;
}
@@ -46,34 +46,48 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
ptr = builder.makeUnary(UnaryOp::WrapInt64, ptr);
}
- void visitLoad(Load* curr) { WrapAddress64(curr->ptr); }
+ void extendAddress64(Expression*& ptr) {
+ if (ptr->type == Type::unreachable) {
+ return;
+ }
+ auto& module = *getModule();
+ assert(module.memory.is64());
+ assert(ptr->type == Type::i64);
+ ptr->type = Type::i32;
+ Builder builder(module);
+ ptr = builder.makeUnary(UnaryOp::ExtendUInt32, ptr);
+ }
+
+ void visitLoad(Load* curr) { wrapAddress64(curr->ptr); }
- void visitStore(Store* curr) { WrapAddress64(curr->ptr); }
+ void visitStore(Store* curr) { wrapAddress64(curr->ptr); }
void visitMemorySize(MemorySize* curr) {
auto size = static_cast<Expression*>(curr);
- WrapAddress64(size);
+ extendAddress64(size);
+ curr->ptrType = Type::i32;
replaceCurrent(size);
}
void visitMemoryGrow(MemoryGrow* curr) {
- WrapAddress64(curr->delta);
+ wrapAddress64(curr->delta);
auto size = static_cast<Expression*>(curr);
- WrapAddress64(size);
+ extendAddress64(size);
+ curr->ptrType = Type::i32;
replaceCurrent(size);
}
- void visitMemoryInit(MemoryInit* curr) { WrapAddress64(curr->dest); }
+ void visitMemoryInit(MemoryInit* curr) { wrapAddress64(curr->dest); }
void visitMemoryFill(MemoryFill* curr) {
- WrapAddress64(curr->dest);
- WrapAddress64(curr->size);
+ wrapAddress64(curr->dest);
+ wrapAddress64(curr->size);
}
void visitMemoryCopy(MemoryCopy* curr) {
- WrapAddress64(curr->dest);
- WrapAddress64(curr->source);
- WrapAddress64(curr->size);
+ wrapAddress64(curr->dest);
+ wrapAddress64(curr->source);
+ wrapAddress64(curr->size);
}
void visitMemory(Memory* memory) {