2626#include " pass.h"
2727#include " support/graph_traversal.h"
2828#include " support/strongly_connected_components.h"
29+ #include " support/utilities.h"
2930#include " wasm.h"
3031
3132namespace wasm {
@@ -227,10 +228,13 @@ void mergeMaybeEffects(std::optional<EffectAnalyzer>& dest,
227228// - Merge all of the effects of functions within the CC
228229// - Also merge the (already computed) effects of each callee CC
229230// - Add trap effects for potentially recursive call chains
230- void propagateEffects (const Module& module ,
231- const PassOptions& passOptions,
232- std::map<Function*, FuncInfo>& funcInfos,
233- const CallGraph& callGraph) {
231+ void propagateEffects (
232+ const Module& module ,
233+ const PassOptions& passOptions,
234+ std::map<Function*, FuncInfo>& funcInfos,
235+ std::unordered_map<HeapType, std::shared_ptr<const EffectAnalyzer>>&
236+ typeEffects,
237+ const CallGraph& callGraph) {
234238 // We only care about Functions that are roots, not types.
235239 // A type would be a root if a function exists with that type, but no-one
236240 // indirect calls the type.
@@ -319,12 +323,21 @@ void propagateEffects(const Module& module,
319323 }
320324
321325 // Assign each function's effects to its CC effects.
322- for (Function* f : ccFuncs) {
323- if (!ccEffects) {
324- funcInfos.at (f).effects = UnknownEffects;
325- } else {
326- funcInfos.at (f).effects .emplace (*ccEffects);
327- }
326+ for (auto node : cc) {
327+ std::visit (overloaded{[&](HeapType type) {
328+ if (ccEffects != UnknownEffects) {
329+ typeEffects[type] =
330+ std::make_shared<EffectAnalyzer>(*ccEffects);
331+ }
332+ },
333+ [&](Function* f) {
334+ if (!ccEffects) {
335+ funcInfos.at (f).effects = UnknownEffects;
336+ } else {
337+ funcInfos.at (f).effects .emplace (*ccEffects);
338+ }
339+ }},
340+ node);
328341 }
329342 }
330343}
@@ -348,7 +361,8 @@ struct GenerateGlobalEffects : public Pass {
348361 auto callGraph =
349362 buildCallGraph (*module , funcInfos, getPassOptions ().closedWorld );
350363
351- propagateEffects (*module , getPassOptions (), funcInfos, callGraph);
364+ propagateEffects (
365+ *module , getPassOptions (), funcInfos, module ->typeEffects , callGraph);
352366
353367 copyEffectsToFunctions (funcInfos);
354368 }
0 commit comments