Skip to content

Commit

Permalink
[test] Factor out creation of copy of SCC Nodes into function
Browse files Browse the repository at this point in the history
Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D93434
  • Loading branch information
aeubanks committed Dec 17, 2020
1 parent 58f2b76 commit 7529fab
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
Expand Up @@ -1714,6 +1714,16 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses10) {
MPM.run(*M, MAM);
}

// Returns a vector containing the SCC's nodes. Useful for not iterating over an
// SCC while mutating it.
static SmallVector<LazyCallGraph::Node *> SCCNodes(LazyCallGraph::SCC &C) {
SmallVector<LazyCallGraph::Node *> Nodes;
for (auto &N : C)
Nodes.push_back(&N);

return Nodes;
}

// Start with call recursive f, create f -> g and ref recursive f.
TEST_F(CGSCCPassManagerTest, TestInsertionOfNewFunctions1) {
std::unique_ptr<Module> M = parseIR("define void @f() {\n"
Expand All @@ -1734,12 +1744,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewFunctions1) {
auto &FAM =
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();

// Don't iterate over SCC while changing it.
SmallVector<LazyCallGraph::Node *> Nodes;
for (auto &N : C)
Nodes.push_back(&N);

for (LazyCallGraph::Node *N : Nodes) {
for (LazyCallGraph::Node *N : SCCNodes(C)) {
Function &F = N->getFunction();
if (F.getName() != "f")
continue;
Expand Down Expand Up @@ -1801,12 +1806,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewFunctions2) {
auto &FAM =
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();

// Don't iterate over SCC while changing it.
SmallVector<LazyCallGraph::Node *> Nodes;
for (auto &N : C)
Nodes.push_back(&N);

for (LazyCallGraph::Node *N : Nodes) {
for (LazyCallGraph::Node *N : SCCNodes(C)) {
Function &F = N->getFunction();
if (F.getName() != "f")
continue;
Expand Down Expand Up @@ -1908,12 +1908,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewNonTrivialCallEdge) {
auto &FAM =
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();

// Don't iterate over SCC while changing it.
SmallVector<LazyCallGraph::Node *> Nodes;
for (auto &N : C)
Nodes.push_back(&N);

for (LazyCallGraph::Node *N : Nodes) {
for (LazyCallGraph::Node *N : SCCNodes(C)) {
Function &F = N->getFunction();
if (F.getName() != "f1")
continue;
Expand Down

0 comments on commit 7529fab

Please sign in to comment.