summaryrefslogtreecommitdiff
path: root/src/passes/GlobalStructInference.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/GlobalStructInference.cpp')
-rw-r--r--src/passes/GlobalStructInference.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/passes/GlobalStructInference.cpp b/src/passes/GlobalStructInference.cpp
index 6a917596f..ceee8b02d 100644
--- a/src/passes/GlobalStructInference.cpp
+++ b/src/passes/GlobalStructInference.cpp
@@ -52,6 +52,7 @@
#include "ir/module-utils.h"
#include "ir/properties.h"
#include "ir/subtypes.h"
+#include "ir/utils.h"
#include "pass.h"
#include "wasm-builder.h"
#include "wasm.h"
@@ -221,6 +222,8 @@ struct GlobalStructInference : public Pass {
FunctionOptimizer(GlobalStructInference& parent) : parent(parent) {}
+ bool refinalize = false;
+
void visitStructGet(StructGet* curr) {
auto type = curr->ref->type;
if (type == Type::unreachable) {
@@ -262,9 +265,16 @@ struct GlobalStructInference : public Pass {
// will unlock those other optimizations. Note we must trap if the ref
// is null, so add RefAsNonNull here.
auto global = globals[0];
+ auto globalType = wasm.getGlobal(global)->type;
+ if (globalType != curr->ref->type) {
+ // The struct.get will now read from something of the type of the
+ // global, which is different, so the field being read might be
+ // refined, which could change the struct.get's type.
+ refinalize = true;
+ }
curr->ref = builder.makeSequence(
builder.makeDrop(builder.makeRefAs(RefAsNonNull, curr->ref)),
- builder.makeGlobalGet(global, wasm.getGlobal(globals[0])->type));
+ builder.makeGlobalGet(global, globalType));
return;
}
@@ -367,6 +377,12 @@ struct GlobalStructInference : public Pass {
builder.makeConstantExpression(values[1])));
}
+ void visitFunction(Function* func) {
+ if (refinalize) {
+ ReFinalize().walkFunctionInModule(func, getModule());
+ }
+ }
+
private:
GlobalStructInference& parent;
};