diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -138,7 +138,7 @@ addSourceMaterialization( [&](mlir::OpBuilder &builder, mlir::Type resultType, mlir::ValueRange inputs, - mlir::Location loc) -> llvm::Optional { + mlir::Location loc) -> std::optional { if (inputs.size() != 1) return std::nullopt; return inputs[0]; @@ -148,7 +148,7 @@ addTargetMaterialization( [&](mlir::OpBuilder &builder, mlir::Type resultType, mlir::ValueRange inputs, - mlir::Location loc) -> llvm::Optional { + mlir::Location loc) -> std::optional { if (inputs.size() != 1) return std::nullopt; return inputs[0]; @@ -163,7 +163,7 @@ mlir::Type indexType() { return mlir::IntegerType::get(&getContext(), 64); } // fir.type --> llvm<"%name = { ty... }"> - llvm::Optional + std::optional convertRecordType(fir::RecordType derived, llvm::SmallVectorImpl &results, llvm::ArrayRef callStack) { diff --git a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h --- a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h +++ b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h @@ -23,23 +23,25 @@ namespace spirv { /// Mapping from numeric MemRef memory spaces into SPIR-V symbolic ones. using MemorySpaceToStorageClassMap = - std::function(Attribute)>; + std::function(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 mapMemorySpaceToVulkanStorageClass(Attribute); +std::optional + 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 mapVulkanStorageClassToMemorySpace(spirv::StorageClass); +std::optional 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 mapMemorySpaceToOpenCLStorageClass(Attribute); +std::optional + 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 mapOpenCLStorageClassToMemorySpace(spirv::StorageClass); +std::optional 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 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h @@ -56,7 +56,7 @@ /// 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 storage = std::nullopt); + std::optional 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 @@ /// uniqueness of capabilities; the same capability may be appended multiple /// times. void getCapabilities(CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional 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 getSizeInBytes(); + std::optional getSizeInBytes(); }; // SPIR-V scalar type: bool type, integer type, floating point type. @@ -89,11 +89,11 @@ static bool isValid(IntegerType); void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); - Optional getSizeInBytes(); + std::optional getSizeInBytes(); }; // SPIR-V composite type: VectorType, SPIR-V ArrayType, or SPIR-V StructType. @@ -117,11 +117,11 @@ bool hasCompileTimeKnownNumElements() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); - Optional getSizeInBytes(); + std::optional getSizeInBytes(); }; // SPIR-V array type @@ -145,13 +145,13 @@ unsigned getArrayStride() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional 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 getSizeInBytes(); + std::optional getSizeInBytes(); }; // SPIR-V image type @@ -188,9 +188,9 @@ // TODO: Add support for Access qualifier void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; // SPIR-V pointer type @@ -206,9 +206,9 @@ StorageClass getStorageClass() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; // SPIR-V run-time array type @@ -230,9 +230,9 @@ unsigned getArrayStride() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; // SPIR-V sampled image type @@ -253,9 +253,10 @@ Type getImageType() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); - void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); + void + getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, + std::optional storage = std::nullopt); }; /// SPIR-V struct type. Two kinds of struct types are supported: @@ -389,9 +390,9 @@ ArrayRef memberDecorations = {}); void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; llvm::hash_code @@ -416,9 +417,9 @@ unsigned getColumns() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; // SPIR-V joint matrix type @@ -443,9 +444,9 @@ MatrixLayout getMatrixLayout() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; // SPIR-V matrix type @@ -480,9 +481,9 @@ Type getElementType() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = std::nullopt); + std::optional storage = std::nullopt); }; } // namespace spirv diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h --- a/mlir/include/mlir/Transforms/DialectConversion.h +++ b/mlir/include/mlir/Transforms/DialectConversion.h @@ -54,7 +54,7 @@ ArrayRef getConvertedTypes() const { return argTypes; } /// Get the input mapping for the given argument. - Optional getInputMapping(unsigned input) const { + std::optional getInputMapping(unsigned input) const { return remappedInputs[input]; } @@ -81,7 +81,7 @@ unsigned newInputCount = 1); /// The remapping information for each of the original arguments. - SmallVector, 4> remappedInputs; + SmallVector, 4> remappedInputs; /// The set of new argument types. SmallVector argTypes; @@ -89,19 +89,20 @@ /// 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(T) + /// * std::optional(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(T, SmallVectorImpl &) + /// * std::optional(T, SmallVectorImpl &) /// - 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(T, SmallVectorImpl &, ArrayRef) + /// * std::optional(T, SmallVectorImpl &, + /// ArrayRef) /// - 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 @@ /// Register a materialization function, which must be convertible to the /// following form: - /// `Optional(OpBuilder &, T, ValueRange, Location)`, + /// `std::optional(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 @@ /// 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 convertBlockSignature(Block *block); + std::optional 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 @@ /// 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( + using ConversionCallbackFn = std::function( Type, SmallVectorImpl &, ArrayRef)>; /// The signature of the callback used to materialize a conversion. - using MaterializationCallbackFn = - std::function(OpBuilder &, Type, ValueRange, Location)>; + using MaterializationCallbackFn = std::function( + OpBuilder &, Type, ValueRange, Location)>; /// Attempt to materialize a conversion using one of the provided /// materialization functions. @@ -244,23 +245,24 @@ /// Generate a wrapper for the given callback. This allows for accepting /// different callback forms, that all compose into a single version. - /// With callback of form: `Optional(T)` + /// With callback of form: `std::optional(T)` template std::enable_if_t, ConversionCallbackFn> wrapCallback(FnT &&callback) { return wrapCallback( [callback = std::forward(callback)]( T type, SmallVectorImpl &results, ArrayRef) { - if (Optional resultOpt = callback(type)) { + if (std::optional resultOpt = callback(type)) { bool wasSuccess = static_cast(*resultOpt); if (wasSuccess) results.push_back(*resultOpt); - return Optional(success(wasSuccess)); + return std::optional(success(wasSuccess)); } - return Optional(); + return std::optional(); }); } - /// With callback of form: `Optional(T, SmallVectorImpl + /// With callback of form: `std::optional(T, + /// SmallVectorImpl /// &)` template std::enable_if_t &>, @@ -272,7 +274,8 @@ return callback(type, results); }); } - /// With callback of form: `Optional(T, SmallVectorImpl + /// With callback of form: `std::optional(T, + /// SmallVectorImpl /// &, ArrayRef)`. template std::enable_if_t< @@ -281,7 +284,7 @@ wrapCallback(FnT &&callback) { return [callback = std::forward(callback)]( Type type, SmallVectorImpl &results, - ArrayRef callStack) -> Optional { + ArrayRef callStack) -> std::optional { T derivedType = type.dyn_cast(); if (!derivedType) return std::nullopt; @@ -303,7 +306,7 @@ MaterializationCallbackFn wrapMaterialization(FnT &&callback) { return [callback = std::forward(callback)]( OpBuilder &builder, Type resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { if (T derivedType = resultType.dyn_cast()) return callback(builder, derivedType, inputs, loc); return std::nullopt; @@ -681,7 +684,8 @@ /// The signature of the callback used to determine if an operation is /// dynamically legal on the target. - using DynamicLegalityCallbackFn = std::function(Operation *)>; + using DynamicLegalityCallbackFn = + std::function(Operation *)>; ConversionTarget(MLIRContext &ctx) : ctx(ctx) {} virtual ~ConversionTarget() = default; @@ -830,7 +834,7 @@ //===--------------------------------------------------------------------===// /// Get the legality action for the given operation. - Optional getOpAction(OperationName op) const; + std::optional 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 @@ /// 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 isLegal(Operation *op) const; + std::optional 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 @@ }; /// Get the legalization information for the given operation. - Optional getOpInfo(OperationName op) const; + std::optional 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 --- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp +++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp @@ -1156,7 +1156,7 @@ auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs, Location loc) { auto cast = builder.create(loc, type, inputs); - return Optional(cast.getResult(0)); + return std::optional(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 --- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp +++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp @@ -288,14 +288,14 @@ auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs, Location loc) { auto cast = builder.create(loc, type, inputs); - return Optional(cast.getResult(0)); + return std::optional(cast.getResult(0)); }; addSourceMaterialization(addUnrealizedCast); addTargetMaterialization(addUnrealizedCast); } - static Optional convertAsyncTypes(Type type) { + static std::optional convertAsyncTypes(Type type) { if (type.isa()) return AsyncAPI::opaquePointerType(type.getContext()); diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -180,7 +180,7 @@ // 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 { + converter.addConversion([&](MemRefType type) -> std::optional { 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 --- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp +++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp @@ -42,13 +42,13 @@ // 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) + return LLVM::isCompatibleType(type) ? std::optional(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 { + addConversion([&](LLVM::LLVMPointerType type) -> std::optional { if (type.isOpaque()) return type; if (auto pointee = convertType(type.getElementType())) @@ -56,7 +56,7 @@ return std::nullopt; }); addConversion([&](LLVM::LLVMStructType type, SmallVectorImpl &results, - ArrayRef callStack) -> llvm::Optional { + ArrayRef callStack) -> std::optional { // Fastpath for types that won't be converted by this callback anyway. if (LLVM::isCompatibleType(type)) { results.push_back(type); @@ -99,12 +99,12 @@ type.getContext(), convertedSubtypes, type.isPacked())); return success(); }); - addConversion([&](LLVM::LLVMArrayType type) -> llvm::Optional { + addConversion([&](LLVM::LLVMArrayType type) -> std::optional { if (auto element = convertType(type.getElementType())) return LLVM::LLVMArrayType::get(element, type.getNumElements()); return std::nullopt; }); - addConversion([&](LLVM::LLVMFunctionType type) -> llvm::Optional { + addConversion([&](LLVM::LLVMFunctionType type) -> std::optional { Type convertedResType = convertType(type.getReturnType()); if (!convertedResType) return std::nullopt; @@ -123,7 +123,7 @@ // value represents a memref. addArgumentMaterialization( [&](OpBuilder &builder, UnrankedMemRefType resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { if (inputs.size() == 1) return std::nullopt; return UnrankedMemRefDescriptor::pack(builder, loc, *this, resultType, @@ -131,7 +131,7 @@ }); addArgumentMaterialization([&](OpBuilder &builder, MemRefType resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { // 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 @@ // non-LLVM types persist after an LLVM conversion. addSourceMaterialization([&](OpBuilder &builder, Type resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { if (inputs.size() != 1) return std::nullopt; @@ -151,7 +151,7 @@ }); addTargetMaterialization([&](OpBuilder &builder, Type resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { if (inputs.size() != 1) return std::nullopt; diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp --- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp +++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRVPass.cpp @@ -47,7 +47,7 @@ auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs, Location loc) { auto cast = builder.create(loc, type, inputs); - return Optional(cast.getResult(0)); + return std::optional(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 --- a/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp @@ -56,7 +56,7 @@ MAP_FN(spirv::StorageClass::Input, 9) \ MAP_FN(spirv::StorageClass::Output, 10) -Optional +std::optional spirv::mapMemorySpaceToVulkanStorageClass(Attribute memorySpaceAttr) { // Handle null memory space attribute specially. if (!memorySpaceAttr) @@ -83,7 +83,7 @@ #undef STORAGE_SPACE_MAP_FN } -Optional +std::optional spirv::mapVulkanStorageClassToMemorySpace(spirv::StorageClass storageClass) { #define STORAGE_SPACE_MAP_FN(storage, space) \ case storage: \ @@ -110,7 +110,7 @@ MAP_FN(spirv::StorageClass::Function, 6) \ MAP_FN(spirv::StorageClass::Image, 7) -Optional +std::optional spirv::mapMemorySpaceToOpenCLStorageClass(Attribute memorySpaceAttr) { // Handle null memory space attribute specially. if (!memorySpaceAttr) @@ -137,7 +137,7 @@ #undef STORAGE_SPACE_MAP_FN } -Optional +std::optional spirv::mapOpenCLStorageClassToMemorySpace(spirv::StorageClass storageClass) { #define STORAGE_SPACE_MAP_FN(storage, space) \ case storage: \ @@ -165,8 +165,8 @@ // Pass through for all other types. addConversion([](Type type) { return type; }); - addConversion([this](BaseMemRefType memRefType) -> Optional { - Optional storage = + addConversion([this](BaseMemRefType memRefType) -> std::optional { + std::optional 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 --- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp @@ -48,7 +48,7 @@ auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs, Location loc) { auto cast = builder.create(loc, type, inputs); - return Optional(cast.getResult(0)); + return std::optional(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 --- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp @@ -184,7 +184,7 @@ /// Converts SPIR-V struct with a regular (according to `VulkanLayoutUtils`) /// offset to LLVM struct. Otherwise, the conversion is not supported. -static Optional +static std::optional convertStructTypeWithOffset(spirv::StructType type, LLVMTypeConverter &converter) { if (type != VulkanLayoutUtils::decorateType(type)) @@ -247,8 +247,8 @@ /// 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 convertArrayType(spirv::ArrayType type, - TypeConverter &converter) { +static std::optional convertArrayType(spirv::ArrayType type, + TypeConverter &converter) { unsigned stride = type.getArrayStride(); Type elementType = type.getElementType(); auto sizeInBytes = elementType.cast().getSizeInBytes(); @@ -271,8 +271,8 @@ /// 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 convertRuntimeArrayType(spirv::RuntimeArrayType type, - TypeConverter &converter) { +static std::optional convertRuntimeArrayType(spirv::RuntimeArrayType type, + TypeConverter &converter) { if (type.getArrayStride() != 0) return std::nullopt; auto elementType = converter.convertType(type.getElementType()); @@ -281,8 +281,8 @@ /// Converts SPIR-V struct to LLVM struct. There is no support of structs with /// member decorations. Also, only natural offset is supported. -static Optional convertStructType(spirv::StructType type, - LLVMTypeConverter &converter) { +static std::optional convertStructType(spirv::StructType type, + LLVMTypeConverter &converter) { SmallVector memberDecorations; type.getMemberDecorations(memberDecorations); if (!memberDecorations.empty()) diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp --- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp +++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp @@ -47,7 +47,7 @@ auto addUnrealizedCast = [](OpBuilder &builder, Type type, ValueRange inputs, Location loc) { auto cast = builder.create(loc, type, inputs); - return Optional(cast.getResult(0)); + return std::optional(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 --- a/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp @@ -1001,10 +1001,10 @@ assert(widestIntSupportedByTarget >= 2 && "Integer type too narrow"); // Allow unknown types. - addConversion([](Type ty) -> Optional { return ty; }); + addConversion([](Type ty) -> std::optional { return ty; }); // Scalar case. - addConversion([this](IntegerType ty) -> Optional { + addConversion([this](IntegerType ty) -> std::optional { unsigned width = ty.getWidth(); if (width <= maxIntWidth) return ty; @@ -1017,7 +1017,7 @@ }); // Vector case. - addConversion([this](VectorType ty) -> Optional { + addConversion([this](VectorType ty) -> std::optional { auto intTy = ty.getElementType().dyn_cast(); if (!intTy) return ty; @@ -1038,7 +1038,7 @@ }); // Function case. - addConversion([this](FunctionType ty) -> Optional { + addConversion([this](FunctionType ty) -> std::optional { // Convert inputs and results, e.g.: // (i2N, i2N) -> i2N --> (vector<2xiN>, vector<2xiN>) -> vector<2xiN> SmallVector inputs; diff --git a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp --- a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp @@ -128,11 +128,11 @@ target .addDynamicallyLegalOp( - [&solver](Operation *op) -> Optional { + [&solver](Operation *op) -> std::optional { return failed(staticallyNonNegative(solver, op)); }); target.addDynamicallyLegalOp( - [&solver](CmpIOp op) -> Optional { + [&solver](CmpIOp op) -> std::optional { return failed(isCmpIConvertable(solver, op)); }); diff --git a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp --- a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp +++ b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp @@ -145,7 +145,7 @@ void memref::populateMemRefWideIntEmulationConversions( arith::WideIntEmulationConverter &typeConverter) { typeConverter.addConversion( - [&typeConverter](MemRefType ty) -> Optional { + [&typeConverter](MemRefType ty) -> std::optional { auto intTy = ty.getElementType().dyn_cast(); if (!intTy) return ty; diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp @@ -66,19 +66,19 @@ unsigned ArrayType::getArrayStride() const { return getImpl()->stride; } void ArrayType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getElementType().cast().getExtensions(extensions, storage); } void ArrayType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { getElementType().cast().getCapabilities(capabilities, storage); } -Optional ArrayType::getSizeInBytes() { +std::optional ArrayType::getSizeInBytes() { auto elementType = getElementType().cast(); - Optional size = elementType.getSizeInBytes(); + std::optional size = elementType.getSizeInBytes(); if (!size) return std::nullopt; return (*size + getArrayStride()) * getNumElements(); @@ -153,7 +153,7 @@ void CompositeType::getExtensions( SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { TypeSwitch(*this) .Case( @@ -167,7 +167,7 @@ void CompositeType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { TypeSwitch(*this) .Case( @@ -185,13 +185,13 @@ .Default([](Type) { llvm_unreachable("invalid composite type"); }); } -Optional CompositeType::getSizeInBytes() { +std::optional CompositeType::getSizeInBytes() { if (auto arrayType = dyn_cast()) return arrayType.getSizeInBytes(); if (auto structType = dyn_cast()) return structType.getSizeInBytes(); if (auto vectorType = dyn_cast()) { - Optional elementSize = + std::optional elementSize = vectorType.getElementType().cast().getSizeInBytes(); if (!elementSize) return std::nullopt; @@ -247,7 +247,7 @@ void CooperativeMatrixNVType::getExtensions( SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getElementType().cast().getExtensions(extensions, storage); static const Extension exts[] = {Extension::SPV_NV_cooperative_matrix}; ArrayRef ref(exts, std::size(exts)); @@ -256,7 +256,7 @@ void CooperativeMatrixNVType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { getElementType().cast().getCapabilities(capabilities, storage); static const Capability caps[] = {Capability::CooperativeMatrixNV}; ArrayRef ref(caps, std::size(caps)); @@ -315,7 +315,7 @@ void JointMatrixINTELType::getExtensions( SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getElementType().cast().getExtensions(extensions, storage); static const Extension exts[] = {Extension::SPV_INTEL_joint_matrix}; ArrayRef ref(exts, std::size(exts)); @@ -324,7 +324,7 @@ void JointMatrixINTELType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { getElementType().cast().getCapabilities(capabilities, storage); static const Capability caps[] = {Capability::JointMatrixINTEL}; ArrayRef ref(caps, std::size(caps)); @@ -434,12 +434,13 @@ ImageFormat ImageType::getImageFormat() const { return getImpl()->format; } void ImageType::getExtensions(SPIRVType::ExtensionArrayRefVector &, - Optional) { + std::optional) { // Image types do not require extra extensions thus far. } void ImageType::getCapabilities( - SPIRVType::CapabilityArrayRefVector &capabilities, Optional) { + SPIRVType::CapabilityArrayRefVector &capabilities, + std::optional) { if (auto dimCaps = spirv::getCapabilities(getDim())) capabilities.push_back(*dimCaps); @@ -484,7 +485,7 @@ } void PointerType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional 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().getExtensions(extensions, @@ -496,7 +497,7 @@ void PointerType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional 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().getCapabilities(capabilities, @@ -544,13 +545,13 @@ void RuntimeArrayType::getExtensions( SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getElementType().cast().getExtensions(extensions, storage); } void RuntimeArrayType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { { static const Capability caps[] = {Capability::Shader}; ArrayRef ref(caps, std::size(caps)); @@ -589,7 +590,7 @@ } void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional 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::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { unsigned bitwidth = getIntOrFloatBitWidth(); // 8- or 16-bit integer/floating-point numbers will require extra capabilities @@ -707,7 +708,7 @@ #undef WIDTH_CASE } -Optional ScalarType::getSizeInBytes() { +std::optional 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 @@ } void SPIRVType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { if (auto scalarType = dyn_cast()) { scalarType.getExtensions(extensions, storage); } else if (auto compositeType = dyn_cast()) { @@ -760,7 +761,7 @@ void SPIRVType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { if (auto scalarType = dyn_cast()) { scalarType.getCapabilities(capabilities, storage); } else if (auto compositeType = dyn_cast()) { @@ -778,7 +779,7 @@ } } -Optional SPIRVType::getSizeInBytes() { +std::optional SPIRVType::getSizeInBytes() { if (auto scalarType = dyn_cast()) return scalarType.getSizeInBytes(); if (auto compositeType = dyn_cast()) @@ -828,13 +829,13 @@ void SampledImageType::getExtensions( SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getImageType().cast().getExtensions(extensions, storage); } void SampledImageType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { getImageType().cast().getCapabilities(capabilities, storage); } @@ -1128,14 +1129,14 @@ } void StructType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { for (Type elementType : getElementTypes()) elementType.cast().getExtensions(extensions, storage); } void StructType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { for (Type elementType : getElementTypes()) elementType.cast().getCapabilities(capabilities, storage); } @@ -1227,13 +1228,13 @@ } void MatrixType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage) { + std::optional storage) { getColumnType().cast().getExtensions(extensions, storage); } void MatrixType::getCapabilities( SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage) { + std::optional storage) { { static const Capability caps[] = {Capability::Matrix}; ArrayRef ref(caps, std::size(caps)); diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp --- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp @@ -129,8 +129,8 @@ // 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 getTypeNumBytes(const SPIRVConversionOptions &options, - Type type) { +static std::optional +getTypeNumBytes(const SPIRVConversionOptions &options, Type type) { if (type.isa()) { auto bitWidth = type.getIntOrFloatBitWidth(); // According to the SPIR-V spec: @@ -203,10 +203,10 @@ } /// 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 storageClass = {}) { +static Type +convertScalarType(const spirv::TargetEnv &targetEnv, + const SPIRVConversionOptions &options, spirv::ScalarType type, + std::optional storageClass = {}) { // Get extension and capability requirements for the given type. SmallVector, 1> extensions; SmallVector, 2> capabilities; @@ -243,10 +243,10 @@ } /// 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 storageClass = {}) { +static Type +convertVectorType(const spirv::TargetEnv &targetEnv, + const SPIRVConversionOptions &options, VectorType type, + std::optional storageClass = {}) { auto scalarType = type.getElementType().cast(); if (type.getRank() <= 1 && type.getNumElements() == 1) return convertScalarType(targetEnv, options, scalarType, storageClass); @@ -299,8 +299,8 @@ return nullptr; } - Optional scalarSize = getTypeNumBytes(options, scalarType); - Optional tensorSize = getTypeNumBytes(options, type); + std::optional scalarSize = getTypeNumBytes(options, scalarType); + std::optional tensorSize = getTypeNumBytes(options, type); if (!scalarSize || !tensorSize) { LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot deduce element count\n"); @@ -311,7 +311,8 @@ auto arrayElemType = convertScalarType(targetEnv, options, scalarType); if (!arrayElemType) return nullptr; - Optional arrayElemSize = getTypeNumBytes(options, arrayElemType); + std::optional arrayElemSize = + getTypeNumBytes(options, arrayElemType); if (!arrayElemSize) { LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot deduce converted element size\n"); @@ -339,7 +340,8 @@ convertScalarType(targetEnv, options, elementType, storageClass); if (!arrayElemType) return nullptr; - Optional arrayElemSize = getTypeNumBytes(options, arrayElemType); + std::optional arrayElemSize = + getTypeNumBytes(options, arrayElemType); if (!arrayElemSize) { LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot deduce converted element size\n"); @@ -406,7 +408,8 @@ if (!arrayElemType) return nullptr; - Optional arrayElemSize = getTypeNumBytes(options, arrayElemType); + std::optional arrayElemSize = + getTypeNumBytes(options, arrayElemType); if (!arrayElemSize) { LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot deduce converted element size\n"); @@ -426,7 +429,7 @@ return wrapInStructAndGetPointer(arrayType, storageClass); } - Optional memrefSize = getTypeNumBytes(options, type); + std::optional memrefSize = getTypeNumBytes(options, type); if (!memrefSize) { LLVM_DEBUG(llvm::dbgs() << type << " illegal: cannot deduce element count\n"); @@ -458,13 +461,13 @@ addConversion([this](IndexType /*indexType*/) { return getIndexType(); }); - addConversion([this](IntegerType intType) -> Optional { + addConversion([this](IntegerType intType) -> std::optional { if (auto scalarType = intType.dyn_cast()) return convertScalarType(this->targetEnv, this->options, scalarType); return Type(); }); - addConversion([this](FloatType floatType) -> Optional { + addConversion([this](FloatType floatType) -> std::optional { if (auto scalarType = floatType.dyn_cast()) 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 --- a/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp @@ -84,7 +84,8 @@ /// 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 deduceCanonicalResource(ArrayRef types) { +static std::optional +deduceCanonicalResource(ArrayRef 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 @@ return std::nullopt; // Odd-sized vector has special layout // requirements. - Optional numBytes = type.getSizeInBytes(); + std::optional numBytes = type.getSizeInBytes(); if (!numBytes) return std::nullopt; @@ -280,7 +281,7 @@ elementTypes.push_back(type); } - Optional index = deduceCanonicalResource(elementTypes); + std::optional index = deduceCanonicalResource(elementTypes); if (!index) return; diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp @@ -178,7 +178,7 @@ } /// Maps a sparse tensor type to the appropriate compounded buffers. -static Optional +static std::optional convertSparseTensorType(Type type, SmallVectorImpl &fields) { auto enc = getSparseTensorEncoding(type); if (!enc) @@ -1039,7 +1039,7 @@ // Required by scf.for 1:N type conversion. addSourceMaterialization([](OpBuilder &builder, RankedTensorType tp, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { 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 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp @@ -39,7 +39,7 @@ //===----------------------------------------------------------------------===// /// Maps each sparse tensor type to an opaque pointer. -static Optional convertSparseTensorTypes(Type type) { +static std::optional 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 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -50,8 +50,9 @@ // Don't check this operation's children for conversion if the operation // is recursively legal. - auto legalityInfo = target ? target->isLegal(&op) - : Optional(); + auto legalityInfo = + target ? target->isLegal(&op) + : std::optional(); if (legalityInfo && legalityInfo->isRecursivelyLegal) continue; for (auto ®ion : op.getRegions()) { @@ -496,7 +497,7 @@ /// The conversion information for each of the arguments. The information is /// std::nullopt if the argument was dropped during conversion. - SmallVector, 1> argInfo; + SmallVector, 1> argInfo; /// The type converter used to convert the arguments. TypeConverter *converter; @@ -649,7 +650,7 @@ // Process the remapping for each of the original arguments. for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) { - Optional &argInfo = blockInfo.argInfo[i]; + std::optional &argInfo = blockInfo.argInfo[i]; BlockArgument origArg = origBlock->getArgument(i); // Handle the case of a 1->0 value mapping. @@ -888,7 +889,8 @@ /// 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 inputLoc, + LogicalResult remapValues(StringRef valueDiagTag, + std::optional inputLoc, PatternRewriter &rewriter, ValueRange values, SmallVectorImpl &remapped); @@ -1253,7 +1255,7 @@ } LogicalResult ConversionPatternRewriterImpl::remapValues( - StringRef valueDiagTag, Optional inputLoc, + StringRef valueDiagTag, std::optional inputLoc, PatternRewriter &rewriter, ValueRange values, SmallVectorImpl &remapped) { remapped.reserve(llvm::size(values)); @@ -2186,7 +2188,7 @@ // Check to see if any of the generated operations are invalid. if (llvm::any_of(pattern->getGeneratedOps(), [&](OperationName op) { - Optional action = target.getOpAction(op); + std::optional action = target.getOpAction(op); return !legalizerPatterns.count(op) && (!action || action == LegalizationAction::Illegal); })) @@ -2370,7 +2372,7 @@ LogicalResult legalizeUnresolvedMaterializations( ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, - Optional>> &inverseMapping); + std::optional>> &inverseMapping); /// Legalize an operation result that was marked as "erased". LogicalResult @@ -2479,7 +2481,7 @@ LogicalResult OperationConverter::finalize(ConversionPatternRewriter &rewriter) { - Optional>> inverseMapping; + std::optional>> inverseMapping; ConversionPatternRewriterImpl &rewriterImpl = rewriter.getImpl(); if (failed(legalizeUnresolvedMaterializations(rewriter, rewriterImpl, inverseMapping)) || @@ -2806,7 +2808,7 @@ LogicalResult OperationConverter::legalizeUnresolvedMaterializations( ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, - Optional>> &inverseMapping) { + std::optional>> &inverseMapping) { if (rewriterImpl.unresolvedMaterializations.empty()) return success(); inverseMapping = rewriterImpl.mapping.getInverse(); @@ -2961,7 +2963,7 @@ auto popConversionCallStack = llvm::make_scope_exit([this]() { conversionCallStack.pop_back(); }); for (ConversionCallbackFn &converter : llvm::reverse(conversions)) { - if (Optional result = + if (std::optional result = converter(t, results, conversionCallStack)) { if (!succeeded(*result)) { cachedDirectConversions.try_emplace(t, nullptr); @@ -3039,13 +3041,13 @@ MutableArrayRef materializations, OpBuilder &builder, Location loc, Type resultType, ValueRange inputs) { for (MaterializationCallbackFn &fn : llvm::reverse(materializations)) - if (Optional result = fn(builder, resultType, inputs, loc)) + if (std::optional result = fn(builder, resultType, inputs, loc)) return *result; return nullptr; } auto TypeConverter::convertBlockSignature(Block *block) - -> Optional { + -> std::optional { SignatureConversion conversion(block->getNumArguments()); if (failed(convertSignatureArgs(block->getArgumentTypes(), conversion))) return std::nullopt; @@ -3138,14 +3140,14 @@ } auto ConversionTarget::getOpAction(OperationName op) const - -> Optional { - Optional info = getOpInfo(op); - return info ? info->action : Optional(); + -> std::optional { + std::optional info = getOpInfo(op); + return info ? info->action : std::optional(); } auto ConversionTarget::isLegal(Operation *op) const - -> Optional { - Optional info = getOpInfo(op->getName()); + -> std::optional { + std::optional info = getOpInfo(op->getName()); if (!info) return std::nullopt; @@ -3153,7 +3155,7 @@ auto isOpLegal = [&] { // Handle dynamic legality either with the provided legality function. if (info->action == LegalizationAction::Dynamic) { - Optional result = info->legalityFn(op); + std::optional result = info->legalityFn(op); if (result) return *result; } @@ -3179,12 +3181,12 @@ } bool ConversionTarget::isIllegal(Operation *op) const { - Optional info = getOpInfo(op->getName()); + std::optional info = getOpInfo(op->getName()); if (!info) return false; if (info->action == LegalizationAction::Dynamic) { - Optional result = info->legalityFn(op); + std::optional result = info->legalityFn(op); if (!result) return false; @@ -3201,8 +3203,8 @@ return newCallback; auto chain = [oldCl = std::move(oldCallback), newCl = std::move(newCallback)]( - Operation *op) -> Optional { - if (Optional result = newCl(op)) + Operation *op) -> std::optional { + if (std::optional result = newCl(op)) return *result; return oldCl(op); @@ -3250,7 +3252,7 @@ } auto ConversionTarget::getOpInfo(OperationName op) const - -> Optional { + -> std::optional { // 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 --- a/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp +++ b/mlir/test/lib/Dialect/Arith/TestEmulateWideInt.cpp @@ -59,7 +59,7 @@ // 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 { + Location loc) -> std::optional { auto cast = builder.create(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 --- a/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp +++ b/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp @@ -73,7 +73,7 @@ typeConverter.addArgumentMaterialization( [](OpBuilder &builder, TupleType resultType, ValueRange inputs, - Location loc) -> Optional { + Location loc) -> std::optional { 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 --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -777,8 +777,9 @@ /// Hook for materializing a conversion. This is necessary because we generate /// 1->N type mappings. - static Optional materializeCast(OpBuilder &builder, Type resultType, - ValueRange inputs, Location loc) { + static std::optional materializeCast(OpBuilder &builder, + Type resultType, + ValueRange inputs, Location loc) { return builder.create(loc, resultType, inputs).getResult(); } }; @@ -1267,7 +1268,7 @@ // Convert a recursive self-referring type into a non-self-referring // type named "outer_converted_type" that contains a SimpleAType. [&](test::TestRecursiveType type, SmallVectorImpl &results, - ArrayRef callStack) -> Optional { + ArrayRef callStack) -> std::optional { // 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 --- a/mlir/test/lib/Transforms/TestDialectConversion.cpp +++ b/mlir/test/lib/Transforms/TestDialectConversion.cpp @@ -44,8 +44,9 @@ return success(); } /// Hook for materializing a conversion. - static Optional materializeCast(OpBuilder &builder, Type resultType, - ValueRange inputs, Location loc) { + static std::optional materializeCast(OpBuilder &builder, + Type resultType, + ValueRange inputs, Location loc) { return builder.create(loc, resultType, inputs) .getResult(0); } diff --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp --- a/mlir/unittests/Transforms/DialectConversion.cpp +++ b/mlir/unittests/Transforms/DialectConversion.cpp @@ -37,10 +37,11 @@ }); int callbackCalled2 = 0; - target.addDynamicallyLegalOp([&](Operation *) -> Optional { - callbackCalled2 = ++index; - return std::nullopt; - }); + target.addDynamicallyLegalOp( + [&](Operation *) -> std::optional { + callbackCalled2 = ++index; + return std::nullopt; + }); auto *op = createOp(&context); EXPECT_TRUE(target.isLegal(op)); @@ -58,10 +59,11 @@ int index = 0; int callbackCalled = 0; - target.addDynamicallyLegalOp([&](Operation *) -> Optional { - callbackCalled = ++index; - return std::nullopt; - }); + target.addDynamicallyLegalOp( + [&](Operation *) -> std::optional { + callbackCalled = ++index; + return std::nullopt; + }); auto *op = createOp(&context); EXPECT_FALSE(target.isLegal(op)); @@ -83,7 +85,7 @@ }); int callbackCalled2 = 0; - target.markUnknownOpDynamicallyLegal([&](Operation *) -> Optional { + target.markUnknownOpDynamicallyLegal([&](Operation *) -> std::optional { callbackCalled2 = ++index; return std::nullopt; }); @@ -103,7 +105,7 @@ ConversionTarget target(context); target.addDynamicallyLegalOp( - [&](Operation *) -> Optional { return std::nullopt; }); + [&](Operation *) -> std::optional { return std::nullopt; }); auto *op = createOp(&context); EXPECT_FALSE(target.isLegal(op)); @@ -120,7 +122,7 @@ ConversionTarget target(context); target.markUnknownOpDynamicallyLegal( - [&](Operation *) -> Optional { return std::nullopt; }); + [&](Operation *) -> std::optional { return std::nullopt; }); auto *op = createOp(&context); EXPECT_FALSE(target.isLegal(op));