[Mlir-commits] [mlir] 0de16fa - mlir/DialectConversion: use std::optional (NFC)
Ramkumar Ramachandra
llvmlistbot at llvm.org
Mon Dec 19 09:49:32 PST 2022
Author: Ramkumar Ramachandra
Date: 2022-12-19T18:48:59+01:00
New Revision: 0de16fafa57153a70168d69ca8591dbe8489905f
URL: https://github.com/llvm/llvm-project/commit/0de16fafa57153a70168d69ca8591dbe8489905f
DIFF: https://github.com/llvm/llvm-project/commit/0de16fafa57153a70168d69ca8591dbe8489905f.diff
LOG: mlir/DialectConversion: use std::optional (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch touches DialectConversion, and modifies
existing conversions and tests appropriately.
See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Signed-off-by: Ramkumar Ramachandra <r at artagnon.com>
Differential Revision: https://reviews.llvm.org/D140303
Added:
Modified:
flang/lib/Optimizer/CodeGen/TypeConverter.h
mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp
mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp
mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp
mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/lib/Transforms/TestDialectConversion.cpp
mlir/unittests/Transforms/DialectConversion.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index 737c28193f2d6..c129e1c40cc40 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -138,7 +138,7 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
addSourceMaterialization(
[&](mlir::OpBuilder &builder, mlir::Type resultType,
mlir::ValueRange inputs,
- mlir::Location loc) -> llvm::Optional<mlir::Value> {
+ mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
@@ -148,7 +148,7 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
addTargetMaterialization(
[&](mlir::OpBuilder &builder, mlir::Type resultType,
mlir::ValueRange inputs,
- mlir::Location loc) -> llvm::Optional<mlir::Value> {
+ mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
@@ -163,7 +163,7 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
mlir::Type indexType() { return mlir::IntegerType::get(&getContext(), 64); }
// fir.type<name(p : TY'...){f : TY...}> --> llvm<"%name = { ty... }">
- llvm::Optional<mlir::LogicalResult>
+ std::optional<mlir::LogicalResult>
convertRecordType(fir::RecordType derived,
llvm::SmallVectorImpl<mlir::Type> &results,
llvm::ArrayRef<mlir::Type> callStack) {
diff --git a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h
index 48a82b19501c3..9463ceb4363ef 100644
--- a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h
+++ b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h
@@ -23,23 +23,25 @@ class SPIRVTypeConverter;
namespace spirv {
/// Mapping from numeric MemRef memory spaces into SPIR-V symbolic ones.
using MemorySpaceToStorageClassMap =
- std::function<Optional<spirv::StorageClass>(Attribute)>;
+ std::function<std::optional<spirv::StorageClass>(Attribute)>;
/// Maps MemRef memory spaces to storage classes for Vulkan-flavored SPIR-V
/// using the default rule. Returns std::nullopt if the memory space is unknown.
-Optional<spirv::StorageClass> mapMemorySpaceToVulkanStorageClass(Attribute);
+std::optional<spirv::StorageClass>
+ mapMemorySpaceToVulkanStorageClass(Attribute);
/// Maps storage classes for Vulkan-flavored SPIR-V to MemRef memory spaces
/// using the default rule. Returns std::nullopt if the storage class is
/// unsupported.
-Optional<unsigned> mapVulkanStorageClassToMemorySpace(spirv::StorageClass);
+std::optional<unsigned> mapVulkanStorageClassToMemorySpace(spirv::StorageClass);
/// Maps MemRef memory spaces to storage classes for OpenCL-flavored SPIR-V
/// using the default rule. Returns std::nullopt if the memory space is unknown.
-Optional<spirv::StorageClass> mapMemorySpaceToOpenCLStorageClass(Attribute);
+std::optional<spirv::StorageClass>
+ mapMemorySpaceToOpenCLStorageClass(Attribute);
/// Maps storage classes for OpenCL-flavored SPIR-V to MemRef memory spaces
/// using the default rule. Returns std::nullopt if the storage class is
/// unsupported.
-Optional<unsigned> mapOpenCLStorageClassToMemorySpace(spirv::StorageClass);
+std::optional<unsigned> mapOpenCLStorageClassToMemorySpace(spirv::StorageClass);
/// Type converter for converting numeric MemRef memory spaces into SPIR-V
/// symbolic ones.
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
index 33a0f577f9ca5..daa4d61f7103f 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
@@ -56,7 +56,7 @@ class SPIRVType : public Type {
/// the given `storage` class. This method does not guarantee the uniqueness
/// of extensions; the same extension may be appended multiple times.
void getExtensions(ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
/// The capability requirements for each type are following the
/// ((Capability::A OR Extension::B) AND (Capability::C OR Capability::D))
@@ -68,12 +68,12 @@ class SPIRVType : public Type {
/// uniqueness of capabilities; the same capability may be appended multiple
/// times.
void getCapabilities(CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
/// Returns the size in bytes for each type. If no size can be calculated,
/// returns `std::nullopt`. Note that if the type has explicit layout, it is
/// also taken into account in calculation.
- Optional<int64_t> getSizeInBytes();
+ std::optional<int64_t> getSizeInBytes();
};
// SPIR-V scalar type: bool type, integer type, floating point type.
@@ -89,11 +89,11 @@ class ScalarType : public SPIRVType {
static bool isValid(IntegerType);
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
- Optional<int64_t> getSizeInBytes();
+ std::optional<int64_t> getSizeInBytes();
};
// SPIR-V composite type: VectorType, SPIR-V ArrayType, or SPIR-V StructType.
@@ -117,11 +117,11 @@ class CompositeType : public SPIRVType {
bool hasCompileTimeKnownNumElements() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
- Optional<int64_t> getSizeInBytes();
+ std::optional<int64_t> getSizeInBytes();
};
// SPIR-V array type
@@ -145,13 +145,13 @@ class ArrayType : public Type::TypeBase<ArrayType, CompositeType,
unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
/// Returns the array size in bytes. Since array type may have an explicit
/// stride declaration (in bytes), we also include it in the calculation.
- Optional<int64_t> getSizeInBytes();
+ std::optional<int64_t> getSizeInBytes();
};
// SPIR-V image type
@@ -188,9 +188,9 @@ class ImageType
// TODO: Add support for Access qualifier
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
// SPIR-V pointer type
@@ -206,9 +206,9 @@ class PointerType : public Type::TypeBase<PointerType, SPIRVType,
StorageClass getStorageClass() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
// SPIR-V run-time array type
@@ -230,9 +230,9 @@ class RuntimeArrayType
unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
// SPIR-V sampled image type
@@ -253,9 +253,10 @@ class SampledImageType
Type getImageType() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = std::nullopt);
- void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = std::nullopt);
+ std::optional<spirv::StorageClass> storage = std::nullopt);
+ void
+ getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
+ std::optional<spirv::StorageClass> storage = std::nullopt);
};
/// SPIR-V struct type. Two kinds of struct types are supported:
@@ -389,9 +390,9 @@ class StructType
ArrayRef<MemberDecorationInfo> memberDecorations = {});
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
llvm::hash_code
@@ -416,9 +417,9 @@ class CooperativeMatrixNVType
unsigned getColumns() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
// SPIR-V joint matrix type
@@ -443,9 +444,9 @@ class JointMatrixINTELType
MatrixLayout getMatrixLayout() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
// SPIR-V matrix type
@@ -480,9 +481,9 @@ class MatrixType : public Type::TypeBase<MatrixType, CompositeType,
Type getElementType() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage = std::nullopt);
+ std::optional<StorageClass> storage = std::nullopt);
};
} // namespace spirv
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index 871f4b0251fe1..f024d80e59743 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -54,7 +54,7 @@ class TypeConverter {
ArrayRef<Type> getConvertedTypes() const { return argTypes; }
/// Get the input mapping for the given argument.
- Optional<InputMapping> getInputMapping(unsigned input) const {
+ std::optional<InputMapping> getInputMapping(unsigned input) const {
return remappedInputs[input];
}
@@ -81,7 +81,7 @@ class TypeConverter {
unsigned newInputCount = 1);
/// The remapping information for each of the original arguments.
- SmallVector<Optional<InputMapping>, 4> remappedInputs;
+ SmallVector<std::optional<InputMapping>, 4> remappedInputs;
/// The set of new argument types.
SmallVector<Type, 4> argTypes;
@@ -89,19 +89,20 @@ class TypeConverter {
/// Register a conversion function. A conversion function must be convertible
/// to any of the following forms(where `T` is a class derived from `Type`:
- /// * Optional<Type>(T)
+ /// * std::optional<Type>(T)
/// - This form represents a 1-1 type conversion. It should return nullptr
/// or `std::nullopt` to signify failure. If `std::nullopt` is returned,
/// the converter is allowed to try another conversion function to
/// perform the conversion.
- /// * Optional<LogicalResult>(T, SmallVectorImpl<Type> &)
+ /// * std::optional<LogicalResult>(T, SmallVectorImpl<Type> &)
/// - This form represents a 1-N type conversion. It should return
/// `failure` or `std::nullopt` to signify a failed conversion. If the
/// new set of types is empty, the type is removed and any usages of the
/// existing value are expected to be removed during conversion. If
/// `std::nullopt` is returned, the converter is allowed to try another
/// conversion function to perform the conversion.
- /// * Optional<LogicalResult>(T, SmallVectorImpl<Type> &, ArrayRef<Type>)
+ /// * std::optional<LogicalResult>(T, SmallVectorImpl<Type> &,
+ /// ArrayRef<Type>)
/// - This form represents a 1-N type conversion supporting recursive
/// types. The first two arguments and the return value are the same as
/// for the regular 1-N form. The third argument is contains is the
@@ -119,7 +120,7 @@ class TypeConverter {
/// Register a materialization function, which must be convertible to the
/// following form:
- /// `Optional<Value>(OpBuilder &, T, ValueRange, Location)`,
+ /// `std::optional<Value>(OpBuilder &, T, ValueRange, Location)`,
/// where `T` is any subclass of `Type`. This function is responsible for
/// creating an operation, using the OpBuilder and Location provided, that
/// "casts" a range of values into a single value of the given type `T`. It
@@ -203,7 +204,7 @@ class TypeConverter {
/// This function converts the type signature of the given block, by invoking
/// 'convertSignatureArg' for each argument. This function should return a
/// valid conversion for the signature on success, std::nullopt otherwise.
- Optional<SignatureConversion> convertBlockSignature(Block *block);
+ std::optional<SignatureConversion> convertBlockSignature(Block *block);
/// Materialize a conversion from a set of types into one result type by
/// generating a cast sequence of some kind. See the respective
@@ -229,12 +230,12 @@ class TypeConverter {
/// The signature of the callback used to convert a type. If the new set of
/// types is empty, the type is removed and any usages of the existing value
/// are expected to be removed during conversion.
- using ConversionCallbackFn = std::function<Optional<LogicalResult>(
+ using ConversionCallbackFn = std::function<std::optional<LogicalResult>(
Type, SmallVectorImpl<Type> &, ArrayRef<Type>)>;
/// The signature of the callback used to materialize a conversion.
- using MaterializationCallbackFn =
- std::function<Optional<Value>(OpBuilder &, Type, ValueRange, Location)>;
+ using MaterializationCallbackFn = std::function<std::optional<Value>(
+ OpBuilder &, Type, ValueRange, Location)>;
/// Attempt to materialize a conversion using one of the provided
/// materialization functions.
@@ -244,23 +245,24 @@ class TypeConverter {
/// Generate a wrapper for the given callback. This allows for accepting
///
diff erent callback forms, that all compose into a single version.
- /// With callback of form: `Optional<Type>(T)`
+ /// With callback of form: `std::optional<Type>(T)`
template <typename T, typename FnT>
std::enable_if_t<std::is_invocable_v<FnT, T>, ConversionCallbackFn>
wrapCallback(FnT &&callback) {
return wrapCallback<T>(
[callback = std::forward<FnT>(callback)](
T type, SmallVectorImpl<Type> &results, ArrayRef<Type>) {
- if (Optional<Type> resultOpt = callback(type)) {
+ if (std::optional<Type> resultOpt = callback(type)) {
bool wasSuccess = static_cast<bool>(*resultOpt);
if (wasSuccess)
results.push_back(*resultOpt);
- return Optional<LogicalResult>(success(wasSuccess));
+ return std::optional<LogicalResult>(success(wasSuccess));
}
- return Optional<LogicalResult>();
+ return std::optional<LogicalResult>();
});
}
- /// With callback of form: `Optional<LogicalResult>(T, SmallVectorImpl<Type>
+ /// With callback of form: `std::optional<LogicalResult>(T,
+ /// SmallVectorImpl<Type>
/// &)`
template <typename T, typename FnT>
std::enable_if_t<std::is_invocable_v<FnT, T, SmallVectorImpl<Type> &>,
@@ -272,7 +274,8 @@ class TypeConverter {
return callback(type, results);
});
}
- /// With callback of form: `Optional<LogicalResult>(T, SmallVectorImpl<Type>
+ /// With callback of form: `std::optional<LogicalResult>(T,
+ /// SmallVectorImpl<Type>
/// &, ArrayRef<Type>)`.
template <typename T, typename FnT>
std::enable_if_t<
@@ -281,7 +284,7 @@ class TypeConverter {
wrapCallback(FnT &&callback) {
return [callback = std::forward<FnT>(callback)](
Type type, SmallVectorImpl<Type> &results,
- ArrayRef<Type> callStack) -> Optional<LogicalResult> {
+ ArrayRef<Type> callStack) -> std::optional<LogicalResult> {
T derivedType = type.dyn_cast<T>();
if (!derivedType)
return std::nullopt;
@@ -303,7 +306,7 @@ class TypeConverter {
MaterializationCallbackFn wrapMaterialization(FnT &&callback) {
return [callback = std::forward<FnT>(callback)](
OpBuilder &builder, Type resultType, ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (T derivedType = resultType.dyn_cast<T>())
return callback(builder, derivedType, inputs, loc);
return std::nullopt;
@@ -681,7 +684,8 @@ class ConversionTarget {
/// The signature of the callback used to determine if an operation is
/// dynamically legal on the target.
- using DynamicLegalityCallbackFn = std::function<Optional<bool>(Operation *)>;
+ using DynamicLegalityCallbackFn =
+ std::function<std::optional<bool>(Operation *)>;
ConversionTarget(MLIRContext &ctx) : ctx(ctx) {}
virtual ~ConversionTarget() = default;
@@ -830,7 +834,7 @@ class ConversionTarget {
//===--------------------------------------------------------------------===//
/// Get the legality action for the given operation.
- Optional<LegalizationAction> getOpAction(OperationName op) const;
+ std::optional<LegalizationAction> getOpAction(OperationName op) const;
/// If the given operation instance is legal on this target, a structure
/// containing legality information is returned. If the operation is not
@@ -841,7 +845,7 @@ class ConversionTarget {
/// Note: Legality is actually a 4-state: Legal(recursive=true),
/// Legal(recursive=false), Illegal or Unknown, where Unknown is treated
/// either as Legal or Illegal depending on context.
- Optional<LegalOpDetails> isLegal(Operation *op) const;
+ std::optional<LegalOpDetails> isLegal(Operation *op) const;
/// Returns true is operation instance is illegal on this target. Returns
/// false if operation is legal, operation legality wasn't registered by user
@@ -873,7 +877,7 @@ class ConversionTarget {
};
/// Get the legalization information for the given operation.
- Optional<LegalizationInfo> getOpInfo(OperationName op) const;
+ std::optional<LegalizationInfo> getOpInfo(OperationName op) const;
/// A deterministic mapping of operation name and its respective legality
/// information.
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 9533494c5456c..873edc30099ee 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -1156,7 +1156,7 @@ struct ConvertArithToSPIRVPass
auto addUnrealizedCast = [](OpBuilder &builder, Type type,
ValueRange inputs, Location loc) {
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
- return Optional<Value>(cast.getResult(0));
+ return std::optional<Value>(cast.getResult(0));
};
typeConverter.addSourceMaterialization(addUnrealizedCast);
typeConverter.addTargetMaterialization(addUnrealizedCast);
diff --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
index f2d6b9d2928e4..5f00c3da77ea2 100644
--- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
+++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
@@ -288,14 +288,14 @@ class AsyncRuntimeTypeConverter : public TypeConverter {
auto addUnrealizedCast = [](OpBuilder &builder, Type type,
ValueRange inputs, Location loc) {
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
- return Optional<Value>(cast.getResult(0));
+ return std::optional<Value>(cast.getResult(0));
};
addSourceMaterialization(addUnrealizedCast);
addTargetMaterialization(addUnrealizedCast);
}
- static Optional<Type> convertAsyncTypes(Type type) {
+ static std::optional<Type> convertAsyncTypes(Type type) {
if (type.isa<TokenType, GroupType, ValueType>())
return AsyncAPI::opaquePointerType(type.getContext());
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index e4d98f699178e..457355b263e4f 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -180,7 +180,7 @@ struct LowerGpuOpsToNVVMOpsPass
// memory allocations as local `alloca`s in the default address space. This
// converter drops the private memory space to support the use case above.
LLVMTypeConverter converter(m.getContext(), options);
- converter.addConversion([&](MemRefType type) -> Optional<Type> {
+ converter.addConversion([&](MemRefType type) -> std::optional<Type> {
if (type.getMemorySpaceAsInt() !=
gpu::GPUDialect::getPrivateAddressSpace())
return std::nullopt;
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index 2d7fb3ed90f10..f5b35b794bf11 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -42,13 +42,13 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
// before the conversions below since conversions are attempted in reverse
// order and those should take priority.
addConversion([](Type type) {
- return LLVM::isCompatibleType(type) ? llvm::Optional<Type>(type)
+ return LLVM::isCompatibleType(type) ? std::optional<Type>(type)
: std::nullopt;
});
// LLVM container types may (recursively) contain other types that must be
// converted even when the outer type is compatible.
- addConversion([&](LLVM::LLVMPointerType type) -> llvm::Optional<Type> {
+ addConversion([&](LLVM::LLVMPointerType type) -> std::optional<Type> {
if (type.isOpaque())
return type;
if (auto pointee = convertType(type.getElementType()))
@@ -56,7 +56,7 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
return std::nullopt;
});
addConversion([&](LLVM::LLVMStructType type, SmallVectorImpl<Type> &results,
- ArrayRef<Type> callStack) -> llvm::Optional<LogicalResult> {
+ ArrayRef<Type> callStack) -> std::optional<LogicalResult> {
// Fastpath for types that won't be converted by this callback anyway.
if (LLVM::isCompatibleType(type)) {
results.push_back(type);
@@ -99,12 +99,12 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
type.getContext(), convertedSubtypes, type.isPacked()));
return success();
});
- addConversion([&](LLVM::LLVMArrayType type) -> llvm::Optional<Type> {
+ addConversion([&](LLVM::LLVMArrayType type) -> std::optional<Type> {
if (auto element = convertType(type.getElementType()))
return LLVM::LLVMArrayType::get(element, type.getNumElements());
return std::nullopt;
});
- addConversion([&](LLVM::LLVMFunctionType type) -> llvm::Optional<Type> {
+ addConversion([&](LLVM::LLVMFunctionType type) -> std::optional<Type> {
Type convertedResType = convertType(type.getReturnType());
if (!convertedResType)
return std::nullopt;
@@ -123,7 +123,7 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
// value represents a memref.
addArgumentMaterialization(
[&](OpBuilder &builder, UnrankedMemRefType resultType, ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (inputs.size() == 1)
return std::nullopt;
return UnrankedMemRefDescriptor::pack(builder, loc, *this, resultType,
@@ -131,7 +131,7 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
});
addArgumentMaterialization([&](OpBuilder &builder, MemRefType resultType,
ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
// TODO: bare ptr conversion could be handled here but we would need a way
// to distinguish between FuncOp and other regions.
if (inputs.size() == 1)
@@ -142,7 +142,7 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
// non-LLVM types persist after an LLVM conversion.
addSourceMaterialization([&](OpBuilder &builder, Type resultType,
ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (inputs.size() != 1)
return std::nullopt;
@@ -151,7 +151,7 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
});
addTargetMaterialization([&](OpBuilder &builder, Type resultType,
ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (inputs.size() != 1)
return std::nullopt;
diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp
index 6e9ab607fef84..ad455c297e1c4 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp
@@ -47,7 +47,7 @@ void ConvertMathToSPIRVPass::runOnOperation() {
auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs,
Location loc) {
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
- return Optional<Value>(cast.getResult(0));
+ return std::optional<Value>(cast.getResult(0));
};
typeConverter.addSourceMaterialization(addUnrealizedCast);
typeConverter.addTargetMaterialization(addUnrealizedCast);
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
index 2a95199055f7e..884b5ea316bdf 100644
--- a/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
@@ -56,7 +56,7 @@ using namespace mlir;
MAP_FN(spirv::StorageClass::Input, 9) \
MAP_FN(spirv::StorageClass::Output, 10)
-Optional<spirv::StorageClass>
+std::optional<spirv::StorageClass>
spirv::mapMemorySpaceToVulkanStorageClass(Attribute memorySpaceAttr) {
// Handle null memory space attribute specially.
if (!memorySpaceAttr)
@@ -83,7 +83,7 @@ spirv::mapMemorySpaceToVulkanStorageClass(Attribute memorySpaceAttr) {
#undef STORAGE_SPACE_MAP_FN
}
-Optional<unsigned>
+std::optional<unsigned>
spirv::mapVulkanStorageClassToMemorySpace(spirv::StorageClass storageClass) {
#define STORAGE_SPACE_MAP_FN(storage, space) \
case storage: \
@@ -110,7 +110,7 @@ spirv::mapVulkanStorageClassToMemorySpace(spirv::StorageClass storageClass) {
MAP_FN(spirv::StorageClass::Function, 6) \
MAP_FN(spirv::StorageClass::Image, 7)
-Optional<spirv::StorageClass>
+std::optional<spirv::StorageClass>
spirv::mapMemorySpaceToOpenCLStorageClass(Attribute memorySpaceAttr) {
// Handle null memory space attribute specially.
if (!memorySpaceAttr)
@@ -137,7 +137,7 @@ spirv::mapMemorySpaceToOpenCLStorageClass(Attribute memorySpaceAttr) {
#undef STORAGE_SPACE_MAP_FN
}
-Optional<unsigned>
+std::optional<unsigned>
spirv::mapOpenCLStorageClassToMemorySpace(spirv::StorageClass storageClass) {
#define STORAGE_SPACE_MAP_FN(storage, space) \
case storage: \
@@ -165,8 +165,8 @@ spirv::MemorySpaceToStorageClassConverter::MemorySpaceToStorageClassConverter(
// Pass through for all other types.
addConversion([](Type type) { return type; });
- addConversion([this](BaseMemRefType memRefType) -> Optional<Type> {
- Optional<spirv::StorageClass> storage =
+ addConversion([this](BaseMemRefType memRefType) -> std::optional<Type> {
+ std::optional<spirv::StorageClass> storage =
this->memorySpaceMap(memRefType.getMemorySpace());
if (!storage) {
LLVM_DEBUG(llvm::dbgs()
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp
index b12311bc5624c..9effeabc78d37 100644
--- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp
@@ -48,7 +48,7 @@ void ConvertMemRefToSPIRVPass::runOnOperation() {
auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs,
Location loc) {
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
- return Optional<Value>(cast.getResult(0));
+ return std::optional<Value>(cast.getResult(0));
};
typeConverter.addSourceMaterialization(addUnrealizedCast);
typeConverter.addTargetMaterialization(addUnrealizedCast);
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
index d2993836bc970..0ba294f2ed799 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
@@ -184,7 +184,7 @@ static Value processCountOrOffset(Location loc, Value value, Type srcType,
/// Converts SPIR-V struct with a regular (according to `VulkanLayoutUtils`)
/// offset to LLVM struct. Otherwise, the conversion is not supported.
-static Optional<Type>
+static std::optional<Type>
convertStructTypeWithOffset(spirv::StructType type,
LLVMTypeConverter &converter) {
if (type != VulkanLayoutUtils::decorateType(type))
@@ -247,8 +247,8 @@ static LogicalResult replaceWithLoadOrStore(Operation *op, ValueRange operands,
/// Converts SPIR-V array type to LLVM array. Natural stride (according to
/// `VulkanLayoutUtils`) is also mapped to LLVM array. This has to be respected
/// when converting ops that manipulate array types.
-static Optional<Type> convertArrayType(spirv::ArrayType type,
- TypeConverter &converter) {
+static std::optional<Type> convertArrayType(spirv::ArrayType type,
+ TypeConverter &converter) {
unsigned stride = type.getArrayStride();
Type elementType = type.getElementType();
auto sizeInBytes = elementType.cast<spirv::SPIRVType>().getSizeInBytes();
@@ -271,8 +271,8 @@ static Type convertPointerType(spirv::PointerType type,
/// Converts SPIR-V runtime array to LLVM array. Since LLVM allows indexing over
/// the bounds, the runtime array is converted to a 0-sized LLVM array. There is
/// no modelling of array stride at the moment.
-static Optional<Type> convertRuntimeArrayType(spirv::RuntimeArrayType type,
- TypeConverter &converter) {
+static std::optional<Type> convertRuntimeArrayType(spirv::RuntimeArrayType type,
+ TypeConverter &converter) {
if (type.getArrayStride() != 0)
return std::nullopt;
auto elementType = converter.convertType(type.getElementType());
@@ -281,8 +281,8 @@ static Optional<Type> convertRuntimeArrayType(spirv::RuntimeArrayType type,
/// Converts SPIR-V struct to LLVM struct. There is no support of structs with
/// member decorations. Also, only natural offset is supported.
-static Optional<Type> convertStructType(spirv::StructType type,
- LLVMTypeConverter &converter) {
+static std::optional<Type> convertStructType(spirv::StructType type,
+ LLVMTypeConverter &converter) {
SmallVector<spirv::StructType::MemberDecorationInfo, 4> memberDecorations;
type.getMemberDecorations(memberDecorations);
if (!memberDecorations.empty())
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
index 1ab62428d0ad9..57646c86b6620 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
@@ -47,7 +47,7 @@ void ConvertVectorToSPIRVPass::runOnOperation() {
auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs,
Location loc) {
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
- return Optional<Value>(cast.getResult(0));
+ return std::optional<Value>(cast.getResult(0));
};
typeConverter.addSourceMaterialization(addUnrealizedCast);
typeConverter.addTargetMaterialization(addUnrealizedCast);
diff --git a/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp
index 1fffb0312bb1d..db3ddab483b5a 100644
--- a/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp
@@ -1001,10 +1001,10 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
assert(widestIntSupportedByTarget >= 2 && "Integer type too narrow");
// Allow unknown types.
- addConversion([](Type ty) -> Optional<Type> { return ty; });
+ addConversion([](Type ty) -> std::optional<Type> { return ty; });
// Scalar case.
- addConversion([this](IntegerType ty) -> Optional<Type> {
+ addConversion([this](IntegerType ty) -> std::optional<Type> {
unsigned width = ty.getWidth();
if (width <= maxIntWidth)
return ty;
@@ -1017,7 +1017,7 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
});
// Vector case.
- addConversion([this](VectorType ty) -> Optional<Type> {
+ addConversion([this](VectorType ty) -> std::optional<Type> {
auto intTy = ty.getElementType().dyn_cast<IntegerType>();
if (!intTy)
return ty;
@@ -1038,7 +1038,7 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
});
// Function case.
- addConversion([this](FunctionType ty) -> Optional<Type> {
+ addConversion([this](FunctionType ty) -> std::optional<Type> {
// Convert inputs and results, e.g.:
// (i2N, i2N) -> i2N --> (vector<2xiN>, vector<2xiN>) -> vector<2xiN>
SmallVector<Type> inputs;
diff --git a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
index bb566f861524a..53f2008324f05 100644
--- a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
@@ -128,11 +128,11 @@ struct ArithUnsignedWhenEquivalentPass
target
.addDynamicallyLegalOp<DivSIOp, CeilDivSIOp, CeilDivUIOp, FloorDivSIOp,
RemSIOp, MinSIOp, MaxSIOp, ExtSIOp>(
- [&solver](Operation *op) -> Optional<bool> {
+ [&solver](Operation *op) -> std::optional<bool> {
return failed(staticallyNonNegative(solver, op));
});
target.addDynamicallyLegalOp<CmpIOp>(
- [&solver](CmpIOp op) -> Optional<bool> {
+ [&solver](CmpIOp op) -> std::optional<bool> {
return failed(isCmpIConvertable(solver, op));
});
diff --git a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
index 3de4b806cb521..b0e884c285f0c 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
@@ -145,7 +145,7 @@ void memref::populateMemRefWideIntEmulationPatterns(
void memref::populateMemRefWideIntEmulationConversions(
arith::WideIntEmulationConverter &typeConverter) {
typeConverter.addConversion(
- [&typeConverter](MemRefType ty) -> Optional<Type> {
+ [&typeConverter](MemRefType ty) -> std::optional<Type> {
auto intTy = ty.getElementType().dyn_cast<IntegerType>();
if (!intTy)
return ty;
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
index 40082b1cb36af..7dc3fdef32c75 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
@@ -66,19 +66,19 @@ Type ArrayType::getElementType() const { return getImpl()->elementType; }
unsigned ArrayType::getArrayStride() const { return getImpl()->stride; }
void ArrayType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
}
void ArrayType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
}
-Optional<int64_t> ArrayType::getSizeInBytes() {
+std::optional<int64_t> ArrayType::getSizeInBytes() {
auto elementType = getElementType().cast<SPIRVType>();
- Optional<int64_t> size = elementType.getSizeInBytes();
+ std::optional<int64_t> size = elementType.getSizeInBytes();
if (!size)
return std::nullopt;
return (*size + getArrayStride()) * getNumElements();
@@ -153,7 +153,7 @@ bool CompositeType::hasCompileTimeKnownNumElements() const {
void CompositeType::getExtensions(
SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
TypeSwitch<Type>(*this)
.Case<ArrayType, CooperativeMatrixNVType, JointMatrixINTELType,
MatrixType, RuntimeArrayType, StructType>(
@@ -167,7 +167,7 @@ void CompositeType::getExtensions(
void CompositeType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
TypeSwitch<Type>(*this)
.Case<ArrayType, CooperativeMatrixNVType, JointMatrixINTELType,
MatrixType, RuntimeArrayType, StructType>(
@@ -185,13 +185,13 @@ void CompositeType::getCapabilities(
.Default([](Type) { llvm_unreachable("invalid composite type"); });
}
-Optional<int64_t> CompositeType::getSizeInBytes() {
+std::optional<int64_t> CompositeType::getSizeInBytes() {
if (auto arrayType = dyn_cast<ArrayType>())
return arrayType.getSizeInBytes();
if (auto structType = dyn_cast<StructType>())
return structType.getSizeInBytes();
if (auto vectorType = dyn_cast<VectorType>()) {
- Optional<int64_t> elementSize =
+ std::optional<int64_t> elementSize =
vectorType.getElementType().cast<ScalarType>().getSizeInBytes();
if (!elementSize)
return std::nullopt;
@@ -247,7 +247,7 @@ unsigned CooperativeMatrixNVType::getColumns() const {
void CooperativeMatrixNVType::getExtensions(
SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
static const Extension exts[] = {Extension::SPV_NV_cooperative_matrix};
ArrayRef<Extension> ref(exts, std::size(exts));
@@ -256,7 +256,7 @@ void CooperativeMatrixNVType::getExtensions(
void CooperativeMatrixNVType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
static const Capability caps[] = {Capability::CooperativeMatrixNV};
ArrayRef<Capability> ref(caps, std::size(caps));
@@ -315,7 +315,7 @@ MatrixLayout JointMatrixINTELType::getMatrixLayout() const {
void JointMatrixINTELType::getExtensions(
SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
static const Extension exts[] = {Extension::SPV_INTEL_joint_matrix};
ArrayRef<Extension> ref(exts, std::size(exts));
@@ -324,7 +324,7 @@ void JointMatrixINTELType::getExtensions(
void JointMatrixINTELType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
static const Capability caps[] = {Capability::JointMatrixINTEL};
ArrayRef<Capability> ref(caps, std::size(caps));
@@ -434,12 +434,13 @@ ImageSamplerUseInfo ImageType::getSamplerUseInfo() const {
ImageFormat ImageType::getImageFormat() const { return getImpl()->format; }
void ImageType::getExtensions(SPIRVType::ExtensionArrayRefVector &,
- Optional<StorageClass>) {
+ std::optional<StorageClass>) {
// Image types do not require extra extensions thus far.
}
void ImageType::getCapabilities(
- SPIRVType::CapabilityArrayRefVector &capabilities, Optional<StorageClass>) {
+ SPIRVType::CapabilityArrayRefVector &capabilities,
+ std::optional<StorageClass>) {
if (auto dimCaps = spirv::getCapabilities(getDim()))
capabilities.push_back(*dimCaps);
@@ -484,7 +485,7 @@ StorageClass PointerType::getStorageClass() const {
}
void PointerType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
// Use this pointer type's storage class because this pointer indicates we are
// using the pointee type in that specific storage class.
getPointeeType().cast<SPIRVType>().getExtensions(extensions,
@@ -496,7 +497,7 @@ void PointerType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
void PointerType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
// Use this pointer type's storage class because this pointer indicates we are
// using the pointee type in that specific storage class.
getPointeeType().cast<SPIRVType>().getCapabilities(capabilities,
@@ -544,13 +545,13 @@ unsigned RuntimeArrayType::getArrayStride() const { return getImpl()->stride; }
void RuntimeArrayType::getExtensions(
SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
}
void RuntimeArrayType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
{
static const Capability caps[] = {Capability::Shader};
ArrayRef<Capability> ref(caps, std::size(caps));
@@ -589,7 +590,7 @@ bool ScalarType::isValid(IntegerType type) {
}
void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
// 8- or 16-bit integer/floating-point numbers will require extra extensions
// to appear in interface storage classes. See SPV_KHR_16bit_storage and
// SPV_KHR_8bit_storage for more details.
@@ -621,7 +622,7 @@ void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
void ScalarType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
unsigned bitwidth = getIntOrFloatBitWidth();
// 8- or 16-bit integer/floating-point numbers will require extra capabilities
@@ -707,7 +708,7 @@ void ScalarType::getCapabilities(
#undef WIDTH_CASE
}
-Optional<int64_t> ScalarType::getSizeInBytes() {
+std::optional<int64_t> ScalarType::getSizeInBytes() {
auto bitWidth = getIntOrFloatBitWidth();
// According to the SPIR-V spec:
// "There is no physical size or bit pattern defined for values with boolean
@@ -740,7 +741,7 @@ bool SPIRVType::isScalarOrVector() {
}
void SPIRVType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
if (auto scalarType = dyn_cast<ScalarType>()) {
scalarType.getExtensions(extensions, storage);
} else if (auto compositeType = dyn_cast<CompositeType>()) {
@@ -760,7 +761,7 @@ void SPIRVType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
void SPIRVType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
if (auto scalarType = dyn_cast<ScalarType>()) {
scalarType.getCapabilities(capabilities, storage);
} else if (auto compositeType = dyn_cast<CompositeType>()) {
@@ -778,7 +779,7 @@ void SPIRVType::getCapabilities(
}
}
-Optional<int64_t> SPIRVType::getSizeInBytes() {
+std::optional<int64_t> SPIRVType::getSizeInBytes() {
if (auto scalarType = dyn_cast<ScalarType>())
return scalarType.getSizeInBytes();
if (auto compositeType = dyn_cast<CompositeType>())
@@ -828,13 +829,13 @@ SampledImageType::verify(function_ref<InFlightDiagnostic()> emitError,
void SampledImageType::getExtensions(
SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getImageType().cast<ImageType>().getExtensions(extensions, storage);
}
void SampledImageType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getImageType().cast<ImageType>().getCapabilities(capabilities, storage);
}
@@ -1128,14 +1129,14 @@ StructType::trySetBody(ArrayRef<Type> memberTypes,
}
void StructType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
for (Type elementType : getElementTypes())
elementType.cast<SPIRVType>().getExtensions(extensions, storage);
}
void StructType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
for (Type elementType : getElementTypes())
elementType.cast<SPIRVType>().getCapabilities(capabilities, storage);
}
@@ -1227,13 +1228,13 @@ unsigned MatrixType::getNumElements() const {
}
void MatrixType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
getColumnType().cast<SPIRVType>().getExtensions(extensions, storage);
}
void MatrixType::getCapabilities(
SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<StorageClass> storage) {
+ std::optional<StorageClass> storage) {
{
static const Capability caps[] = {Capability::Matrix};
ArrayRef<Capability> ref(caps, std::size(caps));
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index 62e3a3de0f11b..b455993924b55 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -129,8 +129,8 @@ bool SPIRVTypeConverter::allows(spirv::Capability capability) {
// TODO: This is a utility function that should probably be exposed by the
// SPIR-V dialect. Keeping it local till the use case arises.
-static Optional<int64_t> getTypeNumBytes(const SPIRVConversionOptions &options,
- Type type) {
+static std::optional<int64_t>
+getTypeNumBytes(const SPIRVConversionOptions &options, Type type) {
if (type.isa<spirv::ScalarType>()) {
auto bitWidth = type.getIntOrFloatBitWidth();
// According to the SPIR-V spec:
@@ -203,10 +203,10 @@ static Optional<int64_t> getTypeNumBytes(const SPIRVConversionOptions &options,
}
/// Converts a scalar `type` to a suitable type under the given `targetEnv`.
-static Type convertScalarType(const spirv::TargetEnv &targetEnv,
- const SPIRVConversionOptions &options,
- spirv::ScalarType type,
- Optional<spirv::StorageClass> storageClass = {}) {
+static Type
+convertScalarType(const spirv::TargetEnv &targetEnv,
+ const SPIRVConversionOptions &options, spirv::ScalarType type,
+ std::optional<spirv::StorageClass> storageClass = {}) {
// Get extension and capability requirements for the given type.
SmallVector<ArrayRef<spirv::Extension>, 1> extensions;
SmallVector<ArrayRef<spirv::Capability>, 2> capabilities;
@@ -243,10 +243,10 @@ static Type convertScalarType(const spirv::TargetEnv &targetEnv,
}
/// Converts a vector `type` to a suitable type under the given `targetEnv`.
-static Type convertVectorType(const spirv::TargetEnv &targetEnv,
- const SPIRVConversionOptions &options,
- VectorType type,
- Optional<spirv::StorageClass> storageClass = {}) {
+static Type
+convertVectorType(const spirv::TargetEnv &targetEnv,
+ const SPIRVConversionOptions &options, VectorType type,
+ std::optional<spirv::StorageClass> storageClass = {}) {
auto scalarType = type.getElementType().cast<spirv::ScalarType>();
if (type.getRank() <= 1 && type.getNumElements() == 1)
return convertScalarType(targetEnv, options, scalarType, storageClass);
@@ -299,8 +299,8 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
return nullptr;
}
- Optional<int64_t> scalarSize = getTypeNumBytes(options, scalarType);
- Optional<int64_t> tensorSize = getTypeNumBytes(options, type);
+ std::optional<int64_t> scalarSize = getTypeNumBytes(options, scalarType);
+ std::optional<int64_t> tensorSize = getTypeNumBytes(options, type);
if (!scalarSize || !tensorSize) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot deduce element count\n");
@@ -311,7 +311,8 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
auto arrayElemType = convertScalarType(targetEnv, options, scalarType);
if (!arrayElemType)
return nullptr;
- Optional<int64_t> arrayElemSize = getTypeNumBytes(options, arrayElemType);
+ std::optional<int64_t> arrayElemSize =
+ getTypeNumBytes(options, arrayElemType);
if (!arrayElemSize) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot deduce converted element size\n");
@@ -339,7 +340,8 @@ static Type convertBoolMemrefType(const spirv::TargetEnv &targetEnv,
convertScalarType(targetEnv, options, elementType, storageClass);
if (!arrayElemType)
return nullptr;
- Optional<int64_t> arrayElemSize = getTypeNumBytes(options, arrayElemType);
+ std::optional<int64_t> arrayElemSize =
+ getTypeNumBytes(options, arrayElemType);
if (!arrayElemSize) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot deduce converted element size\n");
@@ -406,7 +408,8 @@ static Type convertMemrefType(const spirv::TargetEnv &targetEnv,
if (!arrayElemType)
return nullptr;
- Optional<int64_t> arrayElemSize = getTypeNumBytes(options, arrayElemType);
+ std::optional<int64_t> arrayElemSize =
+ getTypeNumBytes(options, arrayElemType);
if (!arrayElemSize) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot deduce converted element size\n");
@@ -426,7 +429,7 @@ static Type convertMemrefType(const spirv::TargetEnv &targetEnv,
return wrapInStructAndGetPointer(arrayType, storageClass);
}
- Optional<int64_t> memrefSize = getTypeNumBytes(options, type);
+ std::optional<int64_t> memrefSize = getTypeNumBytes(options, type);
if (!memrefSize) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: cannot deduce element count\n");
@@ -458,13 +461,13 @@ SPIRVTypeConverter::SPIRVTypeConverter(spirv::TargetEnvAttr targetAttr,
addConversion([this](IndexType /*indexType*/) { return getIndexType(); });
- addConversion([this](IntegerType intType) -> Optional<Type> {
+ addConversion([this](IntegerType intType) -> std::optional<Type> {
if (auto scalarType = intType.dyn_cast<spirv::ScalarType>())
return convertScalarType(this->targetEnv, this->options, scalarType);
return Type();
});
- addConversion([this](FloatType floatType) -> Optional<Type> {
+ addConversion([this](FloatType floatType) -> std::optional<Type> {
if (auto scalarType = floatType.dyn_cast<spirv::ScalarType>())
return convertScalarType(this->targetEnv, this->options, scalarType);
return Type();
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
index edb72bec52530..3e5b934be677c 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
@@ -84,7 +84,8 @@ static Type getRuntimeArrayElementType(Type type) {
/// Given a list of resource element `types`, returns the index of the canonical
/// resource that all resources should be unified into. Returns std::nullopt if
/// unable to unify.
-static Optional<int> deduceCanonicalResource(ArrayRef<spirv::SPIRVType> types) {
+static std::optional<int>
+deduceCanonicalResource(ArrayRef<spirv::SPIRVType> types) {
// scalarNumBits: contains all resources' scalar types' bit counts.
// vectorNumBits: only contains resources whose element types are vectors.
// vectorIndices: each vector's original index in `types`.
@@ -101,7 +102,7 @@ static Optional<int> deduceCanonicalResource(ArrayRef<spirv::SPIRVType> types) {
return std::nullopt; // Odd-sized vector has special layout
// requirements.
- Optional<int64_t> numBytes = type.getSizeInBytes();
+ std::optional<int64_t> numBytes = type.getSizeInBytes();
if (!numBytes)
return std::nullopt;
@@ -280,7 +281,7 @@ void ResourceAliasAnalysis::recordIfUnifiable(
elementTypes.push_back(type);
}
- Optional<int> index = deduceCanonicalResource(elementTypes);
+ std::optional<int> index = deduceCanonicalResource(elementTypes);
if (!index)
return;
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
index f3e4a9af8f483..6b406d8241bc6 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
@@ -178,7 +178,7 @@ static void createPushback(OpBuilder &builder, Location loc,
}
/// Maps a sparse tensor type to the appropriate compounded buffers.
-static Optional<LogicalResult>
+static std::optional<LogicalResult>
convertSparseTensorType(Type type, SmallVectorImpl<Type> &fields) {
auto enc = getSparseTensorEncoding(type);
if (!enc)
@@ -1039,7 +1039,7 @@ mlir::SparseTensorTypeToBufferConverter::SparseTensorTypeToBufferConverter() {
// Required by scf.for 1:N type conversion.
addSourceMaterialization([](OpBuilder &builder, RankedTensorType tp,
ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (!getSparseTensorEncoding(tp))
// Not a sparse tensor.
return std::nullopt;
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
index a358f384bfb0c..1d5d28ca512af 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
@@ -39,7 +39,7 @@ namespace {
//===----------------------------------------------------------------------===//
/// Maps each sparse tensor type to an opaque pointer.
-static Optional<Type> convertSparseTensorTypes(Type type) {
+static std::optional<Type> convertSparseTensorTypes(Type type) {
if (getSparseTensorEncoding(type) != nullptr)
return LLVM::LLVMPointerType::get(IntegerType::get(type.getContext(), 8));
return std::nullopt;
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 795293bb07988..c476e5f0c5696 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -50,8 +50,9 @@ computeConversionSet(iterator_range<Region::iterator> region,
// Don't check this operation's children for conversion if the operation
// is recursively legal.
- auto legalityInfo = target ? target->isLegal(&op)
- : Optional<ConversionTarget::LegalOpDetails>();
+ auto legalityInfo =
+ target ? target->isLegal(&op)
+ : std::optional<ConversionTarget::LegalOpDetails>();
if (legalityInfo && legalityInfo->isRecursivelyLegal)
continue;
for (auto ®ion : op.getRegions()) {
@@ -496,7 +497,7 @@ struct ArgConverter {
/// The conversion information for each of the arguments. The information is
/// std::nullopt if the argument was dropped during conversion.
- SmallVector<Optional<ConvertedArgInfo>, 1> argInfo;
+ SmallVector<std::optional<ConvertedArgInfo>, 1> argInfo;
/// The type converter used to convert the arguments.
TypeConverter *converter;
@@ -649,7 +650,7 @@ void ArgConverter::applyRewrites(ConversionValueMapping &mapping) {
// Process the remapping for each of the original arguments.
for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) {
- Optional<ConvertedArgInfo> &argInfo = blockInfo.argInfo[i];
+ std::optional<ConvertedArgInfo> &argInfo = blockInfo.argInfo[i];
BlockArgument origArg = origBlock->getArgument(i);
// Handle the case of a 1->0 value mapping.
@@ -888,7 +889,8 @@ struct ConversionPatternRewriterImpl {
/// success if the values could be remapped, failure otherwise. `valueDiagTag`
/// is the tag used when describing a value within a diagnostic, e.g.
/// "operand".
- LogicalResult remapValues(StringRef valueDiagTag, Optional<Location> inputLoc,
+ LogicalResult remapValues(StringRef valueDiagTag,
+ std::optional<Location> inputLoc,
PatternRewriter &rewriter, ValueRange values,
SmallVectorImpl<Value> &remapped);
@@ -1253,7 +1255,7 @@ void ConversionPatternRewriterImpl::undoBlockActions(
}
LogicalResult ConversionPatternRewriterImpl::remapValues(
- StringRef valueDiagTag, Optional<Location> inputLoc,
+ StringRef valueDiagTag, std::optional<Location> inputLoc,
PatternRewriter &rewriter, ValueRange values,
SmallVectorImpl<Value> &remapped) {
remapped.reserve(llvm::size(values));
@@ -2186,7 +2188,7 @@ void OperationLegalizer::buildLegalizationGraph(
// Check to see if any of the generated operations are invalid.
if (llvm::any_of(pattern->getGeneratedOps(), [&](OperationName op) {
- Optional<LegalizationAction> action = target.getOpAction(op);
+ std::optional<LegalizationAction> action = target.getOpAction(op);
return !legalizerPatterns.count(op) &&
(!action || action == LegalizationAction::Illegal);
}))
@@ -2370,7 +2372,7 @@ struct OperationConverter {
LogicalResult legalizeUnresolvedMaterializations(
ConversionPatternRewriter &rewriter,
ConversionPatternRewriterImpl &rewriterImpl,
- Optional<DenseMap<Value, SmallVector<Value>>> &inverseMapping);
+ std::optional<DenseMap<Value, SmallVector<Value>>> &inverseMapping);
/// Legalize an operation result that was marked as "erased".
LogicalResult
@@ -2479,7 +2481,7 @@ LogicalResult OperationConverter::convertOperations(
LogicalResult
OperationConverter::finalize(ConversionPatternRewriter &rewriter) {
- Optional<DenseMap<Value, SmallVector<Value>>> inverseMapping;
+ std::optional<DenseMap<Value, SmallVector<Value>>> inverseMapping;
ConversionPatternRewriterImpl &rewriterImpl = rewriter.getImpl();
if (failed(legalizeUnresolvedMaterializations(rewriter, rewriterImpl,
inverseMapping)) ||
@@ -2806,7 +2808,7 @@ static LogicalResult legalizeUnresolvedMaterialization(
LogicalResult OperationConverter::legalizeUnresolvedMaterializations(
ConversionPatternRewriter &rewriter,
ConversionPatternRewriterImpl &rewriterImpl,
- Optional<DenseMap<Value, SmallVector<Value>>> &inverseMapping) {
+ std::optional<DenseMap<Value, SmallVector<Value>>> &inverseMapping) {
if (rewriterImpl.unresolvedMaterializations.empty())
return success();
inverseMapping = rewriterImpl.mapping.getInverse();
@@ -2961,7 +2963,7 @@ LogicalResult TypeConverter::convertType(Type t,
auto popConversionCallStack =
llvm::make_scope_exit([this]() { conversionCallStack.pop_back(); });
for (ConversionCallbackFn &converter : llvm::reverse(conversions)) {
- if (Optional<LogicalResult> result =
+ if (std::optional<LogicalResult> result =
converter(t, results, conversionCallStack)) {
if (!succeeded(*result)) {
cachedDirectConversions.try_emplace(t, nullptr);
@@ -3039,13 +3041,13 @@ Value TypeConverter::materializeConversion(
MutableArrayRef<MaterializationCallbackFn> materializations,
OpBuilder &builder, Location loc, Type resultType, ValueRange inputs) {
for (MaterializationCallbackFn &fn : llvm::reverse(materializations))
- if (Optional<Value> result = fn(builder, resultType, inputs, loc))
+ if (std::optional<Value> result = fn(builder, resultType, inputs, loc))
return *result;
return nullptr;
}
auto TypeConverter::convertBlockSignature(Block *block)
- -> Optional<SignatureConversion> {
+ -> std::optional<SignatureConversion> {
SignatureConversion conversion(block->getNumArguments());
if (failed(convertSignatureArgs(block->getArgumentTypes(), conversion)))
return std::nullopt;
@@ -3138,14 +3140,14 @@ void ConversionTarget::setDialectAction(ArrayRef<StringRef> dialectNames,
}
auto ConversionTarget::getOpAction(OperationName op) const
- -> Optional<LegalizationAction> {
- Optional<LegalizationInfo> info = getOpInfo(op);
- return info ? info->action : Optional<LegalizationAction>();
+ -> std::optional<LegalizationAction> {
+ std::optional<LegalizationInfo> info = getOpInfo(op);
+ return info ? info->action : std::optional<LegalizationAction>();
}
auto ConversionTarget::isLegal(Operation *op) const
- -> Optional<LegalOpDetails> {
- Optional<LegalizationInfo> info = getOpInfo(op->getName());
+ -> std::optional<LegalOpDetails> {
+ std::optional<LegalizationInfo> info = getOpInfo(op->getName());
if (!info)
return std::nullopt;
@@ -3153,7 +3155,7 @@ auto ConversionTarget::isLegal(Operation *op) const
auto isOpLegal = [&] {
// Handle dynamic legality either with the provided legality function.
if (info->action == LegalizationAction::Dynamic) {
- Optional<bool> result = info->legalityFn(op);
+ std::optional<bool> result = info->legalityFn(op);
if (result)
return *result;
}
@@ -3179,12 +3181,12 @@ auto ConversionTarget::isLegal(Operation *op) const
}
bool ConversionTarget::isIllegal(Operation *op) const {
- Optional<LegalizationInfo> info = getOpInfo(op->getName());
+ std::optional<LegalizationInfo> info = getOpInfo(op->getName());
if (!info)
return false;
if (info->action == LegalizationAction::Dynamic) {
- Optional<bool> result = info->legalityFn(op);
+ std::optional<bool> result = info->legalityFn(op);
if (!result)
return false;
@@ -3201,8 +3203,8 @@ static ConversionTarget::DynamicLegalityCallbackFn composeLegalityCallbacks(
return newCallback;
auto chain = [oldCl = std::move(oldCallback), newCl = std::move(newCallback)](
- Operation *op) -> Optional<bool> {
- if (Optional<bool> result = newCl(op))
+ Operation *op) -> std::optional<bool> {
+ if (std::optional<bool> result = newCl(op))
return *result;
return oldCl(op);
@@ -3250,7 +3252,7 @@ void ConversionTarget::setLegalityCallback(
}
auto ConversionTarget::getOpInfo(OperationName op) const
- -> Optional<LegalizationInfo> {
+ -> std::optional<LegalizationInfo> {
// Check for info for this specific operation.
auto it = legalOperations.find(op);
if (it != legalOperations.end())
diff --git a/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp b/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp
index c1ae321711fcd..8f0c13af9de5b 100644
--- a/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp
+++ b/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp
@@ -59,7 +59,7 @@ struct TestEmulateWideIntPass
// TODO: Consider extending `arith.bitcast` to support scalar-to-1D-vector
// casts (and vice versa) and using it insted of `llvm.bitcast`.
auto addBitcast = [](OpBuilder &builder, Type type, ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
auto cast = builder.create<LLVM::BitcastOp>(loc, type, inputs);
return cast->getResult(0);
};
diff --git a/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp b/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
index 84338d6991235..9492d23b1778f 100644
--- a/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
+++ b/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
@@ -73,7 +73,7 @@ struct TestDecomposeCallGraphTypes
typeConverter.addArgumentMaterialization(
[](OpBuilder &builder, TupleType resultType, ValueRange inputs,
- Location loc) -> Optional<Value> {
+ Location loc) -> std::optional<Value> {
if (inputs.size() == 1)
return std::nullopt;
TupleType tuple = builder.getTupleType(inputs.getTypes());
diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
index 4590419ed2493..f16636cbff161 100644
--- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp
+++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
@@ -777,8 +777,9 @@ struct TestTypeConverter : public TypeConverter {
/// Hook for materializing a conversion. This is necessary because we generate
/// 1->N type mappings.
- static Optional<Value> materializeCast(OpBuilder &builder, Type resultType,
- ValueRange inputs, Location loc) {
+ static std::optional<Value> materializeCast(OpBuilder &builder,
+ Type resultType,
+ ValueRange inputs, Location loc) {
return builder.create<TestCastOp>(loc, resultType, inputs).getResult();
}
};
@@ -1267,7 +1268,7 @@ struct TestTypeConversionDriver
// Convert a recursive self-referring type into a non-self-referring
// type named "outer_converted_type" that contains a SimpleAType.
[&](test::TestRecursiveType type, SmallVectorImpl<Type> &results,
- ArrayRef<Type> callStack) -> Optional<LogicalResult> {
+ ArrayRef<Type> callStack) -> std::optional<LogicalResult> {
// If the type is already converted, return it to indicate that it is
// legal.
if (type.getName() == "outer_converted_type") {
diff --git a/mlir/test/lib/Transforms/TestDialectConversion.cpp b/mlir/test/lib/Transforms/TestDialectConversion.cpp
index 996b7b9e28861..97fe78c35e833 100644
--- a/mlir/test/lib/Transforms/TestDialectConversion.cpp
+++ b/mlir/test/lib/Transforms/TestDialectConversion.cpp
@@ -44,8 +44,9 @@ struct PDLLTypeConverter : public TypeConverter {
return success();
}
/// Hook for materializing a conversion.
- static Optional<Value> materializeCast(OpBuilder &builder, Type resultType,
- ValueRange inputs, Location loc) {
+ static std::optional<Value> materializeCast(OpBuilder &builder,
+ Type resultType,
+ ValueRange inputs, Location loc) {
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
.getResult(0);
}
diff --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp
index 0cac2975ea91c..f4a60af82d126 100644
--- a/mlir/unittests/Transforms/DialectConversion.cpp
+++ b/mlir/unittests/Transforms/DialectConversion.cpp
@@ -37,10 +37,11 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackOrder) {
});
int callbackCalled2 = 0;
- target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
- callbackCalled2 = ++index;
- return std::nullopt;
- });
+ target.addDynamicallyLegalOp<DummyOp>(
+ [&](Operation *) -> std::optional<bool> {
+ callbackCalled2 = ++index;
+ return std::nullopt;
+ });
auto *op = createOp(&context);
EXPECT_TRUE(target.isLegal(op));
@@ -58,10 +59,11 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackSkip) {
int index = 0;
int callbackCalled = 0;
- target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
- callbackCalled = ++index;
- return std::nullopt;
- });
+ target.addDynamicallyLegalOp<DummyOp>(
+ [&](Operation *) -> std::optional<bool> {
+ callbackCalled = ++index;
+ return std::nullopt;
+ });
auto *op = createOp(&context);
EXPECT_FALSE(target.isLegal(op));
@@ -83,7 +85,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownOpCallbackOrder) {
});
int callbackCalled2 = 0;
- target.markUnknownOpDynamicallyLegal([&](Operation *) -> Optional<bool> {
+ target.markUnknownOpDynamicallyLegal([&](Operation *) -> std::optional<bool> {
callbackCalled2 = ++index;
return std::nullopt;
});
@@ -103,7 +105,7 @@ TEST(DialectConversionTest, DynamicallyLegalReturnNone) {
ConversionTarget target(context);
target.addDynamicallyLegalOp<DummyOp>(
- [&](Operation *) -> Optional<bool> { return std::nullopt; });
+ [&](Operation *) -> std::optional<bool> { return std::nullopt; });
auto *op = createOp(&context);
EXPECT_FALSE(target.isLegal(op));
@@ -120,7 +122,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownReturnNone) {
ConversionTarget target(context);
target.markUnknownOpDynamicallyLegal(
- [&](Operation *) -> Optional<bool> { return std::nullopt; });
+ [&](Operation *) -> std::optional<bool> { return std::nullopt; });
auto *op = createOp(&context);
EXPECT_FALSE(target.isLegal(op));
More information about the Mlir-commits
mailing list