summaryrefslogtreecommitdiff
path: root/src/passes/Untee.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-06-14 22:05:55 -0700
committerGitHub <noreply@github.com>2017-06-14 22:05:55 -0700
commit7179572c7fe842df688bcf6b2a1c08e7623ab284 (patch)
tree388789d98340e7511a71102236961b23b4c8ef18 /src/passes/Untee.cpp
parent8aa91ecb38cc7beaec1f56982e25bb2833cbab39 (diff)
downloadbinaryen-7179572c7fe842df688bcf6b2a1c08e7623ab284.tar.gz
binaryen-7179572c7fe842df688bcf6b2a1c08e7623ab284.tar.bz2
binaryen-7179572c7fe842df688bcf6b2a1c08e7623ab284.zip
Untee pass (#1053)
Diffstat (limited to 'src/passes/Untee.cpp')
-rw-r--r--src/passes/Untee.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/passes/Untee.cpp b/src/passes/Untee.cpp
new file mode 100644
index 000000000..b61875243
--- /dev/null
+++ b/src/passes/Untee.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017 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.
+ */
+
+//
+// Removes tee_locals, replacing them with gets and sets.
+//
+// This makes the code "flatter", with less nested side
+// effects. That can make some passes, like CodePushing,
+// more effective.
+//
+
+#include <wasm.h>
+#include <pass.h>
+#include <wasm-builder.h>
+
+namespace wasm {
+
+struct Untee : public WalkerPass<PostWalker<Untee>> {
+ bool isFunctionParallel() override { return true; }
+
+ Pass* create() override { return new Untee; }
+
+ void visitSetLocal(SetLocal *curr) {
+ if (curr->isTee()) {
+ if (curr->value->type == unreachable) {
+ // we don't reach the tee, just remove it
+ replaceCurrent(curr->value);
+ } else {
+ // a normal tee. replace with set and get
+ Builder builder(*getModule());
+ replaceCurrent(
+ builder.makeSequence(
+ curr,
+ builder.makeGetLocal(curr->index, curr->value->type)
+ )
+ );
+ curr->setTee(false);
+ }
+ }
+ }
+};
+
+Pass *createUnteePass() {
+ return new Untee();
+}
+
+} // namespace wasm
+