Index: llvm/include/llvm/Passes/StandardInstrumentations.h =================================================================== --- llvm/include/llvm/Passes/StandardInstrumentations.h +++ llvm/include/llvm/Passes/StandardInstrumentations.h @@ -145,7 +145,7 @@ FunctionAnalysisManager::Invalidator &); }; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallVector PassStack; #endif Index: llvm/include/llvm/Support/GenericDomTreeConstruction.h =================================================================== --- llvm/include/llvm/Support/GenericDomTreeConstruction.h +++ llvm/include/llvm/Support/GenericDomTreeConstruction.h @@ -643,7 +643,7 @@ Bucket; SmallDenseSet Visited; SmallVector Affected; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallVector VisitedUnaffected; #endif }; @@ -852,7 +852,7 @@ TN->setIDom(NCD); } -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS for (const TreeNodePtr TN : II.VisitedUnaffected) assert(TN->getLevel() == TN->getIDom()->getLevel() + 1 && "TN should have been updated by an affected ancestor"); @@ -918,7 +918,7 @@ LLVM_DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> " << BlockNamePrinter(To) << "\n"); -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS // Ensure that the edge was in fact deleted from the CFG before informing // the DomTree about it. // The check is O(N), so run it only in debug configuration. Index: llvm/include/llvm/Transforms/Scalar/JumpThreading.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/JumpThreading.h +++ llvm/include/llvm/Transforms/Scalar/JumpThreading.h @@ -85,7 +85,7 @@ std::unique_ptr BPI; bool HasProfileData = false; bool HasGuards = false; -#ifdef NDEBUG +#ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallPtrSet LoopHeaders; #else SmallSet, 16> LoopHeaders; Index: llvm/include/llvm/Transforms/Scalar/LoopPassManager.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -269,7 +269,7 @@ } void setParentLoop(Loop *L) { -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS ParentL = L; #endif } @@ -308,7 +308,7 @@ /// loops within them will be visited in postorder as usual for the loop pass /// manager. void addSiblingLoops(ArrayRef NewSibLoops) { -#ifndef NDEBUG +#if defined(LLVM_ENABLE_ABI_BREAKING_CHECKS) && !defined(NDEBUG) for (Loop *NewL : NewSibLoops) assert(NewL->getParentLoop() == ParentL && "All of the new loops must be siblings of the current loop!"); @@ -349,7 +349,7 @@ bool SkipCurrentLoop; const bool LoopNestMode; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS // In debug builds we also track the parent loop to implement asserts even in // the face of loop deletion. Loop *ParentL; Index: llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h =================================================================== --- llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h +++ llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h @@ -160,7 +160,7 @@ /// consistent when instructions are moved. SmallVector InsertPointGuards; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS const char *DebugType; #endif @@ -176,7 +176,7 @@ Builder(se.getContext(), TargetFolder(DL), IRBuilderCallbackInserter( [this](Instruction *I) { rememberInstruction(I); })) { -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS DebugType = ""; #endif } @@ -186,7 +186,7 @@ assert(InsertPointGuards.empty()); } -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS void setDebugType(const char *s) { DebugType = s; } #endif Index: llvm/lib/Passes/StandardInstrumentations.cpp =================================================================== --- llvm/lib/Passes/StandardInstrumentations.cpp +++ llvm/lib/Passes/StandardInstrumentations.cpp @@ -1086,7 +1086,9 @@ PIC.registerBeforeNonSkippedPassCallback( [this, &FAM](StringRef P, Any IR) { +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS assert(&PassStack.emplace_back(P)); +#endif (void)this; if (!any_isa(IR)) return; @@ -1098,16 +1100,20 @@ PIC.registerAfterPassInvalidatedCallback( [this](StringRef P, const PreservedAnalyses &PassPA) { +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS assert(PassStack.pop_back_val() == P && "Before and After callbacks must correspond"); +#endif (void)this; }); PIC.registerAfterPassCallback([this, &FAM, checkCFG](StringRef P, Any IR, const PreservedAnalyses &PassPA) { +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS assert(PassStack.pop_back_val() == P && "Before and After callbacks must correspond"); +#endif (void)this; if (!any_isa(IR)) Index: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp =================================================================== --- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -29,6 +29,12 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/LoopUtils.h" +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS +#define SCEV_DEBUG_WITH_TYPE(TYPE, X) DEBUG_WITH_TYPE(TYPE, X) +#else +#define SCEV_DEBUG_WITH_TYPE(TYPE, X) +#endif + using namespace llvm; cl::opt llvm::SCEVCheapExpansionBudget( @@ -1225,7 +1231,7 @@ // We should not look for a incomplete PHI. Getting SCEV for a incomplete // PHI has no meaning at all. if (!PN.isComplete()) { - DEBUG_WITH_TYPE( + SCEV_DEBUG_WITH_TYPE( DebugType, dbgs() << "One incomplete PHI is found: " << PN << "\n"); continue; } @@ -2086,8 +2092,9 @@ Phi->replaceAllUsesWith(V); DeadInsts.emplace_back(Phi); ++NumElim; - DEBUG_WITH_TYPE(DebugType, dbgs() - << "INDVARS: Eliminated constant iv: " << *Phi << '\n'); + SCEV_DEBUG_WITH_TYPE(DebugType, + dbgs() << "INDVARS: Eliminated congruent iv.inc: " + << *IsomorphicInc << '\n'); continue; } @@ -2144,7 +2151,7 @@ TruncExpr == SE.getSCEV(IsomorphicInc) && SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc) && hoistIVInc(OrigInc, IsomorphicInc)) { - DEBUG_WITH_TYPE(DebugType, + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv.inc: " << *IsomorphicInc << '\n'); Value *NewInc = OrigInc; @@ -2165,9 +2172,9 @@ } } } - DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv: " + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv: " << *Phi << '\n'); - DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Original iv: " + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Original iv: " << *OrigPhiRef << '\n'); ++NumElim; Value *NewIV = OrigPhiRef;