[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.
This commit is contained in:
@@ -195,7 +195,7 @@ public:
|
||||
/// Finalize the most recently started operation definition.
|
||||
void finalizeOperationDefinition(
|
||||
Operation *op, SMRange nameLoc, SMLoc endLoc,
|
||||
ArrayRef<std::pair<unsigned, SMLoc>> resultGroups = std::nullopt);
|
||||
ArrayRef<std::pair<unsigned, SMLoc>> resultGroups = {});
|
||||
|
||||
/// Start a definition for a region nested under the current operation.
|
||||
void startRegionDefinition();
|
||||
|
||||
@@ -94,7 +94,7 @@ bool isReductionIterator(utils::IteratorType iteratorType);
|
||||
/// ```
|
||||
Value makeComposedPadHighOp(OpBuilder &b, Location loc, RankedTensorType type,
|
||||
Value source, Value padding, bool nofold,
|
||||
ValueRange typeDynDims = std::nullopt);
|
||||
ValueRange typeDynDims = {});
|
||||
|
||||
/// Returns GenericOp that copies an n-D memref. Unlike the current
|
||||
/// implementation of memref::CopyOp, this op can further tile, lower to loops
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace tensor {
|
||||
// for _static_ dimensions.
|
||||
PadOp createPadHighOp(RankedTensorType resType, Value source, Value pad,
|
||||
bool nofold, Location loc, OpBuilder &builder,
|
||||
ValueRange dynOutDims = std::nullopt);
|
||||
ValueRange dynOutDims = {});
|
||||
|
||||
// Creates dim ops for each dynamic dimension of the ranked tensor argument and
|
||||
// returns these as values.
|
||||
|
||||
@@ -157,8 +157,7 @@ public:
|
||||
|
||||
/// Invokes the function with the given name passing it the list of opaque
|
||||
/// pointers to the actual arguments.
|
||||
llvm::Error invokePacked(StringRef name,
|
||||
MutableArrayRef<void *> args = std::nullopt);
|
||||
llvm::Error invokePacked(StringRef name, MutableArrayRef<void *> args = {});
|
||||
|
||||
/// Trait that defines how a given type is passed to the JIT code. This
|
||||
/// defaults to passing the address but can be specialized.
|
||||
|
||||
@@ -106,7 +106,7 @@ class BlockRange final
|
||||
Block *, Block *, Block *> {
|
||||
public:
|
||||
using RangeBaseT::RangeBaseT;
|
||||
BlockRange(ArrayRef<Block *> blocks = std::nullopt);
|
||||
BlockRange(ArrayRef<Block *> blocks = {});
|
||||
BlockRange(SuccessorRange successors);
|
||||
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
|
||||
ArrayRef<Block *>, Arg>::value>>
|
||||
|
||||
@@ -454,15 +454,14 @@ public:
|
||||
/// 'parent'. `locs` contains the locations of the inserted arguments, and
|
||||
/// should match the size of `argTypes`.
|
||||
Block *createBlock(Region *parent, Region::iterator insertPt = {},
|
||||
TypeRange argTypes = std::nullopt,
|
||||
ArrayRef<Location> locs = std::nullopt);
|
||||
TypeRange argTypes = {}, ArrayRef<Location> 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<Location> locs = std::nullopt);
|
||||
Block *createBlock(Block *insertBefore, TypeRange argTypes = {},
|
||||
ArrayRef<Location> locs = {});
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Operation Creation
|
||||
|
||||
@@ -1200,7 +1200,7 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
|
||||
using ShapedType::Trait<UnrankedMemRefType>::getDimSize;
|
||||
using ShapedType::Trait<UnrankedMemRefType>::getDynamicDimIndex;
|
||||
|
||||
ArrayRef<int64_t> getShape() const { return std::nullopt; }
|
||||
ArrayRef<int64_t> getShape() const { return {}; }
|
||||
|
||||
/// [deprecated] Returns the memory space in old raw integer representation.
|
||||
/// New `Attribute getMemorySpace()` method should be used instead.
|
||||
@@ -1259,7 +1259,7 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
|
||||
using ShapedType::Trait<UnrankedTensorType>::getDimSize;
|
||||
using ShapedType::Trait<UnrankedTensorType>::getDynamicDimIndex;
|
||||
|
||||
ArrayRef<int64_t> getShape() const { return std::nullopt; }
|
||||
ArrayRef<int64_t> getShape() const { return {}; }
|
||||
}];
|
||||
let skipDefaultBuilders = 1;
|
||||
let genVerifyDecl = 1;
|
||||
|
||||
@@ -520,7 +520,7 @@ public:
|
||||
/// unreachable operations.
|
||||
virtual void inlineBlockBefore(Block *source, Block *dest,
|
||||
Block::iterator before,
|
||||
ValueRange argValues = std::nullopt);
|
||||
ValueRange argValues = {});
|
||||
|
||||
/// Inline the operations of block 'source' before the operation 'op'. The
|
||||
/// source block will be deleted and must have no uses. 'argValues' is used to
|
||||
@@ -529,7 +529,7 @@ public:
|
||||
/// The source block must have no successors. Otherwise, the resulting IR
|
||||
/// would have unreachable operations.
|
||||
void inlineBlockBefore(Block *source, Operation *op,
|
||||
ValueRange argValues = std::nullopt);
|
||||
ValueRange argValues = {});
|
||||
|
||||
/// Inline the operations of block 'source' into the end of block 'dest'. The
|
||||
/// source block will be deleted and must have no uses. 'argValues' is used to
|
||||
@@ -537,8 +537,7 @@ public:
|
||||
///
|
||||
/// The dest block must have no successors. Otherwise, the resulting IR would
|
||||
/// have unreachable operation.
|
||||
void mergeBlocks(Block *source, Block *dest,
|
||||
ValueRange argValues = std::nullopt);
|
||||
void mergeBlocks(Block *source, Block *dest, ValueRange argValues = {});
|
||||
|
||||
/// Split the operations starting at "before" (inclusive) out of the given
|
||||
/// block into a new block, and return it.
|
||||
|
||||
@@ -353,7 +353,7 @@ class RegionRange
|
||||
public:
|
||||
using RangeBaseT::RangeBaseT;
|
||||
|
||||
RegionRange(MutableArrayRef<Region> regions = std::nullopt);
|
||||
RegionRange(MutableArrayRef<Region> regions = {});
|
||||
|
||||
template <typename Arg, typename = std::enable_if_t<std::is_constructible<
|
||||
ArrayRef<std::unique_ptr<Region>>, Arg>::value>>
|
||||
|
||||
@@ -411,7 +411,8 @@ public:
|
||||
/// Return the users of the provided symbol operation.
|
||||
ArrayRef<Operation *> 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<Operation *>();
|
||||
}
|
||||
|
||||
/// Return true if the given symbol has no uses.
|
||||
|
||||
@@ -37,7 +37,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
|
||||
Type, Type, Type> {
|
||||
public:
|
||||
using RangeBaseT::RangeBaseT;
|
||||
TypeRange(ArrayRef<Type> types = std::nullopt);
|
||||
TypeRange(ArrayRef<Type> types = {});
|
||||
explicit TypeRange(OperandRange values);
|
||||
explicit TypeRange(ResultRange values);
|
||||
explicit TypeRange(ValueRange values);
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
/// 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<OperandSegment> operandSegments = std::nullopt);
|
||||
ArrayRef<OperandSegment> operandSegments = {});
|
||||
MutableOperandRange(Operation *owner);
|
||||
|
||||
/// Construct a new mutable range for the given OpOperand.
|
||||
@@ -409,7 +409,7 @@ public:
|
||||
: ValueRange(ResultRange(values)) {}
|
||||
ValueRange(ArrayRef<BlockArgument> values)
|
||||
: ValueRange(ArrayRef<Value>(values.data(), values.size())) {}
|
||||
ValueRange(ArrayRef<Value> values = std::nullopt);
|
||||
ValueRange(ArrayRef<Value> values = {});
|
||||
ValueRange(OperandRange values);
|
||||
ValueRange(ResultRange values);
|
||||
|
||||
|
||||
@@ -47,10 +47,9 @@ public:
|
||||
/// `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<std::string> disabledPatternLabels = std::nullopt,
|
||||
ArrayRef<std::string> enabledPatternLabels = std::nullopt);
|
||||
FrozenRewritePatternSet(RewritePatternSet &&patterns,
|
||||
ArrayRef<std::string> disabledPatternLabels = {},
|
||||
ArrayRef<std::string> enabledPatternLabels = {});
|
||||
|
||||
/// Return the op specific native patterns held by this list.
|
||||
const OpSpecificNativePatternListT &getOpSpecificNativePatterns() const {
|
||||
|
||||
@@ -226,8 +226,7 @@ public:
|
||||
/// Return an instance of the Tuple type.
|
||||
static TupleType get(Context &context, ArrayRef<Type> elementTypes,
|
||||
ArrayRef<StringRef> elementNames);
|
||||
static TupleType get(Context &context,
|
||||
ArrayRef<Type> elementTypes = std::nullopt);
|
||||
static TupleType get(Context &context, ArrayRef<Type> elementTypes = {});
|
||||
|
||||
/// Return the element types of this tuple.
|
||||
ArrayRef<Type> getElementTypes() const;
|
||||
|
||||
@@ -826,7 +826,7 @@ public:
|
||||
|
||||
/// PatternRewriter hook for inlining the ops of a block into another block.
|
||||
void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
|
||||
ValueRange argValues = std::nullopt) override;
|
||||
ValueRange argValues = {}) override;
|
||||
using PatternRewriter::inlineBlockBefore;
|
||||
|
||||
/// PatternRewriter hook for updating the given operation in-place.
|
||||
|
||||
@@ -62,8 +62,8 @@ std::unique_ptr<Pass> createCanonicalizerPass();
|
||||
/// set to their type name.
|
||||
std::unique_ptr<Pass>
|
||||
createCanonicalizerPass(const GreedyRewriteConfig &config,
|
||||
ArrayRef<std::string> disabledPatterns = std::nullopt,
|
||||
ArrayRef<std::string> enabledPatterns = std::nullopt);
|
||||
ArrayRef<std::string> disabledPatterns = {},
|
||||
ArrayRef<std::string> enabledPatterns = {});
|
||||
|
||||
/// Creates a pass to perform control-flow sinking.
|
||||
std::unique_ptr<Pass> createControlFlowSinkPass();
|
||||
|
||||
@@ -55,7 +55,7 @@ static bool isInsideLaunch(Operation *op) {
|
||||
static std::tuple<Value, OpFoldResult, SmallVector<OpFoldResult>>
|
||||
getFlatOffsetAndStrides(OpBuilder &rewriter, Location loc, Value source,
|
||||
ArrayRef<OpFoldResult> subOffsets,
|
||||
ArrayRef<OpFoldResult> subStrides = std::nullopt) {
|
||||
ArrayRef<OpFoldResult> subStrides = {}) {
|
||||
auto sourceType = cast<MemRefType>(source.getType());
|
||||
auto sourceRank = static_cast<unsigned>(sourceType.getRank());
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
class Key {
|
||||
public:
|
||||
/// Constructs a key for an identified struct.
|
||||
Key(StringRef name, bool opaque, ArrayRef<Type> types = std::nullopt)
|
||||
Key(StringRef name, bool opaque, ArrayRef<Type> types = {})
|
||||
: types(types), name(name), identified(true), packed(false),
|
||||
opaque(opaque) {}
|
||||
/// Constructs a key for a literal struct.
|
||||
|
||||
@@ -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<Statistic> stats = std::nullopt) {
|
||||
MutableArrayRef<Statistic> stats = {}) {
|
||||
os.indent(indent) << pass << "\n";
|
||||
if (stats.empty())
|
||||
return;
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
using namespace mlir;
|
||||
using namespace mlir::detail;
|
||||
|
||||
static Operation *createOp(MLIRContext *context,
|
||||
ArrayRef<Value> operands = std::nullopt,
|
||||
ArrayRef<Type> resultTypes = std::nullopt,
|
||||
static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
|
||||
ArrayRef<Type> resultTypes = {},
|
||||
unsigned int numRegions = 0) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
static Operation *createOp(MLIRContext *context,
|
||||
ArrayRef<Value> operands = std::nullopt,
|
||||
ArrayRef<Type> resultTypes = std::nullopt,
|
||||
static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
|
||||
ArrayRef<Type> resultTypes = {},
|
||||
unsigned int numRegions = 0) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(
|
||||
|
||||
Reference in New Issue
Block a user