2626
2727namespace wasm {
2828
29- struct FunctionHasher : public PostWalker <FunctionHasher, Visitor<FunctionHasher>> {
30- bool isFunctionParallel () { return true ; }
29+ struct FunctionHasher : public WalkerPass < PostWalker<FunctionHasher, Visitor<FunctionHasher> >> {
30+ bool isFunctionParallel () override { return true ; }
3131
32- FunctionHasher* create () override {
33- auto * ret = new FunctionHasher;
34- ret->setOutput (output);
35- return ret;
36- }
32+ FunctionHasher (std::map<Function*, uint32_t >* output) : output(output) {}
3733
38- void setOutput (std::map<Function*, uint32_t >* output_) {
39- output = output_ ;
34+ FunctionHasher* create () override {
35+ return new FunctionHasher (output) ;
4036 }
4137
4238 void doWalkFunction (Function* func) {
@@ -63,17 +59,13 @@ struct FunctionHasher : public PostWalker<FunctionHasher, Visitor<FunctionHasher
6359 };
6460};
6561
66- struct FunctionReplacer : public PostWalker <FunctionReplacer, Visitor<FunctionReplacer>> {
67- bool isFunctionParallel () { return true ; }
62+ struct FunctionReplacer : public WalkerPass < PostWalker<FunctionReplacer, Visitor<FunctionReplacer> >> {
63+ bool isFunctionParallel () override { return true ; }
6864
69- FunctionReplacer* create () override {
70- auto * ret = new FunctionReplacer;
71- ret->setReplacements (replacements);
72- return ret;
73- }
65+ FunctionReplacer (std::map<Name, Name>* replacements) : replacements(replacements) {}
7466
75- void setReplacements (std::map<Name, Name>* replacements_) {
76- replacements = replacements_ ;
67+ FunctionReplacer* create () override {
68+ return new FunctionReplacer (replacements) ;
7769 }
7870
7971 void visitCall (Call* curr) {
@@ -95,9 +87,9 @@ struct DuplicateFunctionElimination : public Pass {
9587 for (auto & func : module ->functions ) {
9688 hashes[func.get ()] = 0 ; // ensure an entry for each function - we must not modify the map shape in parallel, just the values
9789 }
98- FunctionHasher hasher ;
99- hasher. setOutput (&hashes);
100- hasher. walkModule ( module );
90+ PassRunner hasherRunner ( module ) ;
91+ hasherRunner. add <FunctionHasher> (&hashes);
92+ hasherRunner. run ( );
10193 // Find hash-equal groups
10294 std::map<uint32_t , std::vector<Function*>> hashGroups;
10395 for (auto & func : module ->functions ) {
@@ -127,9 +119,9 @@ struct DuplicateFunctionElimination : public Pass {
127119 }), v.end ());
128120 module ->updateFunctionsMap ();
129121 // replace direct calls
130- FunctionReplacer replacer ;
131- replacer. setReplacements (&replacements);
132- replacer. walkModule ( module );
122+ PassRunner replacerRunner ( module ) ;
123+ replacerRunner. add <FunctionReplacer> (&replacements);
124+ replacerRunner. run ( );
133125 // replace in table
134126 for (auto & name : module ->table .names ) {
135127 auto iter = replacements.find (name);
0 commit comments