1919// Function::effects; see more details there.
2020//
2121
22+ #include " ir/table-utils.h"
2223#include " ir/subtypes.h"
2324#include " ir/effects.h"
2425#include " ir/module-utils.h"
2526#include " pass.h"
27+ #include " ir/element-utils.h"
2628#include " support/unique_deferring_queue.h"
2729#include " wasm.h"
2830
@@ -194,6 +196,20 @@ struct GenerateGlobalEffects : public Pass {
194196 std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>> callers;
195197
196198 std::unordered_set<HeapType> allIndirectCalledTypes;
199+
200+ std::unordered_set<Name> funcsWithAddress;
201+
202+ auto refFuncs = TableUtils::getFunctionsNeedingElemDeclare (*module );
203+ funcsWithAddress.insert (refFuncs.begin (), refFuncs.end ());
204+ ElementUtils::iterAllElementFunctionNames (module , [&funcsWithAddress](Name name) { funcsWithAddress.insert (name); });
205+ for (const auto & export_ : module ->exports ) {
206+ if (export_->kind == ExternalKind::Function) {
207+ // This exported function might flow back to us even in a closed world,
208+ // so it's essentially addressed.
209+ funcsWithAddress.insert (export_->name );
210+ }
211+ }
212+
197213 for (const auto & [func, info] : funcInfos) {
198214 // Name -> Name for direct calls
199215 for (const auto & callee : info.calledFunctions ) {
@@ -206,7 +222,9 @@ struct GenerateGlobalEffects : public Pass {
206222 }
207223
208224 // Name -> HeapType for function types
209- callers[func->name ].insert (func->type .getHeapType ());
225+ if (funcsWithAddress.contains (func->name )) {
226+ callers[func->name ].insert (func->type .getHeapType ());
227+ }
210228
211229 allIndirectCalledTypes.insert (func->type .getHeapType ());
212230 }
@@ -218,6 +236,7 @@ struct GenerateGlobalEffects : public Pass {
218236 // A subtype is a 'callee' of its supertype. Supertypes need to inherit effects from their subtypes
219237 // See the example in (TODO)
220238 callers[sub].insert (type);
239+ // callers[type].insert(sub);
221240 return true ;
222241 });
223242 }
0 commit comments