[llvm] 7529fab - [test] Factor out creation of copy of SCC Nodes into function

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 17 11:39:43 PST 2020


Author: Arthur Eubanks
Date: 2020-12-17T11:39:34-08:00
New Revision: 7529fab602c728d12c387e5eb5bbced1ec139dbd

URL: https://github.com/llvm/llvm-project/commit/7529fab602c728d12c387e5eb5bbced1ec139dbd
DIFF: https://github.com/llvm/llvm-project/commit/7529fab602c728d12c387e5eb5bbced1ec139dbd.diff

LOG: [test] Factor out creation of copy of SCC Nodes into function

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D93434

Added: 
    

Modified: 
    llvm/unittests/Analysis/CGSCCPassManagerTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index 2c3b0c126d2e..5b68b985330a 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/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<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"
@@ -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;
@@ -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;
@@ -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;


        


More information about the llvm-commits mailing list