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.

0 commit comments

Comments
 (0)