diff options
author | Dannii Willis <curiousdannii@gmail.com> | 2024-04-09 03:24:15 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 10:24:15 -0700 |
commit | f0dd9941de2df62e0a29f2faeadf007e37a425a9 (patch) | |
tree | a8fb878d404284eb86eac5321113f3e8e9c6bb59 /src | |
parent | 98f08effb18a94618ef12f25134c289836fc316e (diff) | |
download | binaryen-f0dd9941de2df62e0a29f2faeadf007e37a425a9.tar.gz binaryen-f0dd9941de2df62e0a29f2faeadf007e37a425a9.tar.bz2 binaryen-f0dd9941de2df62e0a29f2faeadf007e37a425a9.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/module-utils.h | 24 | ||||
-rw-r--r-- | src/passes/Asyncify.cpp | 6 | ||||
-rw-r--r-- | src/passes/PostEmscripten.cpp | 10 |
3 files changed, 24 insertions, 16 deletions
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<typename T> 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<bool(const T&)> hasProperty, std::function<bool(const T&)> canHaveProperty, - std::function<void(T&, Function*)> addProperty, + std::function<void(T&)> addProperty, + std::function<void(const T&, Function*)> logVisit, NonDirectCalls nonDirectCalls) { // The work queue contains items we just learned can change the state. UniqueDeferredQueue<Function*> work; @@ -402,17 +404,23 @@ template<typename T> 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<PostWalker<OptimizeInvokes>> { |