diff options
-rw-r--r-- | src/passes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/passes/DeAlign.cpp | 41 | ||||
-rw-r--r-- | src/passes/pass.cpp | 3 | ||||
-rw-r--r-- | src/passes/passes.h | 1 | ||||
-rw-r--r-- | test/passes/dealign.txt | 33 | ||||
-rw-r--r-- | test/passes/dealign.wast | 11 |
6 files changed, 90 insertions, 0 deletions
diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index 8a51e3ac8..ecf9d6a59 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -18,6 +18,7 @@ set(passes_SOURCES DataFlowOpts.cpp DeadArgumentElimination.cpp DeadCodeElimination.cpp + DeAlign.cpp DeNaN.cpp Directize.cpp DuplicateImportElimination.cpp diff --git a/src/passes/DeAlign.cpp b/src/passes/DeAlign.cpp new file mode 100644 index 000000000..795b6a228 --- /dev/null +++ b/src/passes/DeAlign.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2020 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Forces all loads and stores to be completely unaligned, that is, to have +// alignment 1. +// + +#include "pass.h" +#include "wasm.h" + +namespace wasm { + +struct DeAlign : public WalkerPass<PostWalker<DeAlign>> { + bool isFunctionParallel() override { return true; } + + Pass* create() override { return new DeAlign(); } + + void visitLoad(Load* curr) { curr->align = 1; } + + void visitStore(Store* curr) { curr->align = 1; } + + void visitSIMDLoad(SIMDLoad* curr) { curr->align = 1; } +}; + +Pass* createDeAlignPass() { return new DeAlign(); } + +} // namespace wasm diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 14bf5d185..6dcc58b50 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -104,6 +104,9 @@ void PassRegistry::registerPasses() { createConstHoistingPass); registerPass( "dce", "removes unreachable code", createDeadCodeEliminationPass); + registerPass("dealign", + "forces all loads and stores to have alignment 1", + createDeAlignPass); registerPass("denan", "instrument the wasm to convert NaNs into 0 at runtime", createDeNaNPass); diff --git a/src/passes/passes.h b/src/passes/passes.h index ae4fa1e87..a22e979af 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -35,6 +35,7 @@ Pass* createDAEOptimizingPass(); Pass* createDataFlowOptsPass(); Pass* createDeadCodeEliminationPass(); Pass* createDeNaNPass(); +Pass* createDeAlignPass(); Pass* createDirectizePass(); Pass* createDWARFDumpPass(); Pass* createDuplicateImportEliminationPass(); diff --git a/test/passes/dealign.txt b/test/passes/dealign.txt new file mode 100644 index 000000000..379241da9 --- /dev/null +++ b/test/passes/dealign.txt @@ -0,0 +1,33 @@ +(module + (type $none_=>_none (func)) + (memory $0 1 1) + (func $test + (drop + (i32.load align=1 + (i32.const 4) + ) + ) + (drop + (i32.load align=1 + (i32.const 8) + ) + ) + (drop + (i32.load align=1 + (i32.const 12) + ) + ) + (i32.store align=1 + (i32.const 16) + (i32.const 28) + ) + (i32.store align=1 + (i32.const 20) + (i32.const 32) + ) + (i32.store align=1 + (i32.const 24) + (i32.const 36) + ) + ) +) diff --git a/test/passes/dealign.wast b/test/passes/dealign.wast new file mode 100644 index 000000000..c7116daca --- /dev/null +++ b/test/passes/dealign.wast @@ -0,0 +1,11 @@ +(module + (memory $0 1 1) + (func $test + (drop (i32.load (i32.const 4))) + (drop (i32.load align=1 (i32.const 8))) + (drop (i32.load align=2 (i32.const 12))) + (i32.store (i32.const 16) (i32.const 28)) + (i32.store align=1 (i32.const 20) (i32.const 32)) + (i32.store align=2 (i32.const 24) (i32.const 36)) + ) +) |