diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp --- a/llvm/lib/Analysis/CGSCCPassManager.cpp +++ b/llvm/lib/Analysis/CGSCCPassManager.cpp @@ -981,8 +981,10 @@ RefSCC &TargetRC = TargetC.getOuterRefSCC(); (void)TargetRC; // TODO: This only allows trivial edges to be added for now. +#ifdef EXPENSIVE_CHECKS assert((RC == &TargetRC || RC->isAncestorOf(TargetRC)) && "New ref edge is not trivial!"); +#endif RC->insertTrivialRefEdge(N, *RefTarget); } @@ -992,8 +994,10 @@ RefSCC &TargetRC = TargetC.getOuterRefSCC(); (void)TargetRC; // TODO: This only allows trivial edges to be added for now. +#ifdef EXPENSIVE_CHECKS assert((RC == &TargetRC || RC->isAncestorOf(TargetRC)) && "New call edge is not trivial!"); +#endif // Add a trivial ref edge to be promoted later on alongside // PromotedRefTargets. RC->insertTrivialRefEdge(N, *CallTarget); @@ -1087,8 +1091,10 @@ // The easy case is when the target RefSCC is not this RefSCC. This is // only supported when the target RefSCC is a child of this RefSCC. if (&TargetRC != RC) { +#ifdef EXPENSIVE_CHECKS assert(RC->isAncestorOf(TargetRC) && "Cannot potentially form RefSCC cycles here!"); +#endif RC->switchOutgoingEdgeToRef(N, *RefTarget); LLVM_DEBUG(dbgs() << "Switch outgoing call edge to a ref edge from '" << N << "' to '" << *RefTarget << "'\n"); @@ -1121,8 +1127,10 @@ // The easy case is when the target RefSCC is not this RefSCC. This is // only supported when the target RefSCC is a child of this RefSCC. if (&TargetRC != RC) { +#ifdef EXPENSIVE_CHECKS assert(RC->isAncestorOf(TargetRC) && "Cannot potentially form RefSCC cycles here!"); +#endif RC->switchOutgoingEdgeToCall(N, *CallTarget); LLVM_DEBUG(dbgs() << "Switch outgoing ref edge to a call edge from '" << N << "' to '" << *CallTarget << "'\n"); diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp --- a/llvm/lib/Analysis/LazyCallGraph.cpp +++ b/llvm/lib/Analysis/LazyCallGraph.cpp @@ -588,9 +588,7 @@ assert(!(*SourceN)[TargetN].isCall() && "Must start with a ref edge!"); SmallVector DeletedSCCs; -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and when this - // routine finishes. +#ifdef EXPENSIVE_CHECKS verify(); auto VerifyOnExit = make_scope_exit([&]() { verify(); }); #endif @@ -620,7 +618,7 @@ // Compute the SCCs which (transitively) reach the source. auto ComputeSourceConnectedSet = [&](SmallPtrSetImpl &ConnectedSet) { -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS // Check that the RefSCC is still valid before computing this as the // results will be nonsensical of we've broken its invariants. verify(); @@ -646,7 +644,7 @@ // but because this is forward connectivity we just "recurse" through the // edges. auto ComputeTargetConnectedSet = [&](SmallPtrSetImpl &ConnectedSet) { -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS // Check that the RefSCC is still valid before computing this as the // results will be nonsensical of we've broken its invariants. verify(); @@ -694,7 +692,7 @@ return false; // No new cycle. } -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS // Before merging, check that the RefSCC remains valid after all the // postorder updates. verify(); @@ -735,9 +733,7 @@ Node &TargetN) { assert((*SourceN)[TargetN].isCall() && "Must start with a call edge!"); -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and when this - // routine finishes. +#ifdef EXPENSIVE_CHECKS verify(); auto VerifyOnExit = make_scope_exit([&]() { verify(); }); #endif @@ -757,9 +753,7 @@ LazyCallGraph::RefSCC::switchInternalEdgeToRef(Node &SourceN, Node &TargetN) { assert((*SourceN)[TargetN].isCall() && "Must start with a call edge!"); -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and when this - // routine finishes. +#ifdef EXPENSIVE_CHECKS verify(); auto VerifyOnExit = make_scope_exit([&]() { verify(); }); #endif @@ -956,8 +950,7 @@ // just flip the edge here. SourceN->setEdgeKind(TargetN, Edge::Call); -#ifndef NDEBUG - // Check that the RefSCC is still valid. +#ifdef EXPENSIVE_CHECKS verify(); #endif } @@ -978,8 +971,7 @@ // just flip the edge here. SourceN->setEdgeKind(TargetN, Edge::Ref); -#ifndef NDEBUG - // Check that the RefSCC is still valid. +#ifdef EXPENSIVE_CHECKS verify(); #endif } @@ -991,8 +983,7 @@ SourceN->insertEdgeInternal(TargetN, Edge::Ref); -#ifndef NDEBUG - // Check that the RefSCC is still valid. +#ifdef EXPENSIVE_CHECKS verify(); #endif } @@ -1011,8 +1002,7 @@ "Target must be a descendant of the Source."); #endif -#ifndef NDEBUG - // Check that the RefSCC is still valid. +#ifdef EXPENSIVE_CHECKS verify(); #endif } @@ -1029,9 +1019,7 @@ SmallVector DeletedRefSCCs; -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and when this - // routine finishes. +#ifdef EXPENSIVE_CHECKS verify(); auto VerifyOnExit = make_scope_exit([&]() { verify(); }); #endif @@ -1167,9 +1155,7 @@ assert(G->lookupRefSCC(TargetN) != this && "The target must not be a member of this RefSCC"); -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and when this - // routine finishes. +#ifdef EXPENSIVE_CHECKS verify(); auto VerifyOnExit = make_scope_exit([&]() { verify(); }); #endif @@ -1186,10 +1172,10 @@ // We return a list of the resulting *new* RefSCCs in post-order. SmallVector Result; -#ifndef NDEBUG - // In a debug build, verify the RefSCC is valid to start with and that either - // we return an empty list of result RefSCCs and this RefSCC remains valid, - // or we return new RefSCCs and this RefSCC is dead. +#ifdef EXPENSIVE_CHECKS + // Verify the RefSCC is valid to start with and that either we return an empty + // list of result RefSCCs and this RefSCC remains valid, or we return new + // RefSCCs and this RefSCC is dead. verify(); auto VerifyOnExit = make_scope_exit([&]() { // If we didn't replace our RefSCC with new ones, check that this one @@ -1407,7 +1393,7 @@ SCCs.clear(); SCCIndices.clear(); -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS // Verify the new RefSCCs we've built. for (RefSCC *RC : Result) RC->verify(); @@ -1419,11 +1405,9 @@ void LazyCallGraph::RefSCC::insertTrivialCallEdge(Node &SourceN, Node &TargetN) { -#ifndef NDEBUG - // Check that the RefSCC is still valid when we finish. +#ifdef EXPENSIVE_CHECKS auto ExitVerifier = make_scope_exit([this] { verify(); }); -#ifdef EXPENSIVE_CHECKS // Check that we aren't breaking some invariants of the SCC graph. Note that // this is quadratic in the number of edges in the call graph! SCC &SourceC = *G->lookupSCC(SourceN); @@ -1431,8 +1415,7 @@ if (&SourceC != &TargetC) assert(SourceC.isAncestorOf(TargetC) && "Call edge is not trivial in the SCC graph!"); -#endif // EXPENSIVE_CHECKS -#endif // NDEBUG +#endif // First insert it into the source or find the existing edge. auto InsertResult = @@ -1450,19 +1433,16 @@ } void LazyCallGraph::RefSCC::insertTrivialRefEdge(Node &SourceN, Node &TargetN) { -#ifndef NDEBUG - // Check that the RefSCC is still valid when we finish. +#ifdef EXPENSIVE_CHECKS auto ExitVerifier = make_scope_exit([this] { verify(); }); -#ifdef EXPENSIVE_CHECKS // Check that we aren't breaking some invariants of the RefSCC graph. RefSCC &SourceRC = *G->lookupRefSCC(SourceN); RefSCC &TargetRC = *G->lookupRefSCC(TargetN); if (&SourceRC != &TargetRC) assert(SourceRC.isAncestorOf(TargetRC) && "Ref edge is not trivial in the RefSCC graph!"); -#endif // EXPENSIVE_CHECKS -#endif // NDEBUG +#endif // First insert it into the source or find the existing edge. auto InsertResult = @@ -1478,8 +1458,7 @@ void LazyCallGraph::RefSCC::replaceNodeFunction(Node &N, Function &NewF) { Function &OldF = N.getFunction(); -#ifndef NDEBUG - // Check that the RefSCC is still valid when we finish. +#ifdef EXPENSIVE_CHECKS auto ExitVerifier = make_scope_exit([this] { verify(); }); assert(G->lookupRefSCC(N) == this && @@ -1638,7 +1617,7 @@ SCC *OriginalC = lookupSCC(OriginalN); RefSCC *OriginalRC = lookupRefSCC(OriginalN); -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS OriginalRC->verify(); auto VerifyOnExit = make_scope_exit([&]() { OriginalRC->verify(); }); #endif @@ -1717,14 +1696,12 @@ Node &OriginalN = get(OriginalFunction); RefSCC *OriginalRC = lookupRefSCC(OriginalN); -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS OriginalRC->verify(); auto VerifyOnExit = make_scope_exit([&]() { OriginalRC->verify(); -#ifdef EXPENSIVE_CHECKS for (Function *NewFunction : NewFunctions) lookupRefSCC(get(*NewFunction))->verify(); -#endif }); #endif @@ -1979,7 +1956,7 @@ (void)Inserted; assert(Inserted && "Cannot already have this RefSCC in the index map!"); PostOrderRefSCCs.push_back(NewRC); -#ifndef NDEBUG +#ifdef EXPENSIVE_CHECKS NewRC->verify(); #endif });