[Analysis] Teach getOptionalIntLoopAttribute to return std::optional (NFC)
authorKazu Hirata <kazu@google.com>
Sat, 19 Nov 2022 23:36:50 +0000 (15:36 -0800)
committerKazu Hirata <kazu@google.com>
Sat, 19 Nov 2022 23:36:50 +0000 (15:36 -0800)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

llvm/include/llvm/Analysis/LoopInfo.h
llvm/lib/Analysis/LoopInfo.cpp
llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp

index eb0b9ef..865b17b 100644 (file)
@@ -49,6 +49,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/Allocator.h"
 #include <algorithm>
+#include <optional>
 #include <utility>
 
 namespace llvm {
@@ -1333,8 +1334,8 @@ Optional<bool> getOptionalBoolLoopAttribute(const Loop *TheLoop,
 bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name);
 
 /// Find named metadata for a loop with an integer value.
-llvm::Optional<int>
-getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name);
+std::optional<int> getOptionalIntLoopAttribute(const Loop *TheLoop,
+                                               StringRef Name);
 
 /// Find named metadata for a loop with an integer value. Return \p Default if
 /// not set.
index 90077aa..057fc93 100644 (file)
@@ -1086,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();
 }
index 8367e61..eeed11c 100644 (file)
@@ -50,7 +50,7 @@ static void warnAboutLeftoverTransformations(Loop *L,
     LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
     Optional<ElementCount> VectorizeWidth =
         getOptionalElementCountLoopAttribute(L);
-    Optional<int> InterleaveCount =
+    std::optional<int> InterleaveCount =
         getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
 
     if (!VectorizeWidth || VectorizeWidth->isVector())
index 636392a..b69735a 100644 (file)
@@ -249,11 +249,11 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
 
 Optional<ElementCount>
 llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) {
-  Optional<int> Width =
+  std::optional<int> Width =
       getOptionalIntLoopAttribute(TheLoop, "llvm.loop.vectorize.width");
 
   if (Width) {
-    Optional<int> IsScalable = getOptionalIntLoopAttribute(
+    std::optional<int> IsScalable = getOptionalIntLoopAttribute(
         TheLoop, "llvm.loop.vectorize.scalable.enable");
     return ElementCount::get(*Width, IsScalable.value_or(false));
   }
@@ -354,7 +354,7 @@ TransformationMode llvm::hasUnrollTransformation(const Loop *L) {
   if (getBooleanLoopAttribute(L, "llvm.loop.unroll.disable"))
     return TM_SuppressedByUser;
 
-  Optional<int> Count =
+  std::optional<int> Count =
       getOptionalIntLoopAttribute(L, "llvm.loop.unroll.count");
   if (Count)
     return Count.value() == 1 ? TM_SuppressedByUser : TM_ForcedByUser;
@@ -375,7 +375,7 @@ TransformationMode llvm::hasUnrollAndJamTransformation(const Loop *L) {
   if (getBooleanLoopAttribute(L, "llvm.loop.unroll_and_jam.disable"))
     return TM_SuppressedByUser;
 
-  Optional<int> Count =
+  std::optional<int> Count =
       getOptionalIntLoopAttribute(L, "llvm.loop.unroll_and_jam.count");
   if (Count)
     return Count.value() == 1 ? TM_SuppressedByUser : TM_ForcedByUser;
@@ -398,7 +398,7 @@ TransformationMode llvm::hasVectorizeTransformation(const Loop *L) {
 
   Optional<ElementCount> VectorizeWidth =
       getOptionalElementCountLoopAttribute(L);
-  Optional<int> InterleaveCount =
+  std::optional<int> InterleaveCount =
       getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
 
   // 'Forcing' vector width and interleave count to one effectively disables