[PATCH] D116776: [LazyCallGraph] Ignore empty RefSCCs rather than shift RefSCCs when removing dead functions
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 7 09:46:47 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd51e3474e060: [LazyCallGraph] Ignore empty RefSCCs rather than shift RefSCCs when removing… (authored by aeubanks).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116776/new/
https://reviews.llvm.org/D116776
Files:
llvm/include/llvm/Analysis/LazyCallGraph.h
llvm/lib/Analysis/LazyCallGraph.cpp
Index: llvm/lib/Analysis/LazyCallGraph.cpp
===================================================================
--- llvm/lib/Analysis/LazyCallGraph.cpp
+++ llvm/lib/Analysis/LazyCallGraph.cpp
@@ -1544,15 +1544,9 @@
assert(C.size() == 1 && "Dead functions must be in a singular SCC");
assert(RC.size() == 1 && "Dead functions must be in a singular RefSCC");
- auto RCIndexI = RefSCCIndices.find(&RC);
- int RCIndex = RCIndexI->second;
- PostOrderRefSCCs.erase(PostOrderRefSCCs.begin() + RCIndex);
- RefSCCIndices.erase(RCIndexI);
- for (int i = RCIndex, Size = PostOrderRefSCCs.size(); i < Size; ++i)
- RefSCCIndices[PostOrderRefSCCs[i]] = i;
-
// Finally clear out all the data structures from the node down through the
- // components.
+ // components. postorder_ref_scc_iterator will skip empty RefSCCs, so no need
+ // to adjust LazyCallGraph data structures.
N.clear();
N.G = nullptr;
N.F = nullptr;
Index: llvm/include/llvm/Analysis/LazyCallGraph.h
===================================================================
--- llvm/include/llvm/Analysis/LazyCallGraph.h
+++ llvm/include/llvm/Analysis/LazyCallGraph.h
@@ -884,7 +884,9 @@
RefSCC *RC = nullptr;
/// Build the begin iterator for a node.
- postorder_ref_scc_iterator(LazyCallGraph &G) : G(&G), RC(getRC(G, 0)) {}
+ postorder_ref_scc_iterator(LazyCallGraph &G) : G(&G), RC(getRC(G, 0)) {
+ incrementUntilNonEmptyRefSCC();
+ }
/// Build the end iterator for a node. This is selected purely by overload.
postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) : G(&G) {}
@@ -899,6 +901,17 @@
return G.PostOrderRefSCCs[Index];
}
+ // Keep incrementing until RC is non-empty (or null).
+ void incrementUntilNonEmptyRefSCC() {
+ while (RC && RC->size() == 0)
+ increment();
+ }
+
+ void increment() {
+ assert(RC && "Cannot increment the end iterator!");
+ RC = getRC(*G, G->RefSCCIndices.find(RC)->second + 1);
+ }
+
public:
bool operator==(const postorder_ref_scc_iterator &Arg) const {
return G == Arg.G && RC == Arg.RC;
@@ -908,8 +921,8 @@
using iterator_facade_base::operator++;
postorder_ref_scc_iterator &operator++() {
- assert(RC && "Cannot increment the end iterator!");
- RC = getRC(*G, G->RefSCCIndices.find(RC)->second + 1);
+ increment();
+ incrementUntilNonEmptyRefSCC();
return *this;
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116776.398181.patch
Type: text/x-patch
Size: 2451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220107/63dadb7a/attachment.bin>
More information about the llvm-commits
mailing list