forked from OSchip/llvm-project
[NFC] Turn isGuaranteedToExecute into a method
llvm-svn: 344587
This commit is contained in:
parent
f12a43d38a
commit
c8466f937c
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<LoadInst>(&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);
|
||||
|
|
|
@ -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<BranchInst>(TI)) {
|
||||
|
|
Loading…
Reference in New Issue