[Mlir-commits] [mlir] 0542390 - [mlir] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata llvmlistbot at llvm.org
Tue Feb 14 20:33:42 PST 2023


Author: Kazu Hirata
Date: 2023-02-14T20:33:36-08:00
New Revision: 05423905d064c196f745a57050e3e918b0243765

URL: https://github.com/llvm/llvm-project/commit/05423905d064c196f745a57050e3e918b0243765
DIFF: https://github.com/llvm/llvm-project/commit/05423905d064c196f745a57050e3e918b0243765.diff

LOG: [mlir] Use std::optional instead of llvm::Optional (NFC)

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index 1b640bfd83a17..48ba15849cc2e 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -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();

diff  --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 284e099fb4a9e..e74829ac7758d 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -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 {

diff  --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index fed3bd1aea1e5..134911322a4b3 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -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) {

diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index d0641ed0eccb6..b82fc580d2ebd 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -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);


        


More information about the Mlir-commits mailing list