Skip to content

Commit 887222e

Browse files
[mlir] Migrate away from ArrayRef(std::nullopt) (NFC) (#144989)
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch takes care of the mlir side of the migration, starting with straightforward places where I see ArrayRef or ValueRange nearby. Note that ValueRange has a constructor that forwards arguments to an ArrayRef constructor.
1 parent 3f1de19 commit 887222e

File tree

21 files changed

+33
-39
lines changed

21 files changed

+33
-39
lines changed

mlir/include/mlir/AsmParser/AsmParserState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class AsmParserState {
195195
/// Finalize the most recently started operation definition.
196196
void finalizeOperationDefinition(
197197
Operation *op, SMRange nameLoc, SMLoc endLoc,
198-
ArrayRef<std::pair<unsigned, SMLoc>> resultGroups = std::nullopt);
198+
ArrayRef<std::pair<unsigned, SMLoc>> resultGroups = {});
199199

200200
/// Start a definition for a region nested under the current operation.
201201
void startRegionDefinition();

mlir/include/mlir/Dialect/Linalg/Utils/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool isReductionIterator(utils::IteratorType iteratorType);
9494
/// ```
9595
Value makeComposedPadHighOp(OpBuilder &b, Location loc, RankedTensorType type,
9696
Value source, Value padding, bool nofold,
97-
ValueRange typeDynDims = std::nullopt);
97+
ValueRange typeDynDims = {});
9898

9999
/// Returns GenericOp that copies an n-D memref. Unlike the current
100100
/// implementation of memref::CopyOp, this op can further tile, lower to loops

mlir/include/mlir/Dialect/Tensor/Utils/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace tensor {
3030
// for _static_ dimensions.
3131
PadOp createPadHighOp(RankedTensorType resType, Value source, Value pad,
3232
bool nofold, Location loc, OpBuilder &builder,
33-
ValueRange dynOutDims = std::nullopt);
33+
ValueRange dynOutDims = {});
3434

3535
// Creates dim ops for each dynamic dimension of the ranked tensor argument and
3636
// returns these as values.

mlir/include/mlir/ExecutionEngine/ExecutionEngine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ class ExecutionEngine {
157157

158158
/// Invokes the function with the given name passing it the list of opaque
159159
/// pointers to the actual arguments.
160-
llvm::Error invokePacked(StringRef name,
161-
MutableArrayRef<void *> args = std::nullopt);
160+
llvm::Error invokePacked(StringRef name, MutableArrayRef<void *> args = {});
162161

163162
/// Trait that defines how a given type is passed to the JIT code. This
164163
/// defaults to passing the address but can be specialized.

mlir/include/mlir/IR/BlockSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class BlockRange final
106106
Block *, Block *, Block *> {
107107
public:
108108
using RangeBaseT::RangeBaseT;
109-
BlockRange(ArrayRef<Block *> blocks = std::nullopt);
109+
BlockRange(ArrayRef<Block *> blocks = {});
110110
BlockRange(SuccessorRange successors);
111111
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
112112
ArrayRef<Block *>, Arg>::value>>

mlir/include/mlir/IR/Builders.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,14 @@ class OpBuilder : public Builder {
454454
/// 'parent'. `locs` contains the locations of the inserted arguments, and
455455
/// should match the size of `argTypes`.
456456
Block *createBlock(Region *parent, Region::iterator insertPt = {},
457-
TypeRange argTypes = std::nullopt,
458-
ArrayRef<Location> locs = std::nullopt);
457+
TypeRange argTypes = {}, ArrayRef<Location> locs = {});
459458

460459
/// Add new block with 'argTypes' arguments and set the insertion point to the
461460
/// end of it. The block is placed before 'insertBefore'. `locs` contains the
462461
/// locations of the inserted arguments, and should match the size of
463462
/// `argTypes`.
464-
Block *createBlock(Block *insertBefore, TypeRange argTypes = std::nullopt,
465-
ArrayRef<Location> locs = std::nullopt);
463+
Block *createBlock(Block *insertBefore, TypeRange argTypes = {},
464+
ArrayRef<Location> locs = {});
466465

467466
//===--------------------------------------------------------------------===//
468467
// Operation Creation

mlir/include/mlir/IR/BuiltinTypes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
12001200
using ShapedType::Trait<UnrankedMemRefType>::getDimSize;
12011201
using ShapedType::Trait<UnrankedMemRefType>::getDynamicDimIndex;
12021202

1203-
ArrayRef<int64_t> getShape() const { return std::nullopt; }
1203+
ArrayRef<int64_t> getShape() const { return {}; }
12041204

12051205
/// [deprecated] Returns the memory space in old raw integer representation.
12061206
/// New `Attribute getMemorySpace()` method should be used instead.
@@ -1259,7 +1259,7 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
12591259
using ShapedType::Trait<UnrankedTensorType>::getDimSize;
12601260
using ShapedType::Trait<UnrankedTensorType>::getDynamicDimIndex;
12611261

1262-
ArrayRef<int64_t> getShape() const { return std::nullopt; }
1262+
ArrayRef<int64_t> getShape() const { return {}; }
12631263
}];
12641264
let skipDefaultBuilders = 1;
12651265
let genVerifyDecl = 1;

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class RewriterBase : public OpBuilder {
520520
/// unreachable operations.
521521
virtual void inlineBlockBefore(Block *source, Block *dest,
522522
Block::iterator before,
523-
ValueRange argValues = std::nullopt);
523+
ValueRange argValues = {});
524524

525525
/// Inline the operations of block 'source' before the operation 'op'. The
526526
/// source block will be deleted and must have no uses. 'argValues' is used to
@@ -529,16 +529,15 @@ class RewriterBase : public OpBuilder {
529529
/// The source block must have no successors. Otherwise, the resulting IR
530530
/// would have unreachable operations.
531531
void inlineBlockBefore(Block *source, Operation *op,
532-
ValueRange argValues = std::nullopt);
532+
ValueRange argValues = {});
533533

534534
/// Inline the operations of block 'source' into the end of block 'dest'. The
535535
/// source block will be deleted and must have no uses. 'argValues' is used to
536536
/// replace the block arguments of 'source'
537537
///
538538
/// The dest block must have no successors. Otherwise, the resulting IR would
539539
/// have unreachable operation.
540-
void mergeBlocks(Block *source, Block *dest,
541-
ValueRange argValues = std::nullopt);
540+
void mergeBlocks(Block *source, Block *dest, ValueRange argValues = {});
542541

543542
/// Split the operations starting at "before" (inclusive) out of the given
544543
/// block into a new block, and return it.

mlir/include/mlir/IR/Region.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class RegionRange
353353
public:
354354
using RangeBaseT::RangeBaseT;
355355

356-
RegionRange(MutableArrayRef<Region> regions = std::nullopt);
356+
RegionRange(MutableArrayRef<Region> regions = {});
357357

358358
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
359359
ArrayRef<std::unique_ptr<Region>>, Arg>::value>>

mlir/include/mlir/IR/SymbolTable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ class SymbolUserMap {
411411
/// Return the users of the provided symbol operation.
412412
ArrayRef<Operation *> getUsers(Operation *symbol) const {
413413
auto it = symbolToUsers.find(symbol);
414-
return it != symbolToUsers.end() ? it->second.getArrayRef() : std::nullopt;
414+
return it != symbolToUsers.end() ? it->second.getArrayRef()
415+
: ArrayRef<Operation *>();
415416
}
416417

417418
/// Return true if the given symbol has no uses.

mlir/include/mlir/IR/TypeRange.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
3737
Type, Type, Type> {
3838
public:
3939
using RangeBaseT::RangeBaseT;
40-
TypeRange(ArrayRef<Type> types = std::nullopt);
40+
TypeRange(ArrayRef<Type> types = {});
4141
explicit TypeRange(OperandRange values);
4242
explicit TypeRange(ResultRange values);
4343
explicit TypeRange(ValueRange values);

mlir/include/mlir/IR/ValueRange.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class MutableOperandRange {
126126
/// and range length. `operandSegments` is an optional set of operand segments
127127
/// to be updated when mutating the operand list.
128128
MutableOperandRange(Operation *owner, unsigned start, unsigned length,
129-
ArrayRef<OperandSegment> operandSegments = std::nullopt);
129+
ArrayRef<OperandSegment> operandSegments = {});
130130
MutableOperandRange(Operation *owner);
131131

132132
/// Construct a new mutable range for the given OpOperand.
@@ -409,7 +409,7 @@ class ValueRange final
409409
: ValueRange(ResultRange(values)) {}
410410
ValueRange(ArrayRef<BlockArgument> values)
411411
: ValueRange(ArrayRef<Value>(values.data(), values.size())) {}
412-
ValueRange(ArrayRef<Value> values = std::nullopt);
412+
ValueRange(ArrayRef<Value> values = {});
413413
ValueRange(OperandRange values);
414414
ValueRange(ResultRange values);
415415

mlir/include/mlir/Rewrite/FrozenRewritePatternSet.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ class FrozenRewritePatternSet {
4747
/// `RewritePatternSet::addWithLabel`. Debug names may be empty, but patterns
4848
/// created with `RewritePattern::create` have their default debug name set to
4949
/// their type name.
50-
FrozenRewritePatternSet(
51-
RewritePatternSet &&patterns,
52-
ArrayRef<std::string> disabledPatternLabels = std::nullopt,
53-
ArrayRef<std::string> enabledPatternLabels = std::nullopt);
50+
FrozenRewritePatternSet(RewritePatternSet &&patterns,
51+
ArrayRef<std::string> disabledPatternLabels = {},
52+
ArrayRef<std::string> enabledPatternLabels = {});
5453

5554
/// Return the op specific native patterns held by this list.
5655
const OpSpecificNativePatternListT &getOpSpecificNativePatterns() const {

mlir/include/mlir/Tools/PDLL/AST/Types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ class TupleType : public Type::TypeBase<detail::TupleTypeStorage> {
226226
/// Return an instance of the Tuple type.
227227
static TupleType get(Context &context, ArrayRef<Type> elementTypes,
228228
ArrayRef<StringRef> elementNames);
229-
static TupleType get(Context &context,
230-
ArrayRef<Type> elementTypes = std::nullopt);
229+
static TupleType get(Context &context, ArrayRef<Type> elementTypes = {});
231230

232231
/// Return the element types of this tuple.
233232
ArrayRef<Type> getElementTypes() const;

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class ConversionPatternRewriter final : public PatternRewriter {
826826

827827
/// PatternRewriter hook for inlining the ops of a block into another block.
828828
void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
829-
ValueRange argValues = std::nullopt) override;
829+
ValueRange argValues = {}) override;
830830
using PatternRewriter::inlineBlockBefore;
831831

832832
/// PatternRewriter hook for updating the given operation in-place.

mlir/include/mlir/Transforms/Passes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ std::unique_ptr<Pass> createCanonicalizerPass();
6262
/// set to their type name.
6363
std::unique_ptr<Pass>
6464
createCanonicalizerPass(const GreedyRewriteConfig &config,
65-
ArrayRef<std::string> disabledPatterns = std::nullopt,
66-
ArrayRef<std::string> enabledPatterns = std::nullopt);
65+
ArrayRef<std::string> disabledPatterns = {},
66+
ArrayRef<std::string> enabledPatterns = {});
6767

6868
/// Creates a pass to perform control-flow sinking.
6969
std::unique_ptr<Pass> createControlFlowSinkPass();

mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static bool isInsideLaunch(Operation *op) {
5555
static std::tuple<Value, OpFoldResult, SmallVector<OpFoldResult>>
5656
getFlatOffsetAndStrides(OpBuilder &rewriter, Location loc, Value source,
5757
ArrayRef<OpFoldResult> subOffsets,
58-
ArrayRef<OpFoldResult> subStrides = std::nullopt) {
58+
ArrayRef<OpFoldResult> subStrides = {}) {
5959
auto sourceType = cast<MemRefType>(source.getType());
6060
auto sourceRank = static_cast<unsigned>(sourceType.getRank());
6161

mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct LLVMStructTypeStorage : public TypeStorage {
6969
class Key {
7070
public:
7171
/// Constructs a key for an identified struct.
72-
Key(StringRef name, bool opaque, ArrayRef<Type> types = std::nullopt)
72+
Key(StringRef name, bool opaque, ArrayRef<Type> types = {})
7373
: types(types), name(name), identified(true), packed(false),
7474
opaque(opaque) {}
7575
/// Constructs a key for a literal struct.

mlir/lib/Pass/PassStatistics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Statistic {
2727

2828
/// Utility to print a pass entry in the statistics output.
2929
static void printPassEntry(raw_ostream &os, unsigned indent, StringRef pass,
30-
MutableArrayRef<Statistic> stats = std::nullopt) {
30+
MutableArrayRef<Statistic> stats = {}) {
3131
os.indent(indent) << pass << "\n";
3232
if (stats.empty())
3333
return;

mlir/unittests/IR/OperationSupportTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
using namespace mlir;
1919
using namespace mlir::detail;
2020

21-
static Operation *createOp(MLIRContext *context,
22-
ArrayRef<Value> operands = std::nullopt,
23-
ArrayRef<Type> resultTypes = std::nullopt,
21+
static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
22+
ArrayRef<Type> resultTypes = {},
2423
unsigned int numRegions = 0) {
2524
context->allowUnregisteredDialects();
2625
return Operation::create(

mlir/unittests/IR/ValueTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
using namespace mlir;
1818

19-
static Operation *createOp(MLIRContext *context,
20-
ArrayRef<Value> operands = std::nullopt,
21-
ArrayRef<Type> resultTypes = std::nullopt,
19+
static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
20+
ArrayRef<Type> resultTypes = {},
2221
unsigned int numRegions = 0) {
2322
context->allowUnregisteredDialects();
2423
return Operation::create(

0 commit comments

Comments
 (0)