diff --git a/mlir/include/mlir/AsmParser/AsmParserState.h b/mlir/include/mlir/AsmParser/AsmParserState.h index 98bdc4696b846..e47cb32ee4027 100644 --- a/mlir/include/mlir/AsmParser/AsmParserState.h +++ b/mlir/include/mlir/AsmParser/AsmParserState.h @@ -195,7 +195,7 @@ class AsmParserState { /// Finalize the most recently started operation definition. void finalizeOperationDefinition( Operation *op, SMRange nameLoc, SMLoc endLoc, - ArrayRef> resultGroups = std::nullopt); + ArrayRef> resultGroups = {}); /// Start a definition for a region nested under the current operation. void startRegionDefinition(); diff --git a/mlir/include/mlir/CAPI/Wrap.h b/mlir/include/mlir/CAPI/Wrap.h index 5b68f417a3df4..fd5b6e18d4952 100644 --- a/mlir/include/mlir/CAPI/Wrap.h +++ b/mlir/include/mlir/CAPI/Wrap.h @@ -44,7 +44,7 @@ static llvm::ArrayRef unwrapList(size_t size, CTy *first, "incompatible C and C++ types"); if (size == 0) - return std::nullopt; + return {}; assert(storage.empty() && "expected to populate storage"); storage.reserve(size); diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 25f4f616aecf5..1ff55b48d3d8e 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -413,7 +413,7 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load", auto *inst = builder.CreateLoad($_resultType, $addr, $volatile_); $res = inst; if ($invariant) { - llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), std::nullopt); + llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), {}); inst->setMetadata(llvm::LLVMContext::MD_invariant_load, metadata); } }] # setOrderingCode diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td index 1e108c3d8ac77..22d905ebb0a40 100644 --- a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td +++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td @@ -363,7 +363,7 @@ def PDL_OperationOp : PDL_Op<"operation", [AttrSizedOperandSegments]> { let builders = [ OpBuilder<(ins CArg<"std::optional", "std::nullopt">:$name, CArg<"ValueRange", "std::nullopt">:$operandValues, - CArg<"ArrayRef", "std::nullopt">:$attrNames, + CArg<"ArrayRef", "{}">:$attrNames, CArg<"ValueRange", "std::nullopt">:$attrValues, CArg<"ValueRange", "std::nullopt">:$resultTypes), [{ auto nameAttr = name ? $_builder.getStringAttr(*name) : StringAttr(); diff --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h index 66f49c787c190..96ccebcd5685e 100644 --- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h +++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h @@ -157,8 +157,7 @@ class ExecutionEngine { /// Invokes the function with the given name passing it the list of opaque /// pointers to the actual arguments. - llvm::Error invokePacked(StringRef name, - MutableArrayRef args = std::nullopt); + llvm::Error invokePacked(StringRef name, MutableArrayRef args = {}); /// Trait that defines how a given type is passed to the JIT code. This /// defaults to passing the address but can be specialized. diff --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h index ff508891ac2ff..c8a70a5a1d959 100644 --- a/mlir/include/mlir/IR/BlockSupport.h +++ b/mlir/include/mlir/IR/BlockSupport.h @@ -106,7 +106,7 @@ class BlockRange final Block *, Block *, Block *> { public: using RangeBaseT::RangeBaseT; - BlockRange(ArrayRef blocks = std::nullopt); + BlockRange(ArrayRef blocks = {}); BlockRange(SuccessorRange successors); template , Arg>::value>> diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 6fb71ccefda15..d3bff27824ccb 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -465,14 +465,14 @@ class OpBuilder : public Builder { /// should match the size of `argTypes`. Block *createBlock(Region *parent, Region::iterator insertPt = {}, TypeRange argTypes = std::nullopt, - ArrayRef locs = std::nullopt); + ArrayRef locs = {}); /// Add new block with 'argTypes' arguments and set the insertion point to the /// end of it. The block is placed before 'insertBefore'. `locs` contains the /// locations of the inserted arguments, and should match the size of /// `argTypes`. Block *createBlock(Block *insertBefore, TypeRange argTypes = std::nullopt, - ArrayRef locs = std::nullopt); + ArrayRef locs = {}); //===--------------------------------------------------------------------===// // Operation Creation diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td index 492b8309a5ea3..cf0a37d28e9e7 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -516,7 +516,7 @@ def Builtin_DictionaryAttr : Builtin_Attr<"Dictionary", "dictionary"> { }]; let parameters = (ins ArrayRefParameter<"NamedAttribute", "">:$value); let builders = [ - AttrBuilder<(ins CArg<"ArrayRef", "std::nullopt">:$value)> + AttrBuilder<(ins CArg<"ArrayRef", "{}">:$value)> ]; let extraClassDeclaration = [{ using ValueType = ArrayRef; diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td index dca228097d782..26b8b4856bc18 100644 --- a/mlir/include/mlir/IR/BuiltinTypes.td +++ b/mlir/include/mlir/IR/BuiltinTypes.td @@ -1114,7 +1114,7 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [ using ShapedType::Trait::getDimSize; using ShapedType::Trait::getDynamicDimIndex; - ArrayRef getShape() const { return std::nullopt; } + ArrayRef getShape() const { return {}; } /// [deprecated] Returns the memory space in old raw integer representation. /// New `Attribute getMemorySpace()` method should be used instead. @@ -1173,7 +1173,7 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [ using ShapedType::Trait::getDimSize; using ShapedType::Trait::getDynamicDimIndex; - ArrayRef getShape() const { return std::nullopt; } + ArrayRef getShape() const { return {}; } }]; let skipDefaultBuilders = 1; let genVerifyDecl = 1; diff --git a/mlir/include/mlir/IR/Matchers.h b/mlir/include/mlir/IR/Matchers.h index 6fa5a47109d20..41a8ce2d58cb9 100644 --- a/mlir/include/mlir/IR/Matchers.h +++ b/mlir/include/mlir/IR/Matchers.h @@ -88,7 +88,7 @@ struct constant_op_binder { // Fold the constant to an attribute. SmallVector foldedOp; - LogicalResult result = op->fold(/*operands=*/std::nullopt, foldedOp); + LogicalResult result = op->fold(/*operands=*/{}, foldedOp); (void)result; assert(succeeded(result) && "expected ConstantLike op to be foldable"); diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h index 2ab0405043a54..c2f73e94680f9 100644 --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -853,8 +853,7 @@ class RewritePatternSet { RewritePatternSet &add(ConstructorArg &&arg, ConstructorArgs &&...args) { // The following expands a call to emplace_back for each of the pattern // types 'Ts'. - (addImpl(/*debugLabels=*/std::nullopt, - std::forward(arg), + (addImpl(/*debugLabels=*/{}, std::forward(arg), std::forward(args)...), ...); return *this; @@ -937,7 +936,7 @@ class RewritePatternSet { RewritePatternSet &insert(ConstructorArg &&arg, ConstructorArgs &&...args) { // The following expands a call to emplace_back for each of the pattern // types 'Ts'. - (addImpl(/*debugLabels=*/std::nullopt, arg, args...), ...); + (addImpl(/*debugLabels=*/{}, arg, args...), ...); return *this; } diff --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h index 93fc9dbb430ee..cfcd920b33460 100644 --- a/mlir/include/mlir/IR/Region.h +++ b/mlir/include/mlir/IR/Region.h @@ -353,7 +353,7 @@ class RegionRange public: using RangeBaseT::RangeBaseT; - RegionRange(MutableArrayRef regions = std::nullopt); + RegionRange(MutableArrayRef regions = {}); template >, Arg>::value>> diff --git a/mlir/include/mlir/IR/SymbolTable.h b/mlir/include/mlir/IR/SymbolTable.h index 597c6a9a1d891..b3953cdf42bdf 100644 --- a/mlir/include/mlir/IR/SymbolTable.h +++ b/mlir/include/mlir/IR/SymbolTable.h @@ -395,7 +395,8 @@ class SymbolUserMap { /// Return the users of the provided symbol operation. ArrayRef getUsers(Operation *symbol) const { auto it = symbolToUsers.find(symbol); - return it != symbolToUsers.end() ? it->second.getArrayRef() : std::nullopt; + return it != symbolToUsers.end() ? it->second.getArrayRef() + : ArrayRef(); } /// Return true if the given symbol has no uses. diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h index 99fabab334f92..67897c2c3db8f 100644 --- a/mlir/include/mlir/IR/TypeRange.h +++ b/mlir/include/mlir/IR/TypeRange.h @@ -36,7 +36,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base< Type, Type, Type> { public: using RangeBaseT::RangeBaseT; - TypeRange(ArrayRef types = std::nullopt); + TypeRange(ArrayRef types = {}); explicit TypeRange(OperandRange values); explicit TypeRange(ResultRange values); explicit TypeRange(ValueRange values); @@ -47,6 +47,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base< template , Arg>::value>> TypeRange(Arg &&arg) : TypeRange(ArrayRef(std::forward(arg))) {} + TypeRange(std::nullopt_t) : TypeRange(ArrayRef()) {} TypeRange(std::initializer_list types) : TypeRange(ArrayRef(types)) {} diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h index 4b421c08d8418..b934622fa80c1 100644 --- a/mlir/include/mlir/IR/ValueRange.h +++ b/mlir/include/mlir/IR/ValueRange.h @@ -123,7 +123,7 @@ class MutableOperandRange { /// and range length. `operandSegments` is an optional set of operand segments /// to be updated when mutating the operand list. MutableOperandRange(Operation *owner, unsigned start, unsigned length, - ArrayRef operandSegments = std::nullopt); + ArrayRef operandSegments = {}); MutableOperandRange(Operation *owner); /// Construct a new mutable range for the given OpOperand. @@ -392,6 +392,7 @@ class ValueRange final std::is_constructible, Arg>::value && !std::is_convertible::value>> ValueRange(Arg &&arg) : ValueRange(ArrayRef(std::forward(arg))) {} + ValueRange(std::nullopt_t) : ValueRange(ArrayRef()) {} ValueRange(const Value &value) : ValueRange(&value, /*count=*/1) {} ValueRange(const std::initializer_list &values) : ValueRange(ArrayRef(values)) {} @@ -401,7 +402,7 @@ class ValueRange final : ValueRange(ResultRange(values)) {} ValueRange(ArrayRef values) : ValueRange(ArrayRef(values.data(), values.size())) {} - ValueRange(ArrayRef values = std::nullopt); + ValueRange(ArrayRef values = {}); ValueRange(OperandRange values); ValueRange(ResultRange values); diff --git a/mlir/include/mlir/Rewrite/FrozenRewritePatternSet.h b/mlir/include/mlir/Rewrite/FrozenRewritePatternSet.h index 4c6e3cd9ce6f4..d6c431206e06e 100644 --- a/mlir/include/mlir/Rewrite/FrozenRewritePatternSet.h +++ b/mlir/include/mlir/Rewrite/FrozenRewritePatternSet.h @@ -47,10 +47,9 @@ class FrozenRewritePatternSet { /// `RewritePatternSet::addWithLabel`. Debug names may be empty, but patterns /// created with `RewritePattern::create` have their default debug name set to /// their type name. - FrozenRewritePatternSet( - RewritePatternSet &&patterns, - ArrayRef disabledPatternLabels = std::nullopt, - ArrayRef enabledPatternLabels = std::nullopt); + FrozenRewritePatternSet(RewritePatternSet &&patterns, + ArrayRef disabledPatternLabels = {}, + ArrayRef enabledPatternLabels = {}); /// Return the op specific native patterns held by this list. const OpSpecificNativePatternListT &getOpSpecificNativePatterns() const { diff --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h index 26bdf09abba21..1a89081074ec1 100644 --- a/mlir/include/mlir/Support/StorageUniquer.h +++ b/mlir/include/mlir/Support/StorageUniquer.h @@ -97,7 +97,7 @@ class StorageUniquer { template ArrayRef copyInto(ArrayRef elements) { if (elements.empty()) - return std::nullopt; + return {}; auto result = allocator.Allocate(elements.size()); std::uninitialized_copy(elements.begin(), elements.end(), result); return ArrayRef(result, elements.size()); diff --git a/mlir/include/mlir/Tools/PDLL/AST/Nodes.h b/mlir/include/mlir/Tools/PDLL/AST/Nodes.h index aed2562e4d30d..7a9e5048aebe7 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Nodes.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Nodes.h @@ -897,8 +897,8 @@ class UserConstraintDecl final ArrayRef results, const CompoundStmt *body, Type resultType) { - return createImpl(ctx, name, inputs, /*nativeInputTypes=*/std::nullopt, - results, /*codeBlock=*/std::nullopt, body, resultType); + return createImpl(ctx, name, inputs, /*nativeInputTypes=*/{}, results, + /*codeBlock=*/std::nullopt, body, resultType); } /// Return the name of the constraint. diff --git a/mlir/include/mlir/Tools/PDLL/AST/Types.h b/mlir/include/mlir/Tools/PDLL/AST/Types.h index 89c8e193ddc32..aa483a81f87f5 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Types.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Types.h @@ -253,8 +253,7 @@ class TupleType : public Type::TypeBase { /// Return an instance of the Tuple type. static TupleType get(Context &context, ArrayRef elementTypes, ArrayRef elementNames); - static TupleType get(Context &context, - ArrayRef elementTypes = std::nullopt); + static TupleType get(Context &context, ArrayRef elementTypes = {}); /// Return the element types of this tuple. ArrayRef getElementTypes() const; diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h index 41f208216374f..9cd2ef34e15ea 100644 --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -62,8 +62,8 @@ std::unique_ptr createCanonicalizerPass(); /// set to their type name. std::unique_ptr createCanonicalizerPass(const GreedyRewriteConfig &config, - ArrayRef disabledPatterns = std::nullopt, - ArrayRef enabledPatterns = std::nullopt); + ArrayRef disabledPatterns = {}, + ArrayRef enabledPatterns = {}); /// Creates a pass to perform control-flow sinking. std::unique_ptr createControlFlowSinkPass(); diff --git a/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp b/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp index b00cd0dee3ae8..cb10671ac5b79 100644 --- a/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp +++ b/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp @@ -991,7 +991,7 @@ void PDLToPDLInterpPass::runOnOperation() { module.getLoc(), pdl_interp::PDLInterpDialect::getMatcherFunctionName(), builder.getFunctionType(builder.getType(), /*results=*/std::nullopt), - /*attrs=*/std::nullopt); + /*attrs=*/ArrayRef()); // Create a nested module to hold the functions invoked for rewriting the IR // after a successful match. diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 5291f95d37144..9295f53ae6aec 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -243,8 +243,8 @@ static Value createLinalgBodyCalculationForElementwiseOp( auto shifted = rewriter.create(loc, resultTypes, args[0], subtract) ->getResults(); - auto truncated = - rewriter.create(loc, i1Ty, shifted, std::nullopt); + auto truncated = rewriter.create( + loc, i1Ty, shifted, llvm::ArrayRef()); auto isInputOdd = rewriter.create(loc, i1Ty, truncated, i1one); @@ -447,20 +447,20 @@ static Value createLinalgBodyCalculationForElementwiseOp( if (isa(srcTy) && isa(dstTy) && bitExtend) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); if (isa(srcTy) && isa(dstTy) && !bitExtend) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); // 1-bit integers need to be treated as signless. if (srcTy.isInteger(1) && arith::UIToFPOp::areCastCompatible(srcTy, dstTy)) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); if (srcTy.isInteger(1) && isa(dstTy) && bitExtend) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); // Unsigned integers need an unrealized cast so that they can be passed // to UIToFP. @@ -478,7 +478,7 @@ static Value createLinalgBodyCalculationForElementwiseOp( // All other si-to-fp conversions should be handled by SIToFP. if (arith::SIToFPOp::areCastCompatible(srcTy, dstTy)) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); // Casting to boolean, floats need to only be checked as not-equal to zero. if (isa(srcTy) && dstTy.isInteger(1)) { @@ -585,7 +585,7 @@ static Value createLinalgBodyCalculationForElementwiseOp( if (isa(srcTy) && isa(dstTy) && bitExtend) return rewriter.create(loc, resultTypes, args, - std::nullopt); + llvm::ArrayRef()); if (isa(srcTy) && isa(dstTy) && !bitExtend) { return rewriter.create(loc, dstTy, args[0]); diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp index a3e3f80954efc..fda8516a15c39 100644 --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -309,7 +309,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name, return; assert(type.getNumInputs() == argAttrs.size()); function_interface_impl::addArgAndResultAttrs( - builder, state, argAttrs, /*resultAttrs=*/std::nullopt, + builder, state, argAttrs, /*resultAttrs=*/{}, getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name)); } diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index fdc21d6c6e24b..17afc274e07a2 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -530,7 +530,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name, return; assert(type.getNumInputs() == argAttrs.size()); function_interface_impl::addArgAndResultAttrs( - builder, state, argAttrs, /*resultAttrs=*/std::nullopt, + builder, state, argAttrs, /*resultAttrs=*/{}, getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name)); } diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp index a490b4c3c4ab4..3037735d30c3b 100644 --- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp +++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp @@ -191,7 +191,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name, return; assert(type.getNumInputs() == argAttrs.size()); function_interface_impl::addArgAndResultAttrs( - builder, state, argAttrs, /*resultAttrs=*/std::nullopt, + builder, state, argAttrs, /*resultAttrs=*/{}, getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name)); } diff --git a/mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp b/mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp index 004d73a77e535..ad979d7b3ea43 100644 --- a/mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp @@ -55,7 +55,7 @@ static bool isInsideLaunch(Operation *op) { static std::tuple> getFlatOffsetAndStrides(OpBuilder &rewriter, Location loc, Value source, ArrayRef subOffsets, - ArrayRef subStrides = std::nullopt) { + ArrayRef subStrides = {}) { auto sourceType = cast(source.getType()); auto sourceRank = static_cast(sourceType.getRank()); @@ -110,8 +110,9 @@ static Value getFlatMemref(OpBuilder &rewriter, Location loc, Value source, auto &&[base, offset, ignore] = getFlatOffsetAndStrides(rewriter, loc, source, offsetsTemp); MemRefType retType = inferCastResultType(base, offset); - return rewriter.create(loc, retType, base, offset, - std::nullopt, std::nullopt); + return rewriter.create( + loc, retType, base, offset, llvm::ArrayRef(), + llvm::ArrayRef()); } static bool needFlatten(Value val) { diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 9bb0c80749a5f..3a1e1c48dcaad 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2510,7 +2510,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result, assert(llvm::cast(type).getNumParams() == argAttrs.size() && "expected as many argument attribute lists as arguments"); function_interface_impl::addArgAndResultAttrs( - builder, result, argAttrs, /*resultAttrs=*/std::nullopt, + builder, result, argAttrs, /*resultAttrs=*/{}, getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name)); } diff --git a/mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h b/mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h index 8767b1c3ffc5b..081a89d0b5dc7 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h +++ b/mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h @@ -69,7 +69,7 @@ struct LLVMStructTypeStorage : public TypeStorage { class Key { public: /// Constructs a key for an identified struct. - Key(StringRef name, bool opaque, ArrayRef types = std::nullopt) + Key(StringRef name, bool opaque, ArrayRef types = {}) : types(types), name(name), identified(true), packed(false), opaque(opaque) {} /// Constructs a key for a literal struct. diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp index 8eb8e579954fa..0aaa657ef2e16 100644 --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -1290,7 +1290,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name, return; assert(type.getNumInputs() == argAttrs.size()); function_interface_impl::addArgAndResultAttrs( - builder, state, argAttrs, /*resultAttrs=*/std::nullopt, + builder, state, argAttrs, /*resultAttrs=*/{}, getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name)); } diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp index 7eb3d5bcd07f1..ef61a65735ae1 100644 --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -710,7 +710,7 @@ SourceMgrDiagnosticVerifierHandlerImpl::computeExpectedDiags( raw_ostream &os, llvm::SourceMgr &mgr, const llvm::MemoryBuffer *buf) { // If the buffer is invalid, return an empty list. if (!buf) - return std::nullopt; + return {}; auto &expectedDiags = expectedDiagsPerFile[buf->getBufferIdentifier()]; // The number of the last line that did not correlate to a designator. diff --git a/mlir/lib/Interfaces/FunctionInterfaces.cpp b/mlir/lib/Interfaces/FunctionInterfaces.cpp index 80f47a3f83676..6ac5aead96926 100644 --- a/mlir/lib/Interfaces/FunctionInterfaces.cpp +++ b/mlir/lib/Interfaces/FunctionInterfaces.cpp @@ -44,14 +44,14 @@ function_interface_impl::getResultAttrDict(FunctionOpInterface op, ArrayRef function_interface_impl::getArgAttrs(FunctionOpInterface op, unsigned index) { auto argDict = getArgAttrDict(op, index); - return argDict ? argDict.getValue() : std::nullopt; + return argDict ? argDict.getValue() : ArrayRef(); } ArrayRef function_interface_impl::getResultAttrs(FunctionOpInterface op, unsigned index) { auto resultDict = getResultAttrDict(op, index); - return resultDict ? resultDict.getValue() : std::nullopt; + return resultDict ? resultDict.getValue() : ArrayRef(); } /// Get either the argument or result attributes array. diff --git a/mlir/lib/Pass/PassStatistics.cpp b/mlir/lib/Pass/PassStatistics.cpp index 779dcfe7b6661..01191aa824440 100644 --- a/mlir/lib/Pass/PassStatistics.cpp +++ b/mlir/lib/Pass/PassStatistics.cpp @@ -27,7 +27,7 @@ struct Statistic { /// Utility to print a pass entry in the statistics output. static void printPassEntry(raw_ostream &os, unsigned indent, StringRef pass, - MutableArrayRef stats = std::nullopt) { + MutableArrayRef stats = {}) { os.indent(indent) << pass << "\n"; if (stats.empty()) return; diff --git a/mlir/lib/Reducer/Tester.cpp b/mlir/lib/Reducer/Tester.cpp index 14760c0be70df..03f12af174839 100644 --- a/mlir/lib/Reducer/Tester.cpp +++ b/mlir/lib/Reducer/Tester.cpp @@ -68,7 +68,7 @@ Tester::Interestingness Tester::isInteresting(StringRef testCase) const { std::string errMsg; int result = llvm::sys::ExecuteAndWait( - testScript, testerArgs, /*Env=*/std::nullopt, /*Redirects=*/std::nullopt, + testScript, testerArgs, /*Env=*/std::nullopt, /*Redirects=*/{}, /*SecondsToWait=*/0, /*MemoryLimit=*/0, &errMsg); if (result < 0) diff --git a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp index 1dde457b5c34f..d98a90016c109 100644 --- a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp @@ -206,7 +206,7 @@ void LoopAnnotationConversion::convertLocation(FusedLoc location) { llvm::MDNode *LoopAnnotationConversion::convert() { // Reserve operand 0 for loop id self reference. - auto dummy = llvm::MDNode::getTemporary(ctx, std::nullopt); + auto dummy = llvm::MDNode::getTemporary(ctx, {}); metadataNodes.push_back(dummy.get()); if (FusedLoc startLoc = attr.getStartLoc()) diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 9e58d2a29199e..bdbb08602f4a6 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1713,7 +1713,7 @@ ModuleTranslation::getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr) { if (!scopeInserted) return scopeIt->second; llvm::LLVMContext &ctx = llvmModule->getContext(); - auto dummy = llvm::MDNode::getTemporary(ctx, std::nullopt); + auto dummy = llvm::MDNode::getTemporary(ctx, {}); // Convert the domain metadata node if necessary. auto [domainIt, insertedDomain] = aliasDomainMetadataMapping.try_emplace( aliasScopeAttr.getDomain(), nullptr); diff --git a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp index 964d94c9c0a46..f91abd714e285 100644 --- a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp +++ b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp @@ -350,8 +350,9 @@ Value CodeGen::genNonInitializerVar(const ast::VariableDecl *varDecl, Value results = builder.create( loc, pdl::RangeType::get(builder.getType()), /*types=*/ArrayAttr()); - return builder.create( - loc, opType.getName(), operands, std::nullopt, ValueRange(), results); + return builder.create(loc, opType.getName(), operands, + llvm::ArrayRef(), + ValueRange(), results); } if (ast::RangeType rangeTy = dyn_cast(type)) { diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 575fb4aacd947..fd10f21749144 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -984,8 +984,7 @@ ast::Decl *Parser::createODSNativePDLLConstraintDecl( // Build the native constraint. auto *constraintDecl = ast::UserConstraintDecl::createNative( ctx, ast::Name::create(ctx, name, loc), paramVar, - /*results=*/std::nullopt, codeBlock, ast::TupleType::get(ctx), - nativeType); + /*results=*/{}, codeBlock, ast::TupleType::get(ctx), nativeType); constraintDecl->setDocComment(ctx, docString); curDeclScope->add(constraintDecl); return constraintDecl; @@ -1780,7 +1779,7 @@ Parser::parseConstraint(std::optional &typeConstraint, FailureOr Parser::parseArgOrResultConstraint() { std::optional typeConstraint; - return parseConstraint(typeConstraint, /*existingConstraints=*/std::nullopt, + return parseConstraint(typeConstraint, /*existingConstraints=*/{}, /*allowInlineTypeConstraints=*/false); } @@ -2877,8 +2876,8 @@ Parser::validateOperationOperands(SMRange loc, std::optional name, SmallVectorImpl &operands) { return validateOperationOperandsOrResults( "operand", loc, odsOp ? odsOp->getLoc() : std::optional(), name, - operands, odsOp ? odsOp->getOperands() : std::nullopt, valueTy, - valueRangeTy); + operands, odsOp ? odsOp->getOperands() : ArrayRef(), + valueTy, valueRangeTy); } LogicalResult @@ -2887,7 +2886,8 @@ Parser::validateOperationResults(SMRange loc, std::optional name, SmallVectorImpl &results) { return validateOperationOperandsOrResults( "result", loc, odsOp ? odsOp->getLoc() : std::optional(), name, - results, odsOp ? odsOp->getResults() : std::nullopt, typeTy, typeRangeTy); + results, odsOp ? odsOp->getResults() : ArrayRef(), + typeTy, typeRangeTy); } void Parser::checkOperationResultTypeInferrence(SMRange loc, StringRef opName, @@ -2986,8 +2986,8 @@ LogicalResult Parser::validateOperationOperandsOrResults( // Otherwise, create dummy values for each of the entries so that we // adhere to the ODS signature. for (unsigned i = 0, e = odsValues.size(); i < e; ++i) { - values.push_back(ast::RangeExpr::create( - ctx, loc, /*elements=*/std::nullopt, rangeTy)); + values.push_back( + ast::RangeExpr::create(ctx, loc, /*elements=*/{}, rangeTy)); } return success(); } diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp index 76b066feb6930..3a822f9d0d4bb 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp @@ -1044,7 +1044,8 @@ class LSPSignatureHelpContext : public CodeCompleteContext { const ods::Operation *odsOp = opName ? odsContext.lookupOperation(*opName) : nullptr; codeCompleteOperationOperandOrResultSignature( - opName, odsOp, odsOp ? odsOp->getOperands() : std::nullopt, + opName, odsOp, + odsOp ? odsOp->getOperands() : ArrayRef(), currentNumOperands, "operand", "Value"); } @@ -1053,7 +1054,8 @@ class LSPSignatureHelpContext : public CodeCompleteContext { const ods::Operation *odsOp = opName ? odsContext.lookupOperation(*opName) : nullptr; codeCompleteOperationOperandOrResultSignature( - opName, odsOp, odsOp ? odsOp->getResults() : std::nullopt, + opName, odsOp, + odsOp ? odsOp->getResults() : ArrayRef(), currentNumResults, "result", "Type"); } diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp index e09ea10906164..d62f7a24a65b3 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -194,7 +194,7 @@ void TestSubElementsAccessAttr::print(::mlir::AsmPrinter &printer) const { ArrayRef TestExtern1DI64ElementsAttr::getElements() const { if (auto *blob = getHandle().getBlob()) return blob->getDataAs(); - return std::nullopt; + return {}; } //===----------------------------------------------------------------------===// diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp index 3df6cff3c0a60..3272cf638ca1d 100644 --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -985,7 +985,7 @@ struct TestPassthroughInvalidOp : public ConversionPattern { matchAndRewrite(Operation *op, ArrayRef operands, ConversionPatternRewriter &rewriter) const final { rewriter.replaceOpWithNewOp(op, std::nullopt, operands, - std::nullopt); + llvm::ArrayRef()); return success(); } }; @@ -1001,7 +1001,7 @@ struct TestDropAndReplaceInvalidOp : public ConversionPattern { matchAndRewrite(Operation *op, ArrayRef operands, ConversionPatternRewriter &rewriter) const final { rewriter.replaceOpWithNewOp(op, std::nullopt, ValueRange(), - std::nullopt); + llvm::ArrayRef()); return success(); } }; diff --git a/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp b/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp index 5b48e80749c8b..e9a57f9084220 100644 --- a/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp +++ b/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp @@ -25,7 +25,7 @@ static Operation *createOp(MLIRContext *context, Location loc, context->allowUnregisteredDialects(); return Operation::create(loc, OperationName(operationName, context), std::nullopt, std::nullopt, std::nullopt, - OpaqueProperties(nullptr), std::nullopt, numRegions); + OpaqueProperties(nullptr), BlockRange(), numRegions); } namespace { diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp index f94dc78445807..d4be24410d6b9 100644 --- a/mlir/unittests/IR/OperationSupportTest.cpp +++ b/mlir/unittests/IR/OperationSupportTest.cpp @@ -18,14 +18,13 @@ using namespace mlir; using namespace mlir::detail; -static Operation *createOp(MLIRContext *context, - ArrayRef operands = std::nullopt, - ArrayRef resultTypes = std::nullopt, +static Operation *createOp(MLIRContext *context, ArrayRef operands = {}, + ArrayRef resultTypes = {}, unsigned int numRegions = 0) { context->allowUnregisteredDialects(); return Operation::create( UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes, - operands, std::nullopt, nullptr, std::nullopt, numRegions); + operands, std::nullopt, nullptr, BlockRange(), numRegions); } namespace { @@ -34,7 +33,7 @@ TEST(OperandStorageTest, NonResizable) { Builder builder(&context); Operation *useOp = - createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16)); + createOp(&context, /*operands=*/{}, builder.getIntegerType(16)); Value operand = useOp->getResult(0); // Create a non-resizable operation with one operand. @@ -58,7 +57,7 @@ TEST(OperandStorageTest, Resizable) { Builder builder(&context); Operation *useOp = - createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16)); + createOp(&context, /*operands=*/{}, builder.getIntegerType(16)); Value operand = useOp->getResult(0); // Create a resizable operation with one operand. @@ -86,7 +85,7 @@ TEST(OperandStorageTest, RangeReplace) { Builder builder(&context); Operation *useOp = - createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16)); + createOp(&context, /*operands=*/{}, builder.getIntegerType(16)); Value operand = useOp->getResult(0); // Create a resizable operation with one operand. @@ -122,7 +121,7 @@ TEST(OperandStorageTest, MutableRange) { Builder builder(&context); Operation *useOp = - createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16)); + createOp(&context, /*operands=*/{}, builder.getIntegerType(16)); Value operand = useOp->getResult(0); // Create a resizable operation with one operand. @@ -159,8 +158,7 @@ TEST(OperandStorageTest, RangeErase) { Builder builder(&context); Type type = builder.getNoneType(); - Operation *useOp = - createOp(&context, /*operands=*/std::nullopt, {type, type}); + Operation *useOp = createOp(&context, /*operands=*/{}, {type, type}); Value operand1 = useOp->getResult(0); Value operand2 = useOp->getResult(1); @@ -190,8 +188,8 @@ TEST(OperationOrderTest, OrderIsAlwaysValid) { MLIRContext context; Builder builder(&context); - Operation *containerOp = createOp(&context, /*operands=*/std::nullopt, - /*resultTypes=*/std::nullopt, + Operation *containerOp = createOp(&context, /*operands=*/{}, + /*resultTypes=*/{}, /*numRegions=*/1); Region ®ion = containerOp->getRegion(0); Block *block = new Block(); diff --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp index 10d7fb041278d..389d80c19963f 100644 --- a/mlir/unittests/Transforms/DialectConversion.cpp +++ b/mlir/unittests/Transforms/DialectConversion.cpp @@ -15,7 +15,7 @@ static Operation *createOp(MLIRContext *context) { context->allowUnregisteredDialects(); return Operation::create( UnknownLoc::get(context), OperationName("foo.bar", context), std::nullopt, - std::nullopt, std::nullopt, /*properties=*/nullptr, std::nullopt, 0); + std::nullopt, std::nullopt, /*properties=*/nullptr, BlockRange(), 0); } namespace {