summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-06-17 16:16:50 -0700
committerGitHub <noreply@github.com>2024-06-17 16:16:50 -0700
commit0f9f2dc21a913164c5a8681b93b7db4d383a8c47 (patch)
treec2cc4cebe603a07b3cdad5b0233a2967264fb44b /src
parentb377b6f175cf5904d8e65eb8f2184c7379f97297 (diff)
downloadbinaryen-0f9f2dc21a913164c5a8681b93b7db4d383a8c47.tar.gz
binaryen-0f9f2dc21a913164c5a8681b93b7db4d383a8c47.tar.bz2
binaryen-0f9f2dc21a913164c5a8681b93b7db4d383a8c47.zip
GlobalStructInference: Optimize globals too (#6674)
This is achieved by simply replacing the Literal with PossibleConstantValues, which supports both Literals and Globals.
Diffstat (limited to 'src')
-rw-r--r--src/passes/GlobalStructInference.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/passes/GlobalStructInference.cpp b/src/passes/GlobalStructInference.cpp
index 9fc906971..c0b92e3bb 100644
--- a/src/passes/GlobalStructInference.cpp
+++ b/src/passes/GlobalStructInference.cpp
@@ -50,7 +50,7 @@
#include "ir/find_all.h"
#include "ir/module-utils.h"
-#include "ir/properties.h"
+#include "ir/possible-constant.h"
#include "ir/subtypes.h"
#include "ir/utils.h"
#include "pass.h"
@@ -300,7 +300,7 @@ struct GlobalStructInference : public Pass {
// Find the constant values and which globals correspond to them.
// TODO: SmallVectors?
- std::vector<Literal> values;
+ std::vector<PossibleConstantValues> values;
std::vector<std::vector<Name>> globalsForValue;
// Check if the relevant fields contain constants.
@@ -308,16 +308,15 @@ struct GlobalStructInference : public Pass {
for (Index i = 0; i < globals.size(); i++) {
Name global = globals[i];
auto* structNew = wasm.getGlobal(global)->init->cast<StructNew>();
- Literal value;
+ PossibleConstantValues value;
if (structNew->isWithDefault()) {
- value = Literal::makeZero(fieldType);
+ value.note(Literal::makeZero(fieldType));
} else {
- auto* init = structNew->operands[fieldIndex];
- if (!Properties::isConstantExpression(init)) {
- // Non-constant; give up entirely.
+ value.note(structNew->operands[fieldIndex], wasm);
+ if (!value.isConstant()) {
+ // Give up entirely.
return;
}
- value = Properties::getLiteral(init);
}
// Process the current value, comparing it against the previous.
@@ -346,7 +345,7 @@ struct GlobalStructInference : public Pass {
// otherwise return the value.
replaceCurrent(builder.makeSequence(
builder.makeDrop(builder.makeRefAs(RefAsNonNull, curr->ref)),
- builder.makeConstantExpression(values[0])));
+ values[0].makeExpression(wasm)));
return;
}
assert(values.size() == 2);
@@ -373,8 +372,8 @@ struct GlobalStructInference : public Pass {
builder.makeRefEq(builder.makeRefAs(RefAsNonNull, curr->ref),
builder.makeGlobalGet(
checkGlobal, wasm.getGlobal(checkGlobal)->type)),
- builder.makeConstantExpression(values[0]),
- builder.makeConstantExpression(values[1])));
+ values[0].makeExpression(wasm),
+ values[1].makeExpression(wasm)));
}
void visitFunction(Function* func) {