-
Notifications
You must be signed in to change notification settings - Fork 831
[NFC] DeadArgumentElimination: Compute callers once #8053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
90b8a3b
54f3495
a746311
cef0679
3369eb4
927c81e
7bdccd5
48d6a91
0851b43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,20 @@ struct DAE : public Pass { | |
| } | ||
| } | ||
|
|
||
| // For each function, the set of callers. This is used to propagate changes, | ||
| // e.g. if we remove a return value from a function, the calls might benefit | ||
| // from optimization. It is ok if this is an over-approximation, that is, if | ||
| // we think there are more callers than there are, as it would just lead to | ||
| // unneeded extra scanning of calling functions (in the example just given, if | ||
| // a caller did not actually call, they would not benefit from optimization, | ||
| // but no harm is done, and no optimization is missed). Such over- | ||
| // approximation can happen in later optimization iterations: We may manage to | ||
| // remove a call from a function to another (say, after applying a constant | ||
| // param, we see the call is not reached). This is somewhat rare, and the cost | ||
| // of computing this map is significant, so we compute it once at the start | ||
| // and then use that possibly-over-approximating data. | ||
| std::vector<std::unordered_set<Name>> callers; | ||
|
||
|
|
||
| bool iteration(Module* module, DAEFunctionInfoMap& infoMap) { | ||
| allDroppedCalls.clear(); | ||
|
|
||
|
|
@@ -246,15 +260,10 @@ struct DAE : public Pass { | |
| std::vector<bool> tailCallees(numFunctions); | ||
| std::vector<bool> hasUnseenCalls(numFunctions); | ||
|
|
||
| // For each function, the set of callers. | ||
| std::vector<std::unordered_set<Name>> callers(numFunctions); | ||
|
|
||
| for (auto& [func, info] : infoMap) { | ||
| for (auto& [name, calls] : info.calls) { | ||
| auto targetIndex = indexes[name]; | ||
| auto& allCallsToName = allCalls[targetIndex]; | ||
| auto& allCallsToName = allCalls[indexes[name]]; | ||
| allCallsToName.insert(allCallsToName.end(), calls.begin(), calls.end()); | ||
| callers[targetIndex].insert(func); | ||
| } | ||
| for (auto& callee : info.tailCallees) { | ||
| tailCallees[indexes[callee]] = true; | ||
|
|
@@ -273,6 +282,16 @@ struct DAE : public Pass { | |
| } | ||
| } | ||
|
|
||
| // See comment above, we compute callers once and never again. | ||
| if (callers.empty()) { | ||
| callers.resize(numFunctions); | ||
| for (auto& [func, info] : infoMap) { | ||
| for (auto& [name, calls] : info.calls) { | ||
| callers[indexes[name]].insert(func); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Track which functions we changed that are worth re-optimizing at the end. | ||
| std::unordered_set<Function*> worthOptimizing; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.