summaryrefslogtreecommitdiff
path: root/src/passes/DeAlign.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-07-31 12:35:01 -0700
committerGitHub <noreply@github.com>2020-07-31 12:35:01 -0700
commitd09c607ff2f2c264546b7d4ea3593ae75a037750 (patch)
tree28106c525a5a6174c70ecb5527eabc171e9be039 /src/passes/DeAlign.cpp
parent26060b2cfe835e208d29e12d70a1a8eee70b3c14 (diff)
downloadbinaryen-d09c607ff2f2c264546b7d4ea3593ae75a037750.tar.gz
binaryen-d09c607ff2f2c264546b7d4ea3593ae75a037750.tar.bz2
binaryen-d09c607ff2f2c264546b7d4ea3593ae75a037750.zip
New Dealign pass: reduce load/store alignment to 1 (#3010)
Pretty trivial, but will be useful in wasm2js testing, where we can't assume an incorrectly-aligned load/store will still work, so we'll need to be pessimistic about alignment there.
Diffstat (limited to 'src/passes/DeAlign.cpp')
-rw-r--r--src/passes/DeAlign.cpp41
1 files changed, 41 insertions, 0 deletions
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