From 517fe7c42bf7e1f80f2584ea279b2f4a7e6a8ca4 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Wed, 16 Dec 2020 17:14:13 -0800 Subject: [PATCH] [test] Factor out creation of copy of SCC Nodes into function Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D93434 --- unittests/Analysis/CGSCCPassManagerTest.cpp | 31 +++++++++------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/unittests/Analysis/CGSCCPassManagerTest.cpp b/unittests/Analysis/CGSCCPassManagerTest.cpp index 2c3b0c126d2..5b68b985330 100644 --- a/unittests/Analysis/CGSCCPassManagerTest.cpp +++ b/unittests/Analysis/CGSCCPassManagerTest.cpp @@ -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 SCCNodes(LazyCallGraph::SCC &C) { + SmallVector 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 M = parseIR("define void @f() {\n" @@ -1734,12 +1744,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewFunctions1) { auto &FAM = AM.getResult(C, CG).getManager(); - // Don't iterate over SCC while changing it. - SmallVector 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; @@ -1801,12 +1806,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewFunctions2) { auto &FAM = AM.getResult(C, CG).getManager(); - // Don't iterate over SCC while changing it. - SmallVector 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; @@ -1908,12 +1908,7 @@ TEST_F(CGSCCPassManagerTest, TestInsertionOfNewNonTrivialCallEdge) { auto &FAM = AM.getResult(C, CG).getManager(); - // Don't iterate over SCC while changing it. - SmallVector 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;