summaryrefslogtreecommitdiff
path: root/src/passes/SSAify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/SSAify.cpp')
-rw-r--r--src/passes/SSAify.cpp51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/passes/SSAify.cpp b/src/passes/SSAify.cpp
index 1ed3b976f..2f0f9439c 100644
--- a/src/passes/SSAify.cpp
+++ b/src/passes/SSAify.cpp
@@ -50,13 +50,13 @@
#include <iterator>
-#include "wasm.h"
-#include "pass.h"
-#include "wasm-builder.h"
-#include "support/permutations.h"
#include "ir/find_all.h"
#include "ir/literal-utils.h"
#include "ir/local-graph.h"
+#include "pass.h"
+#include "support/permutations.h"
+#include "wasm-builder.h"
+#include "wasm.h"
namespace wasm {
@@ -77,9 +77,11 @@ struct SSAify : public Pass {
Module* module;
Function* func;
- std::vector<Expression*> functionPrepends; // things we add to the function prologue
+ // things we add to the function prologue
+ std::vector<Expression*> functionPrepends;
- void runOnFunction(PassRunner* runner, Module* module_, Function* func_) override {
+ void
+ runOnFunction(PassRunner* runner, Module* module_, Function* func_) override {
module = module_;
func = func_;
LocalGraph graph(func);
@@ -87,7 +89,8 @@ struct SSAify : public Pass {
graph.computeSSAIndexes();
// create new local indexes, one for each set
createNewIndexes(graph);
- // we now know the sets for each get, and can compute get indexes and handle phis
+ // we now know the sets for each get, and can compute get indexes and handle
+ // phis
computeGetsAndPhis(graph);
// add prepends to function
addPrepends();
@@ -96,9 +99,9 @@ struct SSAify : public Pass {
void createNewIndexes(LocalGraph& graph) {
FindAll<SetLocal> sets(func->body);
for (auto* set : sets.list) {
- // Indexes already in SSA form do not need to be modified - there is already
- // just one set for that index. Otherwise, use a new index, unless merges
- // are disallowed.
+ // Indexes already in SSA form do not need to be modified - there is
+ // already just one set for that index. Otherwise, use a new index, unless
+ // merges are disallowed.
if (!graph.isSSA(set->index) && (allowMerges || !hasMerges(set, graph))) {
set->index = addLocal(func->getLocalType(set->index));
}
@@ -132,12 +135,14 @@ struct SSAify : public Pass {
// leave it, it's fine
} else {
// zero it out
- (*graph.locations[get]) = LiteralUtils::makeZero(get->type, *module);
+ (*graph.locations[get]) =
+ LiteralUtils::makeZero(get->type, *module);
}
}
continue;
}
- if (!allowMerges) continue;
+ if (!allowMerges)
+ continue;
// more than 1 set, need a phi: a new local written to at each of the sets
auto new_ = addLocal(get->type);
auto old = get->index;
@@ -148,10 +153,7 @@ struct SSAify : public Pass {
if (set) {
// a set exists, just add a tee of its value
auto* value = set->value;
- auto* tee = builder.makeTeeLocal(
- new_,
- value
- );
+ auto* tee = builder.makeTeeLocal(new_, 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
@@ -165,9 +167,7 @@ struct SSAify : public Pass {
// we add a set with the proper
// param value at the beginning of the function
auto* set = builder.makeSetLocal(
- new_,
- builder.makeGetLocal(old, func->getLocalType(old))
- );
+ new_, builder.makeGetLocal(old, func->getLocalType(old)));
functionPrepends.push_back(set);
} else {
// this is a zero init, so we don't need to do anything actually
@@ -177,9 +177,7 @@ struct SSAify : public Pass {
}
}
- Index addLocal(Type type) {
- return Builder::addVar(func, type);
- }
+ Index addLocal(Type type) { return Builder::addVar(func, type); }
void addPrepends() {
if (functionPrepends.size() > 0) {
@@ -195,13 +193,8 @@ struct SSAify : public Pass {
}
};
-Pass* createSSAifyPass() {
- return new SSAify(true);
-}
+Pass* createSSAifyPass() { return new SSAify(true); }
-Pass* createSSAifyNoMergePass() {
- return new SSAify(false);
-}
+Pass* createSSAifyNoMergePass() { return new SSAify(false); }
} // namespace wasm
-