[llvm] 26f3563 - [LazyCallGraph] Fix ambiguous index value
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 20:33:03 PST 2020
Author: Brian Gesiak
Date: 2020-02-18T23:32:55-05:00
New Revision: 26f356350bd56f5418e5fae230b1a6931774c8f1
URL: https://github.com/llvm/llvm-project/commit/26f356350bd56f5418e5fae230b1a6931774c8f1
DIFF: https://github.com/llvm/llvm-project/commit/26f356350bd56f5418e5fae230b1a6931774c8f1.diff
LOG: [LazyCallGraph] Fix ambiguous index value
After having committed https://reviews.llvm.org/D72226, 2 buildbots
running GCC 5.4.0 began failing. The cause was the order in which those
compilers evaluated the left- and right-hand sides of the expression
`RC.SCCIndices[C] = RC.SCCIndices.size();`. This commit splits the
expression into multiple statements to avoid ambiguity, and adds a test
case that exercises the code that caused the test failures on those
older compilers (which was originally included in the reviewed patch,
https://reviews.llvm.org/D72226).
Added:
Modified:
llvm/lib/Analysis/LazyCallGraph.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index 0d647cba7092..1ce20d1db156 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -1576,7 +1576,8 @@ void LazyCallGraph::addNewFunctionIntoRefSCC(Function &NewF, RefSCC &RC) {
auto *C = createSCC(RC, SmallVector<Node *, 1>());
addNodeToSCC(*C, N);
- RC.SCCIndices[C] = RC.SCCIndices.size();
+ auto Index = RC.SCCIndices.size();
+ RC.SCCIndices[C] = Index;
RC.SCCs.push_back(C);
}
diff --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index b8983901269b..0ed3ca353507 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1685,5 +1685,55 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses10) {
MPM.run(*M, MAM);
}
+TEST_F(CGSCCPassManagerTest, TestInsertionOfNewRefSCC) {
+ std::unique_ptr<Module> M = parseIR("define void @f() {\n"
+ "entry:\n"
+ " call void @f()\n"
+ " ret void\n"
+ "}\n");
+
+ CGSCCPassManager CGPM(/*DebugLogging*/ true);
+ CGPM.addPass(LambdaSCCPassNoPreserve(
+ [&](LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG,
+ CGSCCUpdateResult &UR) {
+ for (auto &N : C) {
+ auto &F = N.getFunction();
+ if (F.getName() != "f")
+ continue;
+ auto *Call = dyn_cast<CallInst>(F.begin()->begin());
+ if (!Call || Call->getCalledFunction()->getName() != "f")
+ continue;
+
+ // Create a new function 'g'.
+ auto *G = Function::Create(F.getFunctionType(), F.getLinkage(),
+ F.getAddressSpace(), "g", F.getParent());
+ BasicBlock::Create(F.getParent()->getContext(), "entry", G);
+ // Instruct the LazyCallGraph to create a new node for 'g', as the
+ // single node in a new SCC, into the call graph. As a result
+ // the call graph is composed of a single RefSCC with two SCCs:
+ // [(f), (g)].
+ CG.addNewFunctionIntoRefSCC(*G, C.getOuterRefSCC());
+
+ // "Demote" the 'f -> f' call egde to a ref edge.
+ // 1. Erase the call edge from 'f' to 'f'.
+ Call->eraseFromParent();
+ // 2. Insert a ref edge from 'f' to 'f'.
+ (void)CastInst::CreatePointerCast(&F,
+ Type::getInt8PtrTy(F.getContext()),
+ "f.ref", &*F.begin()->begin());
+
+ ASSERT_NO_FATAL_FAILURE(
+ updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR))
+ << "Updating the call graph with a demoted, self-referential "
+ "call edge 'f -> f', and a newly inserted ref edge 'f -> g', "
+ "caused a fatal failure";
+ }
+ }));
+
+ ModulePassManager MPM(/*DebugLogging*/ true);
+ MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
+ MPM.run(*M, MAM);
+}
+
#endif
} // namespace
More information about the llvm-commits
mailing list