summaryrefslogtreecommitdiff
path: root/src/passes/PostEmscripten.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/PostEmscripten.cpp')
-rw-r--r--src/passes/PostEmscripten.cpp60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp
index 72c0d8808..7e2bacf25 100644
--- a/src/passes/PostEmscripten.cpp
+++ b/src/passes/PostEmscripten.cpp
@@ -32,66 +32,6 @@ struct PostEmscripten : public WalkerPass<PostWalker<PostEmscripten>> {
Pass* create() override { return new PostEmscripten; }
- // When we have a Load from a local value (typically a GetLocal) plus a constant offset,
- // we may be able to fold it in.
- // The semantics of the Add are to wrap, while wasm offset semantics purposefully do
- // not wrap. So this is not always safe to do. For example, a load may depend on
- // wrapping via
- // (2^32 - 10) + 100 => wrap and load from address 90
- // Without wrapping, we get something too large, and an error. *However*, for
- // asm2wasm output coming from Emscripten, we allocate the lowest 1024 for mapped
- // globals. Mapped globals are simple types (i32, float or double), always
- // accessed directly by a single constant. Therefore if we see (..) + K where
- // K is less then 1024, then if it wraps, it wraps into [0, 1024) which is at best
- // a mapped global, but it can't be because they are accessed directly (at worst,
- // it's 0 or an unused section of memory that was reserved for mapped globlas).
- // Thus it is ok to optimize such small constants into Load offsets.
-
- #define SAFE_MAX 1024
-
- void optimizeMemoryAccess(Expression*& ptr, Address& offset) {
- while (1) {
- auto* add = ptr->dynCast<Binary>();
- if (!add) break;
- if (add->op != AddInt32) break;
- auto* left = add->left->dynCast<Const>();
- auto* right = add->right->dynCast<Const>();
- // note: in optimized code, we shouldn't see an add of two constants, so don't worry about that much
- // (precompute would optimize that)
- if (left) {
- auto value = left->value.geti32();
- if (value >= 0 && value < SAFE_MAX) {
- offset = offset + value;
- ptr = add->right;
- continue;
- }
- }
- if (right) {
- auto value = right->value.geti32();
- if (value >= 0 && value < SAFE_MAX) {
- offset = offset + value;
- ptr = add->left;
- continue;
- }
- }
- break;
- }
- // finally ptr may be a const, but it isn't worth folding that in (we still have a const); in fact,
- // it's better to do the opposite for gzip purposes as well as for readability.
- auto* last = ptr->dynCast<Const>();
- if (last) {
- last->value = Literal(int32_t(last->value.geti32() + offset));
- offset = 0;
- }
- }
-
- void visitLoad(Load* curr) {
- optimizeMemoryAccess(curr->ptr, curr->offset);
- }
- void visitStore(Store* curr) {
- optimizeMemoryAccess(curr->ptr, curr->offset);
- }
-
void visitCall(Call* curr) {
// special asm.js imports can be optimized
auto* func = getModule()->getFunction(curr->target);