aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp b/contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp
index 693b9ebd450a..69bcbcb11203 100644
--- a/contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp
+++ b/contrib/llvm-project/llvm/lib/Analysis/LoopInfo.cpp
@@ -68,15 +68,16 @@ bool Loop::hasLoopInvariantOperands(const Instruction *I) const {
}
bool Loop::makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt,
- MemorySSAUpdater *MSSAU) const {
+ MemorySSAUpdater *MSSAU,
+ ScalarEvolution *SE) const {
if (Instruction *I = dyn_cast<Instruction>(V))
- return makeLoopInvariant(I, Changed, InsertPt, MSSAU);
+ return makeLoopInvariant(I, Changed, InsertPt, MSSAU, SE);
return true; // All non-instructions are loop-invariant.
}
bool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
- Instruction *InsertPt,
- MemorySSAUpdater *MSSAU) const {
+ Instruction *InsertPt, MemorySSAUpdater *MSSAU,
+ ScalarEvolution *SE) const {
// Test if the value is already loop-invariant.
if (isLoopInvariant(I))
return true;
@@ -97,7 +98,7 @@ bool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
}
// Don't hoist instructions with loop-variant operands.
for (Value *Operand : I->operands())
- if (!makeLoopInvariant(Operand, Changed, InsertPt, MSSAU))
+ if (!makeLoopInvariant(Operand, Changed, InsertPt, MSSAU, SE))
return false;
// Hoist.
@@ -113,6 +114,9 @@ bool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
// information to the optimizer.
I->dropUnknownNonDebugMetadata();
+ if (SE)
+ SE->forgetBlockAndLoopDispositions(I);
+
Changed = true;
return true;
}
@@ -194,17 +198,17 @@ static Value *findFinalIVValue(const Loop &L, const PHINode &IndVar,
return nullptr;
}
-Optional<Loop::LoopBounds> Loop::LoopBounds::getBounds(const Loop &L,
- PHINode &IndVar,
- ScalarEvolution &SE) {
+std::optional<Loop::LoopBounds>
+Loop::LoopBounds::getBounds(const Loop &L, PHINode &IndVar,
+ ScalarEvolution &SE) {
InductionDescriptor IndDesc;
if (!InductionDescriptor::isInductionPHI(&IndVar, &L, &SE, IndDesc))
- return None;
+ return std::nullopt;
Value *InitialIVValue = IndDesc.getStartValue();
Instruction *StepInst = IndDesc.getInductionBinOp();
if (!InitialIVValue || !StepInst)
- return None;
+ return std::nullopt;
const SCEV *Step = IndDesc.getStep();
Value *StepInstOp1 = StepInst->getOperand(1);
@@ -217,7 +221,7 @@ Optional<Loop::LoopBounds> Loop::LoopBounds::getBounds(const Loop &L,
Value *FinalIVValue = findFinalIVValue(L, IndVar, *StepInst);
if (!FinalIVValue)
- return None;
+ return std::nullopt;
return LoopBounds(L, *InitialIVValue, *StepInst, StepValue, *FinalIVValue,
SE);
@@ -280,11 +284,11 @@ Direction Loop::LoopBounds::getDirection() const {
return Direction::Unknown;
}
-Optional<Loop::LoopBounds> Loop::getBounds(ScalarEvolution &SE) const {
+std::optional<Loop::LoopBounds> Loop::getBounds(ScalarEvolution &SE) const {
if (PHINode *IndVar = getInductionVariable(SE))
return LoopBounds::getBounds(*this, *IndVar, SE);
- return None;
+ return std::nullopt;
}
PHINode *Loop::getInductionVariable(ScalarEvolution &SE) const {
@@ -1045,11 +1049,11 @@ MDNode *llvm::findOptionMDForLoop(const Loop *TheLoop, StringRef Name) {
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
/// operand or null otherwise. If the string metadata is not found return
/// Optional's not-a-value.
-Optional<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
- StringRef Name) {
+std::optional<const MDOperand *>
+llvm::findStringMetadataForLoop(const Loop *TheLoop, StringRef Name) {
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
if (!MD)
- return None;
+ return std::nullopt;
switch (MD->getNumOperands()) {
case 1:
return nullptr;
@@ -1060,11 +1064,11 @@ Optional<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
}
}
-Optional<bool> llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop,
- StringRef Name) {
+std::optional<bool> llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop,
+ StringRef Name) {
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
if (!MD)
- return None;
+ return std::nullopt;
switch (MD->getNumOperands()) {
case 1:
// When the value is absent it is interpreted as 'attribute set'.
@@ -1082,16 +1086,16 @@ bool llvm::getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name) {
return getOptionalBoolLoopAttribute(TheLoop, Name).value_or(false);
}
-llvm::Optional<int> llvm::getOptionalIntLoopAttribute(const Loop *TheLoop,
- StringRef Name) {
+std::optional<int> llvm::getOptionalIntLoopAttribute(const Loop *TheLoop,
+ StringRef Name) {
const MDOperand *AttrMD =
findStringMetadataForLoop(TheLoop, Name).value_or(nullptr);
if (!AttrMD)
- return None;
+ return std::nullopt;
ConstantInt *IntMD = mdconst::extract_or_null<ConstantInt>(AttrMD->get());
if (!IntMD)
- return None;
+ return std::nullopt;
return IntMD->getSExtValue();
}