@@ -95,21 +95,21 @@ TableInfoMap computeTableInfo(Module& wasm, bool initialContentsImmutable) {
9595
9696 for (auto & table : wasm.tables ) {
9797 if (table->imported ()) {
98- tables[table->name ].mayBeModified = true ;
98+ tables[table->name ].hasSet = true ;
9999 }
100100 }
101101
102102 for (auto & ex : wasm.exports ) {
103103 if (ex->kind == ExternalKind::Table) {
104- tables[*ex->getInternalName ()].mayBeModified = true ;
104+ tables[*ex->getInternalName ()].hasSet = true ;
105105 }
106106 }
107107
108108 // Find which tables have sets, by scanning for instructions. Only do so if we
109109 // might learn anything new.
110110 auto hasUnmodifiableTable = false ;
111111 for (auto & [_, info] : tables) {
112- if (!info.mayBeModified ) {
112+ if (!info.hasSet ) {
113113 hasUnmodifiableTable = true ;
114114 break ;
115115 }
@@ -118,39 +118,54 @@ TableInfoMap computeTableInfo(Module& wasm, bool initialContentsImmutable) {
118118 return tables;
119119 }
120120
121- using TablesWithSet = std::unordered_set<Name>;
121+ // Miniature form of TableInfo, without things we don't need (some of which
122+ // cause compilation errors on the copies below).
123+ struct MiniTableInfo {
124+ bool hasSet = false ;
125+ bool hasGrow = false ;
126+ };
122127
123- ModuleUtils::ParallelFunctionAnalysis<TablesWithSet> analysis (
124- wasm, [&](Function* func, TablesWithSet& tablesWithSet) {
128+ using MiniTableInfoMap = std::unordered_map<Name, MiniTableInfo>;
129+
130+ ModuleUtils::ParallelFunctionAnalysis<MiniTableInfoMap> analysis (
131+ wasm, [&](Function* func, MiniTableInfoMap& tableInfoMap) {
125132 if (func->imported ()) {
126133 return ;
127134 }
128135
129136 struct Finder : public PostWalker <Finder> {
130- TablesWithSet& tablesWithSet ;
137+ MiniTableInfoMap& tableInfoMap ;
131138
132- Finder (TablesWithSet& tablesWithSet ) : tablesWithSet(tablesWithSet ) {}
139+ Finder (MiniTableInfoMap& tableInfoMap ) : tableInfoMap(tableInfoMap ) {}
133140
134141 void visitTableSet (TableSet* curr) {
135- tablesWithSet. insert ( curr->table ) ;
142+ tableInfoMap[ curr->table ]. hasSet = true ;
136143 }
137144 void visitTableFill (TableFill* curr) {
138- tablesWithSet. insert ( curr->table ) ;
145+ tableInfoMap[ curr->table ]. hasSet = true ;
139146 }
140147 void visitTableCopy (TableCopy* curr) {
141- tablesWithSet. insert ( curr->destTable ) ;
148+ tableInfoMap[ curr->destTable ]. hasSet = true ;
142149 }
143150 void visitTableInit (TableInit* curr) {
144- tablesWithSet.insert (curr->table );
151+ tableInfoMap[curr->table ].hasSet = true ;
152+ }
153+ void visitTableGrow (TableGrow* curr) {
154+ tableInfoMap[curr->table ].hasGrow = true ;
145155 }
146156 };
147157
148- Finder (tablesWithSet ).walkFunction (func);
158+ Finder (tableInfoMap ).walkFunction (func);
149159 });
150160
151- for (auto & [_, names] : analysis.map ) {
152- for (auto name : names) {
153- tables[name].mayBeModified = true ;
161+ for (auto & [_, tableInfoMap] : analysis.map ) {
162+ for (auto & [tableName, info] : tableInfoMap) {
163+ if (info.hasSet ) {
164+ tables[tableName].hasSet = true ;
165+ }
166+ if (info.hasGrow ) {
167+ tables[tableName].hasGrow = true ;
168+ }
154169 }
155170 }
156171
0 commit comments