summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-10-11 10:13:32 -0700
committerGitHub <noreply@github.com>2017-10-11 10:13:32 -0700
commita8da89653981bb37565981afc69104f918fea64a (patch)
treede5fe7d39b8f73390c5034ff7a2036f25efd5c06 /src
parentf0d858b6c2793f7bae00e4c5dc2d0f38fc1e30f8 (diff)
downloadbinaryen-a8da89653981bb37565981afc69104f918fea64a.tar.gz
binaryen-a8da89653981bb37565981afc69104f918fea64a.tar.bz2
binaryen-a8da89653981bb37565981afc69104f918fea64a.zip
fix ssaify bug where we failed to update the location of values as we moved them around, causing us to zero out the wrong thing in another place and ensuing hilarity (#1212)
Diffstat (limited to 'src')
-rw-r--r--src/ast/LocalGraph.cpp13
-rw-r--r--src/passes/SSAify.cpp18
2 files changed, 25 insertions, 6 deletions
diff --git a/src/ast/LocalGraph.cpp b/src/ast/LocalGraph.cpp
index c997eff1b..0d36fec84 100644
--- a/src/ast/LocalGraph.cpp
+++ b/src/ast/LocalGraph.cpp
@@ -17,6 +17,7 @@
#include <iterator>
#include <wasm-builder.h>
+#include <wasm-printing.h>
#include <ast/find_all.h>
#include <ast/local-graph.h>
@@ -24,6 +25,18 @@ namespace wasm {
LocalGraph::LocalGraph(Function* func, Module* module) {
walkFunctionInModule(func, module);
+
+#ifdef LOCAL_GRAPH_DEBUG
+ std::cout << "LocalGraph::dump\n";
+ for (auto& pair : getSetses) {
+ auto* get = pair.first;
+ auto& sets = pair.second;
+ std::cout << "GET\n" << get << " is influenced by\n";
+ for (auto* set : sets) {
+ std::cout << set << '\n';
+ }
+ }
+#endif
}
void LocalGraph::computeInfluences() {
diff --git a/src/passes/SSAify.cpp b/src/passes/SSAify.cpp
index a71a75308..aafea8a97 100644
--- a/src/passes/SSAify.cpp
+++ b/src/passes/SSAify.cpp
@@ -60,7 +60,7 @@ struct SSAify : public Pass {
LocalGraph graph(func, module);
// create new local indexes, one for each set
createNewIndexes(graph);
- // we now know the sets for each get
+ // we now know the sets for each get, and can compute get indexes and handle phis
computeGetsAndPhis(graph);
// add prepends to function
addPrepends();
@@ -75,7 +75,6 @@ struct SSAify : public Pass {
}
}
- // After we traversed it all, we can compute gets and phis
void computeGetsAndPhis(LocalGraph& graph) {
for (auto& iter : graph.getSetses) {
auto* get = iter.first;
@@ -84,8 +83,7 @@ struct SSAify : public Pass {
continue; // unreachable, ignore
}
if (sets.size() == 1) {
- // TODO: add tests for this case
- // easy, just one set, use it's index
+ // easy, just one set, use its index
auto* set = *sets.begin();
if (set) {
get->index = set->index;
@@ -138,10 +136,18 @@ struct SSAify : public Pass {
for (auto* set : sets) {
if (set) {
// a set exists, just add a tee of its value
- set->value = builder.makeTeeLocal(
+ auto* value = set->value;
+ auto* tee = builder.makeTeeLocal(
new_,
- set->value
+ value
);
+ set->value = tee;
+ // the value may have been something we tracked the location
+ // of. if so, update that, since we moved it into the tee
+ if (graph.locations.count(value) > 0) {
+ assert(graph.locations[value] == &set->value);
+ graph.locations[value] = &tee->value;
+ }
} else {
// this is a param or the zero init value.
if (func->isParam(old)) {