From f0dd9941de2df62e0a29f2faeadf007e37a425a9 Mon Sep 17 00:00:00 2001 From: Dannii Willis Date: Tue, 9 Apr 2024 03:24:15 +1000 Subject: Asyncify-verbose: Show all reasons why a function is instrumented (#6457) Helps emscripten-core/emscripten#17380 by logging all the reasons why we instrument a function, and not just the first as we did before. --- src/ir/module-utils.h | 24 ++++++++++++++++-------- src/passes/Asyncify.cpp | 6 +++--- src/passes/PostEmscripten.cpp | 10 +++++----- 3 files changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index eabcd036c..190191cd7 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -390,11 +390,13 @@ template struct CallGraphPropertyAnalysis { // // hasProperty() - Check if the property is present. // canHaveProperty() - Check if the property could be present. - // addProperty() - Adds the property. This receives a second parameter which - // is the function due to which we are adding the property. + // addProperty() - Adds the property. + // logVisit() - Log each visit of the propagation. This is called before + // we check if the function already has the property. void propagateBack(std::function hasProperty, std::function canHaveProperty, - std::function addProperty, + std::function addProperty, + std::function logVisit, NonDirectCalls nonDirectCalls) { // The work queue contains items we just learned can change the state. UniqueDeferredQueue work; @@ -402,17 +404,23 @@ template struct CallGraphPropertyAnalysis { if (hasProperty(map[func.get()]) || (nonDirectCalls == NonDirectCallsHaveProperty && map[func.get()].hasNonDirectCall)) { - addProperty(map[func.get()], func.get()); + addProperty(map[func.get()]); work.push(func.get()); } } while (!work.empty()) { auto* func = work.pop(); for (auto* caller : map[func].calledBy) { - // If we don't already have the property, and we are not forbidden - // from getting it, then it propagates back to us now. - if (!hasProperty(map[caller]) && canHaveProperty(map[caller])) { - addProperty(map[caller], func); + // Skip functions forbidden from getting this property. + if (!canHaveProperty(map[caller])) { + continue; + } + // Log now, even if the function already has the property. + logVisit(map[caller], func); + // If we don't already have the property, then add it now, and propagate + // further. + if (!hasProperty(map[caller])) { + addProperty(map[caller]); work.push(caller); } } diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index 07b05d21e..b74c1d7ae 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -716,13 +716,13 @@ public: return !info.isBottomMostRuntime && !info.inRemoveList; }, - [verbose](Info& info, Function* reason) { - if (verbose && !info.canChangeState) { + [](Info& info) { info.canChangeState = true; }, + [verbose](const Info& info, Function* reason) { + if (verbose) { std::cout << "[asyncify] " << info.name << " can change the state due to " << reason->name << "\n"; } - info.canChangeState = true; }, scanner.IgnoreNonDirectCalls); diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index b7d3e9f91..7ade801cc 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -287,11 +287,11 @@ struct PostEmscripten : public Pass { }); // Assume a non-direct call might throw. - analyzer.propagateBack( - [](const Info& info) { return info.canThrow; }, - [](const Info& info) { return true; }, - [](Info& info, Function* reason) { info.canThrow = true; }, - analyzer.NonDirectCallsHaveProperty); + analyzer.propagateBack([](const Info& info) { return info.canThrow; }, + [](const Info& info) { return true; }, + [](Info& info) { info.canThrow = true; }, + [](const Info& info, Function* reason) {}, + analyzer.NonDirectCallsHaveProperty); // Apply the information. struct OptimizeInvokes : public WalkerPass> { -- cgit v1.2.3