[mlir] Use std::optional instead of llvm::Optional (NFC)
authorKazu Hirata <kazu@google.com>
Wed, 15 Feb 2023 04:33:36 +0000 (20:33 -0800)
committerKazu Hirata <kazu@google.com>
Wed, 15 Feb 2023 04:33:36 +0000 (20:33 -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

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
mlir/lib/Transforms/Utils/DialectConversion.cpp

index 1b640bf..48ba158 100644 (file)
@@ -11,6 +11,7 @@
 #include "mlir/Conversion/LLVMCommon/MemRefBuilder.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
+#include <optional>
 
 using namespace mlir;
 
@@ -398,7 +399,7 @@ FailureOr<unsigned>
 LLVMTypeConverter::getMemRefAddressSpace(BaseMemRefType type) {
   if (!type.getMemorySpace()) // Default memory space -> 0.
     return 0;
-  Optional<Attribute> converted =
+  std::optional<Attribute> converted =
       convertTypeAttribute(type, type.getMemorySpace());
   if (!converted)
     return failure();
index 284e099..e74829a 100644 (file)
@@ -23,6 +23,7 @@
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/Debug.h"
 #include <numeric>
+#include <optional>
 
 using namespace mlir;
 
@@ -683,7 +684,7 @@ static std::optional<int64_t> getLowerBound(Value iv) {
 }
 
 /// Gets the constant upper bound on an affine.for `iv`.
-static Optional<int64_t> getUpperBound(Value iv) {
+static std::optional<int64_t> getUpperBound(Value iv) {
   AffineForOp forOp = getForInductionVarOwner(iv);
   if (!forOp || !forOp.hasConstantUpperBound())
     return std::nullopt;
@@ -708,8 +709,9 @@ static Optional<int64_t> getUpperBound(Value iv) {
 /// will lead a none being returned.
 static std::optional<int64_t>
 getBoundForExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols,
-                ArrayRef<Optional<int64_t>> constLowerBounds,
-                ArrayRef<Optional<int64_t>> constUpperBounds, bool isUpper) {
+                ArrayRef<std::optional<int64_t>> constLowerBounds,
+                ArrayRef<std::optional<int64_t>> constUpperBounds,
+                bool isUpper) {
   // Handle divs and mods.
   if (auto binOpExpr = expr.dyn_cast<AffineBinaryOpExpr>()) {
     // If the LHS of a floor or ceil is bounded and the RHS is a constant, we
@@ -787,11 +789,11 @@ getBoundForExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols,
 /// Determine a constant upper bound for `expr` if one exists while exploiting
 /// values in `operands`. Note that the upper bound is an inclusive one. `expr`
 /// is guaranteed to be less than or equal to it.
-static Optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
-                                       unsigned numSymbols,
-                                       ArrayRef<Value> operands) {
+static std::optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
+                                            unsigned numSymbols,
+                                            ArrayRef<Value> operands) {
   // Get the constant lower or upper bounds on the operands.
-  SmallVector<Optional<int64_t>> constLowerBounds, constUpperBounds;
+  SmallVector<std::optional<int64_t>> constLowerBounds, constUpperBounds;
   constLowerBounds.reserve(operands.size());
   constUpperBounds.reserve(operands.size());
   for (Value operand : operands) {
@@ -810,11 +812,11 @@ static Optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
 /// Determine a constant lower bound for `expr` if one exists while exploiting
 /// values in `operands`. Note that the upper bound is an inclusive one. `expr`
 /// is guaranteed to be less than or equal to it.
-static Optional<int64_t> getLowerBound(AffineExpr expr, unsigned numDims,
-                                       unsigned numSymbols,
-                                       ArrayRef<Value> operands) {
+static std::optional<int64_t> getLowerBound(AffineExpr expr, unsigned numDims,
+                                            unsigned numSymbols,
+                                            ArrayRef<Value> operands) {
   // Get the constant lower or upper bounds on the operands.
-  SmallVector<Optional<int64_t>> constLowerBounds, constUpperBounds;
+  SmallVector<std::optional<int64_t>> constLowerBounds, constUpperBounds;
   constLowerBounds.reserve(operands.size());
   constUpperBounds.reserve(operands.size());
   for (Value operand : operands) {
@@ -822,7 +824,7 @@ static Optional<int64_t> getLowerBound(AffineExpr expr, unsigned numDims,
     constUpperBounds.push_back(getUpperBound(operand));
   }
 
-  Optional<int64_t> lowerBound;
+  std::optional<int64_t> lowerBound;
   if (auto constExpr = expr.dyn_cast<AffineConstantExpr>()) {
     lowerBound = constExpr.getValue();
   } else {
index fed3bd1..1349113 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/Debug.h"
+#include <optional>
 
 #define DEBUG_TYPE "transform-dialect"
 #define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "] ")
@@ -26,7 +27,7 @@
 using namespace mlir;
 
 static ParseResult parseSequenceOpOperands(
-    OpAsmParser &parser, Optional<OpAsmParser::UnresolvedOperand> &root,
+    OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &root,
     Type &rootType,
     SmallVectorImpl<OpAsmParser::UnresolvedOperand> &extraBindings,
     SmallVectorImpl<Type> &extraBindingTypes);
@@ -666,7 +667,7 @@ transform::SequenceOp::apply(transform::TransformResults &results,
 }
 
 static ParseResult parseSequenceOpOperands(
-    OpAsmParser &parser, Optional<OpAsmParser::UnresolvedOperand> &root,
+    OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &root,
     Type &rootType,
     SmallVectorImpl<OpAsmParser::UnresolvedOperand> &extraBindings,
     SmallVectorImpl<Type> &extraBindingTypes) {
index d0641ed..b82fc58 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include <optional>
 
 using namespace mlir;
 using namespace mlir::detail;
@@ -3088,8 +3089,8 @@ Attribute TypeConverter::AttributeConversionResult::getResult() const {
   return impl.getPointer();
 }
 
-Optional<Attribute> TypeConverter::convertTypeAttribute(Type type,
-                                                        Attribute attr) {
+std::optional<Attribute> TypeConverter::convertTypeAttribute(Type type,
+                                                             Attribute attr) {
   for (TypeAttributeConversionCallbackFn &fn :
        llvm::reverse(typeAttributeConversions)) {
     AttributeConversionResult res = fn(type, attr);