Skip to content

Commit

Permalink
Change how we log, so that we can log for each caller-callee pair
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Apr 3, 2024
1 parent 1b434fe commit 23da798
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/ir/module-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,22 @@ template<typename T> struct CallGraphPropertyAnalysis {

// Propagate a property from a function to those that call it.
//
// hasProperty() - Check if the property is present.
// hasProperty() - Check if the property is present. The second parameter is
// the function due to which we are adding the property, which
// may be useful for logging.
// 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.
void propagateBack(std::function<bool(const T&)> hasProperty,
// addProperty() - Adds the property.
void propagateBack(std::function<bool(const T&, Function*)> hasProperty,
std::function<bool(const T&)> canHaveProperty,
std::function<void(T&, Function*)> addProperty,
std::function<void(T&)> addProperty,
NonDirectCalls nonDirectCalls) {
// The work queue contains items we just learned can change the state.
UniqueDeferredQueue<Function*> work;
for (auto& func : wasm.functions) {
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());
}
}
Expand All @@ -411,8 +412,8 @@ template<typename T> struct CallGraphPropertyAnalysis {
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);
if (canHaveProperty(map[caller]) && !hasProperty(map[caller], func)) {
addProperty(map[caller]);
work.push(caller);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/passes/Asyncify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,19 +711,19 @@ class ModuleAnalyzer {
handleAddList(scanner.map);
}

scanner.propagateBack([](const Info& info) { return info.canChangeState; },
[](const Info& info) {
return !info.isBottomMostRuntime &&
!info.inRemoveList;
},
[verbose](Info& info, Function* reason) {
scanner.propagateBack([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;
return info.canChangeState;
},
[](const Info& info) {
return !info.isBottomMostRuntime &&
!info.inRemoveList;
},
[](Info& info) { info.canChangeState = true; },
scanner.IgnoreNonDirectCalls);

map.swap(scanner.map);
Expand Down
4 changes: 2 additions & 2 deletions src/passes/PostEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ struct PostEmscripten : public Pass {

// Assume a non-direct call might throw.
analyzer.propagateBack(
[](const Info& info) { return info.canThrow; },
[](const Info& info, Function* reason) { return info.canThrow; },
[](const Info& info) { return true; },
[](Info& info, Function* reason) { info.canThrow = true; },
[](Info& info) { info.canThrow = true; },
analyzer.NonDirectCallsHaveProperty);

// Apply the information.
Expand Down

0 comments on commit 23da798

Please # to comment.