summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-26 01:03:46 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-26 01:03:46 +0000
commit8f92d6db22b8f4ccfedf4349a8d18ab4f93dc8f8 (patch)
tree2833c97782c435739862d314b5b5cd4b14c21f59
parent8cc9059ce8f3bd25fd61b0cf6936295c80518bf3 (diff)
downloadbcm5719-llvm-8f92d6db22b8f4ccfedf4349a8d18ab4f93dc8f8.tar.gz
bcm5719-llvm-8f92d6db22b8f4ccfedf4349a8d18ab4f93dc8f8.zip
[LCG] Refactor the duplicated code I added in my last commit here into
a helper function. Also factor the other two places where we did the same thing into the helper function. =] Much cleaner this way. NFC. llvm-svn: 207300
-rw-r--r--llvm/include/llvm/Analysis/LazyCallGraph.h2
-rw-r--r--llvm/lib/Analysis/LazyCallGraph.cpp37
2 files changed, 16 insertions, 23 deletions
diff --git a/llvm/include/llvm/Analysis/LazyCallGraph.h b/llvm/include/llvm/Analysis/LazyCallGraph.h
index 2ed3cd0d13b..940a7cd7886 100644
--- a/llvm/include/llvm/Analysis/LazyCallGraph.h
+++ b/llvm/include/llvm/Analysis/LazyCallGraph.h
@@ -220,6 +220,8 @@ public:
SCC() {}
+ void insert(LazyCallGraph &G, Node &N);
+
void removeEdge(LazyCallGraph &G, Function &Caller, Function &Callee,
SCC &CalleeC);
diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index 6c94abb6000..f7f10101ad9 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -131,6 +131,12 @@ LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) {
return *this;
}
+void LazyCallGraph::SCC::insert(LazyCallGraph &G, Node &N) {
+ N.DFSNumber = N.LowLink = -1;
+ Nodes.push_back(&N);
+ G.SCCMap[&N] = this;
+}
+
void LazyCallGraph::SCC::removeEdge(LazyCallGraph &G, Function &Caller,
Function &Callee, SCC &CalleeC) {
assert(std::find(G.LeafSCCs.begin(), G.LeafSCCs.end(), this) ==
@@ -203,9 +209,7 @@ LazyCallGraph::SCC::removeInternalEdge(LazyCallGraph &G, Node &Caller,
// incrementally add any chain of nodes which reaches something in the new
// node set to the new node set. This short circuits one side of the Tarjan's
// walk.
- Nodes.push_back(&Callee);
- G.SCCMap.insert(std::make_pair(&Callee, this));
- Callee.DFSNumber = Callee.LowLink = -1;
+ insert(G, Callee);
for (;;) {
if (DFSStack.empty()) {
@@ -235,16 +239,10 @@ LazyCallGraph::SCC::removeInternalEdge(LazyCallGraph &G, Node &Caller,
// this SCC. If so, the entire stack is necessarily in that set and we
// can re-start.
if (ChildSCC == this) {
- while (!PendingSCCStack.empty()) {
- Nodes.push_back(PendingSCCStack.pop_back_val());
- G.SCCMap.insert(std::make_pair(Nodes.back(), this));
- Nodes.back()->DFSNumber = Nodes.back()->LowLink = -1;
- }
- while (!DFSStack.empty()) {
- Nodes.push_back(DFSStack.pop_back_val().first);
- G.SCCMap.insert(std::make_pair(Nodes.back(), this));
- Nodes.back()->DFSNumber = Nodes.back()->LowLink = -1;
- }
+ while (!PendingSCCStack.empty())
+ insert(G, *PendingSCCStack.pop_back_val());
+ while (!DFSStack.empty())
+ insert(G, *DFSStack.pop_back_val().first);
Recurse = true;
break;
}
@@ -392,20 +390,13 @@ LazyCallGraph::SCC *LazyCallGraph::formSCC(Node *RootN,
// into it.
SCC *NewSCC = new (SCCBPA.Allocate()) SCC();
- SCCMap[RootN] = NewSCC;
- NewSCC->Nodes.push_back(RootN);
-
while (!NodeStack.empty() && NodeStack.back()->DFSNumber > RootN->DFSNumber) {
- Node *SCCN = NodeStack.pop_back_val();
- assert(SCCN->LowLink >= RootN->LowLink &&
+ assert(NodeStack.back()->LowLink >= RootN->LowLink &&
"We cannot have a low link in an SCC lower than its root on the "
"stack!");
- SCCN->DFSNumber = SCCN->LowLink = -1;
-
- SCCMap[SCCN] = NewSCC;
- NewSCC->Nodes.push_back(SCCN);
+ NewSCC->insert(*this, *NodeStack.pop_back_val());
}
- RootN->DFSNumber = RootN->LowLink = -1;
+ NewSCC->insert(*this, *RootN);
// A final pass over all edges in the SCC (this remains linear as we only
// do this once when we build the SCC) to connect it to the parent sets of
OpenPOWER on IntegriCloud