From c8466f937cc2dbc80412dcfcb1051bf74f399a80 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 16 Oct 2018 06:34:53 +0000 Subject: [PATCH] [NFC] Turn isGuaranteedToExecute into a method llvm-svn: 344587 --- llvm/include/llvm/Analysis/MustExecute.h | 11 +++++------ llvm/lib/Analysis/MustExecute.cpp | 16 ++++++++-------- llvm/lib/Transforms/Scalar/LICM.cpp | 6 +++--- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/llvm/include/llvm/Analysis/MustExecute.h b/llvm/include/llvm/Analysis/MustExecute.h index 40a0273..8238747 100644 --- a/llvm/include/llvm/Analysis/MustExecute.h +++ b/llvm/include/llvm/Analysis/MustExecute.h @@ -82,15 +82,14 @@ public: /// LoopSafetyInfo. Some callers rely on this fact. void computeLoopSafetyInfo(Loop *); + /// Returns true if the instruction in a loop is guaranteed to execute at + /// least once (under the assumption that the loop is entered). + bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, + const Loop *CurLoop) const; + LoopSafetyInfo() = default; }; -/// Returns true if the instruction in a loop is guaranteed to execute at least -/// once (under the assumption that the loop is entered). -bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, - const Loop *CurLoop, - const LoopSafetyInfo *SafetyInfo); - } #endif diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index 79ec8e4..7c1ce86 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -176,9 +176,9 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, /// Returns true if the instruction in a loop is guaranteed to execute at least /// once. -bool llvm::isGuaranteedToExecute(const Instruction &Inst, - const DominatorTree *DT, const Loop *CurLoop, - const LoopSafetyInfo *SafetyInfo) { +bool LoopSafetyInfo::isGuaranteedToExecute(const Instruction &Inst, + const DominatorTree *DT, + const Loop *CurLoop) const { // We have to check to make sure that the instruction dominates all // of the exit blocks. If it doesn't, then there is a path out of the loop // which does not execute this instruction, so we can't hoist it. @@ -191,17 +191,17 @@ bool llvm::isGuaranteedToExecute(const Instruction &Inst, // Inst unless we can prove that Inst comes before the potential implicit // exit. At the moment, we use a (cheap) hack for the common case where // the instruction of interest is the first one in the block. - return !SafetyInfo->headerMayThrow() || - Inst.getParent()->getFirstNonPHIOrDbg() == &Inst; + return !headerMayThrow() || + Inst.getParent()->getFirstNonPHIOrDbg() == &Inst; // Somewhere in this loop there is an instruction which may throw and make us // exit the loop. - if (SafetyInfo->anyBlockMayThrow()) + if (anyBlockMayThrow()) return false; // If there is a path from header to exit or latch that doesn't lead to our // instruction's block, return false. - if (!SafetyInfo->allLoopPathsLeadToBlock(CurLoop, Inst.getParent(), DT)) + if (!allLoopPathsLeadToBlock(CurLoop, Inst.getParent(), DT)) return false; return true; @@ -242,7 +242,7 @@ static bool isMustExecuteIn(const Instruction &I, Loop *L, DominatorTree *DT) { // caller actually gets the full power at the moment. LoopSafetyInfo LSI; LSI.computeLoopSafetyInfo(L); - return isGuaranteedToExecute(I, DT, L, &LSI) || + return LSI.isGuaranteedToExecute(I, DT, L) || isGuaranteedToExecuteForEveryIteration(&I, L); } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 601d49f..9bf75a4 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1116,7 +1116,7 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop, // The check on hasMetadataOtherThanDebugLoc is to prevent us from burning // time in isGuaranteedToExecute if we don't actually have anything to // drop. It is a compile time optimization, not required for correctness. - !isGuaranteedToExecute(I, DT, CurLoop, SafetyInfo)) + !SafetyInfo->isGuaranteedToExecute(I, DT, CurLoop)) I.dropUnknownNonDebugMetadata(); // Move the new node to the Preheader, before its terminator. @@ -1150,7 +1150,7 @@ static bool isSafeToExecuteUnconditionally(Instruction &Inst, return true; bool GuaranteedToExecute = - isGuaranteedToExecute(Inst, DT, CurLoop, SafetyInfo); + SafetyInfo->isGuaranteedToExecute(Inst, DT, CurLoop); if (!GuaranteedToExecute) { auto *LI = dyn_cast(&Inst); @@ -1408,7 +1408,7 @@ bool llvm::promoteLoopAccessesToScalars( if (!DereferenceableInPH || !SafeToInsertStore || (InstAlignment > Alignment)) { - if (isGuaranteedToExecute(*UI, DT, CurLoop, SafetyInfo)) { + if (SafetyInfo->isGuaranteedToExecute(*UI, DT, CurLoop)) { DereferenceableInPH = true; SafeToInsertStore = true; Alignment = std::max(Alignment, InstAlignment); diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 13e6bd1..cd49f51 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -721,7 +721,7 @@ bool LoopUnswitch::processCurrentLoop() { // This is a workaround for the discrepancy between LLVM IR and MSan // semantics. See PR28054 for more details. if (SanitizeMemory && - !isGuaranteedToExecute(*TI, DT, currentLoop, &SafetyInfo)) + !SafetyInfo.isGuaranteedToExecute(*TI, DT, currentLoop)) continue; if (BranchInst *BI = dyn_cast(TI)) { -- 2.7.4