From 1540da3b788272e9aacc698ef96e75a4a5839ee1 Mon Sep 17 00:00:00 2001 From: Neil Henning Date: Mon, 14 Jun 2021 12:13:18 +0100 Subject: [PATCH] ABI breaking changes fixes. This commit mostly just replaces bad uses of `NDEBUG` with uses of `LLVM_ENABLE_ABI_BREAKING_CHANGES` - the safe way to include ABI breaking changes (normally extra struct elements in headers). Differential Revision: https://reviews.llvm.org/D104216 --- .../include/llvm/Passes/StandardInstrumentations.h | 2 +- .../llvm/Support/GenericDomTreeConstruction.h | 6 ++--- .../include/llvm/Transforms/Scalar/JumpThreading.h | 2 +- .../llvm/Transforms/Scalar/LoopPassManager.h | 6 ++--- .../Transforms/Utils/ScalarEvolutionExpander.h | 6 ++--- llvm/lib/Passes/StandardInstrumentations.cpp | 6 +++++ .../Transforms/Utils/ScalarEvolutionExpander.cpp | 28 ++++++++++++++-------- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h index 5fadb6f..9011c52 100644 --- a/llvm/include/llvm/Passes/StandardInstrumentations.h +++ b/llvm/include/llvm/Passes/StandardInstrumentations.h @@ -145,7 +145,7 @@ public: FunctionAnalysisManager::Invalidator &); }; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallVector PassStack; #endif diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h index 4b59ad1..c476ccb 100644 --- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h +++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h @@ -643,7 +643,7 @@ struct SemiNCAInfo { Bucket; SmallDenseSet Visited; SmallVector Affected; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallVector VisitedUnaffected; #endif }; @@ -852,7 +852,7 @@ struct SemiNCAInfo { 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 @@ struct SemiNCAInfo { 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. diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h index 951f4e4..816ea10 100644 --- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h +++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h @@ -85,7 +85,7 @@ class JumpThreadingPass : public PassInfoMixin { std::unique_ptr BPI; bool HasProfileData = false; bool HasGuards = false; -#ifdef NDEBUG +#ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS SmallPtrSet LoopHeaders; #else SmallSet, 16> LoopHeaders; diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h index 480f5e5..69ee7c7 100644 --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -269,7 +269,7 @@ public: } void setParentLoop(Loop *L) { -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS ParentL = L; #endif } @@ -308,7 +308,7 @@ public: /// 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 @@ private: 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; diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h index 5d93408..8662dbf 100644 --- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h +++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h @@ -160,7 +160,7 @@ class SCEVExpander : public SCEVVisitor { /// consistent when instructions are moved. SmallVector InsertPointGuards; -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS const char *DebugType; #endif @@ -176,7 +176,7 @@ public: 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 @@ public: assert(InsertPointGuards.empty()); } -#ifndef NDEBUG +#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS void setDebugType(const char *s) { DebugType = s; } #endif diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index b28f4ba..a03e0d4 100644 --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -1086,7 +1086,9 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks( 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 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks( 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)) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 2f851c48..b62b26e 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/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 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized, // 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 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, 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 constant iv: " << *Phi + << '\n'); continue; } @@ -2144,9 +2151,9 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, TruncExpr == SE.getSCEV(IsomorphicInc) && SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc) && hoistIVInc(OrigInc, IsomorphicInc)) { - DEBUG_WITH_TYPE(DebugType, - dbgs() << "INDVARS: Eliminated congruent iv.inc: " - << *IsomorphicInc << '\n'); + SCEV_DEBUG_WITH_TYPE( + DebugType, dbgs() << "INDVARS: Eliminated congruent iv.inc: " + << *IsomorphicInc << '\n'); Value *NewInc = OrigInc; if (OrigInc->getType() != IsomorphicInc->getType()) { Instruction *IP = nullptr; @@ -2165,10 +2172,11 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, } } } - DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv: " - << *Phi << '\n'); - DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Original iv: " - << *OrigPhiRef << '\n'); + SCEV_DEBUG_WITH_TYPE(DebugType, + dbgs() << "INDVARS: Eliminated congruent iv: " << *Phi + << '\n'); + SCEV_DEBUG_WITH_TYPE( + DebugType, dbgs() << "INDVARS: Original iv: " << *OrigPhiRef << '\n'); ++NumElim; Value *NewIV = OrigPhiRef; if (OrigPhiRef->getType() != Phi->getType()) { -- 2.7.4