summaryrefslogtreecommitdiff
path: root/src/ir/local-graph.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/local-graph.h')
-rw-r--r--src/ir/local-graph.h66
1 files changed, 8 insertions, 58 deletions
diff --git a/src/ir/local-graph.h b/src/ir/local-graph.h
index ea27fa1fb..6a8f1b2af 100644
--- a/src/ir/local-graph.h
+++ b/src/ir/local-graph.h
@@ -27,21 +27,23 @@ namespace wasm {
// (see the SSA pass for actually creating new local indexes based
// on this).
//
-// TODO: the algorithm here is pretty simple, but also pretty slow,
-// we should optimize it.
-struct LocalGraph : public PostWalker<LocalGraph> {
+struct LocalGraph {
// main API
// the constructor computes getSetses, the sets affecting each get
- LocalGraph(Function* func, Module* module);
+ LocalGraph(Function* func);
// the set_locals relevant for an index or a get.
typedef std::set<SetLocal*> Sets;
+ typedef std::map<GetLocal*, Sets> GetSetses;
+
+ typedef std::map<Expression*, Expression**> Locations;
+
// externally useful information
- std::map<GetLocal*, Sets> getSetses; // the sets affecting each get. a nullptr set means the initial
+ GetSetses getSetses; // the sets affecting each get. a nullptr set means the initial
// value (0 for a var, the received value for a param)
- std::map<Expression*, Expression**> locations; // where each get and set is (for easy replacing)
+ Locations locations; // where each get and set is (for easy replacing)
// optional computation: compute the influence graphs between sets and gets
// (useful for algorithms that propagate changes)
@@ -50,58 +52,6 @@ struct LocalGraph : public PostWalker<LocalGraph> {
std::unordered_map<SetLocal*, std::unordered_set<GetLocal*>> setInfluences; // for each set, the gets whose values are influenced by that set
void computeInfluences();
-
-private:
- // we map local index => the set_locals for that index.
- // a nullptr set means there is a virtual set, from a param
- // initial value or the zero init initial value.
- typedef std::vector<Sets> Mapping;
-
- // internal state
- Index numLocals;
- Mapping currMapping;
- std::vector<Mapping> mappingStack; // used in ifs, loops
- std::map<Name, std::vector<Mapping>> breakMappings; // break target => infos that reach it
- std::vector<std::vector<GetLocal*>> loopGetStack; // stack of loops, all the gets in each, so we can update them for back branches
-
-public:
- void doWalkFunction(Function* func);
-
- // control flow
-
- void visitBlock(Block* curr);
-
- void finishIf();
-
- static void afterIfCondition(LocalGraph* self, Expression** currp);
- static void afterIfTrue(LocalGraph* self, Expression** currp);
- static void afterIfFalse(LocalGraph* self, Expression** currp);
- static void beforeLoop(LocalGraph* self, Expression** currp);
- void visitLoop(Loop* curr);
- void visitBreak(Break* curr);
- void visitSwitch(Switch* curr);
- void visitReturn(Return *curr);
- void visitUnreachable(Unreachable *curr);
-
- // local usage
-
- void visitGetLocal(GetLocal* curr);
- void visitSetLocal(SetLocal* curr);
-
- // traversal
-
- static void scan(LocalGraph* self, Expression** currp);
-
- // helpers
-
- void setUnreachable(Mapping& mapping);
-
- bool isUnreachable(Mapping& mapping);
-
- // merges a bunch of infos into one.
- // if we need phis, writes them into the provided vector. the caller should
- // ensure those are placed in the right location
- Mapping& merge(std::vector<Mapping>& mappings);
};
} // namespace wasm