[mlir] Use std::optional instead of None in comments (NFC)
authorKazu Hirata <kazu@google.com>
Sun, 11 Dec 2022 01:11:23 +0000 (17:11 -0800)
committerKazu Hirata <kazu@google.com>
Sun, 11 Dec 2022 01:11:23 +0000 (17:11 -0800)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

17 files changed:
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
mlir/include/mlir/Analysis/Presburger/Simplex.h
mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
mlir/include/mlir/IR/OperationSupport.h
mlir/include/mlir/IR/SubElementInterfaces.h
mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
mlir/include/mlir/TableGen/Attribute.h
mlir/include/mlir/TableGen/Builder.h
mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/Analysis/Presburger/IntegerRelation.cpp
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/IR/SymbolTable.cpp
mlir/lib/TableGen/Attribute.cpp
mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp

index 2c4aa9f..772bcea 100644 (file)
@@ -460,18 +460,18 @@ public:
   /// variable (pos^th), i.e., the smallest known constant that is greater
   /// than or equal to 'exclusive upper bound' - 'lower bound' of the
   /// variable. This constant bound is guaranteed to be non-negative. Returns
-  /// None if it's not a constant. This method employs trivial (low complexity /
-  /// cost) checks and detection. Symbolic variables are treated specially,
-  /// i.e., it looks for constant differences between affine expressions
-  /// involving only the symbolic variables. `lb` and `ub` (along with the
-  /// `boundFloorDivisor`) are set to represent the lower and upper bound
-  /// associated with the constant difference: `lb`, `ub` have the coefficients,
-  /// and `boundFloorDivisor`, their divisor. `minLbPos` and `minUbPos` if
-  /// non-null are set to the position of the constant lower bound and upper
-  /// bound respectively (to the same if they are from an equality). Ex: if the
-  /// lower bound is [(s0 + s2 - 1) floordiv 32] for a system with three
-  /// symbolic variables, *lb = [1, 0, 1], lbDivisor = 32. See comments at
-  /// function definition for examples.
+  /// std::nullopt if it's not a constant. This method employs trivial (low
+  /// complexity / cost) checks and detection. Symbolic variables are treated
+  /// specially, i.e., it looks for constant differences between affine
+  /// expressions involving only the symbolic variables. `lb` and `ub` (along
+  /// with the `boundFloorDivisor`) are set to represent the lower and upper
+  /// bound associated with the constant difference: `lb`, `ub` have the
+  /// coefficients, and `boundFloorDivisor`, their divisor. `minLbPos` and
+  /// `minUbPos` if non-null are set to the position of the constant lower bound
+  /// and upper bound respectively (to the same if they are from an
+  /// equality). Ex: if the lower bound is [(s0 + s2 - 1) floordiv 32] for a
+  /// system with three symbolic variables, *lb = [1, 0, 1], lbDivisor = 32. See
+  /// comments at function definition for examples.
   Optional<MPInt> getConstantBoundOnDimSize(
       unsigned pos, SmallVectorImpl<MPInt> *lb = nullptr,
       MPInt *boundFloorDivisor = nullptr, SmallVectorImpl<MPInt> *ub = nullptr,
@@ -497,7 +497,7 @@ public:
   }
 
   /// Returns the constant bound for the pos^th variable if there is one;
-  /// None otherwise.
+  /// std::nullopt otherwise.
   Optional<MPInt> getConstantBound(BoundType type, unsigned pos) const;
   /// The same, but casts to int64_t. This is unsafe and will assert-fail if the
   /// value does not fit in an int64_t.
index bcbec8c..e5d9b6e 100644 (file)
@@ -804,7 +804,7 @@ public:
   bool isRationalSubsetOf(const IntegerRelation &rel);
 
   /// Returns the current sample point if it is integral. Otherwise, returns
-  /// None.
+  /// std::nullopt.
   Optional<SmallVector<MPInt, 8>> getSamplePointIfIntegral() const;
 
   /// Returns the current sample point, which may contain non-integer (rational)
index f78ebef..3ce4ea3 100644 (file)
@@ -129,7 +129,7 @@ struct ComputationSliceState {
   /// If this difference is empty, the slice is declared to be valid. Otherwise,
   /// return false as it implies that the effective fusion results in at least
   /// one iteration of the slice that was not originally in the source's domain.
-  /// If the validity cannot be determined, returns llvm:None.
+  /// If the validity cannot be determined, returns std::nullopt.
   Optional<bool> isSliceValid();
 
   void dump() const;
@@ -292,15 +292,16 @@ struct MemRefRegion {
   void setWrite(bool flag) { write = flag; }
 
   /// Returns a constant upper bound on the number of elements in this region if
-  /// bounded by a known constant (always possible for static shapes), None
-  /// otherwise. Note that the symbols of the region are treated specially,
-  /// i.e., the returned bounding constant holds for *any given* value of the
-  /// symbol variables. The 'shape' vector is set to the corresponding
-  /// dimension-wise bounds major to minor. The number of elements and all the
-  /// dimension-wise bounds are guaranteed to be non-negative. We use int64_t
-  /// instead of uint64_t since index types can be at most int64_t. `lbs` are
-  /// set to the lower bounds for each of the rank dimensions, and lbDivisors
-  /// contains the corresponding denominators for floorDivs.
+  /// bounded by a known constant (always possible for static shapes),
+  /// std::nullopt otherwise. Note that the symbols of the region are treated
+  /// specially, i.e., the returned bounding constant holds for *any given*
+  /// value of the symbol variables. The 'shape' vector is set to the
+  /// corresponding dimension-wise bounds major to minor. The number of elements
+  /// and all the dimension-wise bounds are guaranteed to be non-negative. We
+  /// use int64_t instead of uint64_t since index types can be at most
+  /// int64_t. `lbs` are set to the lower bounds for each of the rank
+  /// dimensions, and lbDivisors contains the corresponding denominators for
+  /// floorDivs.
   Optional<int64_t> getConstantBoundingSizeAndShape(
       SmallVectorImpl<int64_t> *shape = nullptr,
       std::vector<SmallVector<int64_t, 4>> *lbs = nullptr,
index 4081eb0..81ec026 100644 (file)
@@ -930,7 +930,7 @@ struct ExtractSliceOfPadTensorSwapPattern
   /// A function to control pattern application and rewrite logic.
   ///
   /// The function will be given the slice op and should return:
-  /// -  None: to fail the match and not apply the pattern;
+  /// -  std::nullopt: to fail the match and not apply the pattern;
   /// -  true: to apply the pattern with zero slice guard;
   /// - false: to apply the pattern without zero slice guard.
   ///
index b7d1e20..cfd8844 100644 (file)
@@ -134,8 +134,8 @@ public:
   /// Return if this operation is registered.
   bool isRegistered() const { return impl->isRegistered(); }
 
-  /// If this operation is registered, returns the registered information, None
-  /// otherwise.
+  /// If this operation is registered, returns the registered information,
+  /// std::nullopt otherwise.
   Optional<RegisteredOperationName> getRegisteredInfo() const;
 
   /// Returns true if the operation was registered with a particular trait, e.g.
index e284c04..87f4ae5 100644 (file)
@@ -56,9 +56,9 @@ public:
   // Registration
   //===--------------------------------------------------------------------===//
 
-  /// A replacement mapping function, which returns either None (to signal the
-  /// element wasn't handled), or a pair of the replacement element and a
-  /// WalkResult.
+  /// A replacement mapping function, which returns either std::nullopt (to
+  /// signal the element wasn't handled), or a pair of the replacement element
+  /// and a WalkResult.
   template <typename T>
   using ReplaceFnResult = Optional<std::pair<T, WalkResult>>;
   template <typename T>
index b390586..f206c51 100644 (file)
@@ -207,8 +207,8 @@ public:
 private:
   /// The minimum number of times the successor region will be invoked.
   unsigned lower;
-  /// The maximum number of times the successor region will be invoked or `None`
-  /// if an upper bound is not known.
+  /// The maximum number of times the successor region will be invoked or
+  /// `std::nullopt` if an upper bound is not known.
   Optional<unsigned> upper;
 };
 
index 6b81189..d0a9430 100644 (file)
@@ -57,7 +57,7 @@ public:
   StringRef getReturnType() const;
 
   // Return the type constraint corresponding to the type of this attribute, or
-  // None if this is not a TypedAttr.
+  // std::nullopt if this is not a TypedAttr.
   std::optional<Type> getValueType() const;
 
   // Returns the template getter method call which reads this attribute's
index a7ad871..d6e34b7 100644 (file)
@@ -39,7 +39,7 @@ public:
     StringRef getCppType() const;
 
     /// Return an optional string containing the name of this parameter. If
-    /// None, no name was specified for this parameter by the user.
+    /// std::nullopt, no name was specified for this parameter by the user.
     std::optional<StringRef> getName() const { return name; }
 
     /// Return an optional string containing the default value to use for this
index 11a5320..343d8db 100644 (file)
@@ -202,7 +202,7 @@ public:
 
   /// 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, None otherwise.
+  /// valid conversion for the signature on success, std::nullopt otherwise.
   Optional<SignatureConversion> convertBlockSignature(Block *block);
 
   /// Materialize a conversion from a set of types into one result type by
index 9186f92..a39bb49 100644 (file)
@@ -1378,13 +1378,13 @@ void IntegerRelation::constantFoldVarRange(unsigned pos, unsigned num) {
 
 /// Returns a non-negative constant bound on the extent (upper bound - lower
 /// bound) of the specified variable if it is found to be a constant; returns
-/// None if it's not a constant. This methods treats symbolic variables
+/// std::nullopt if it's not a constant. This methods treats symbolic variables
 /// specially, i.e., it looks for constant differences between affine
-/// expressions involving only the symbolic variables. See comments at
-/// function definition for example. 'lb', if provided, is set to the lower
-/// bound associated with the constant difference. Note that 'lb' is purely
-/// symbolic and thus will contain the coefficients of the symbolic variables
-/// and the constant coefficient.
+/// expressions involving only the symbolic variables. See comments at function
+/// definition for example. 'lb', if provided, is set to the lower bound
+/// associated with the constant difference. Note that 'lb' is purely symbolic
+/// and thus will contain the coefficients of the symbolic variables and the
+/// constant coefficient.
 //  Egs: 0 <= i <= 15, return 16.
 //       s0 + 2 <= i <= s0 + 17, returns 16. (s0 has to be a symbol)
 //       s0 + s1 + 16 <= d0 <= s0 + s1 + 31, returns 16.
index 590986e..1c291ab 100644 (file)
@@ -434,8 +434,9 @@ struct BytecodeDialect {
     return *dialect;
   }
 
-  /// The loaded dialect entry. This field is None if we haven't attempted to
-  /// load, nullptr if we failed to load, otherwise the loaded dialect.
+  /// The loaded dialect entry. This field is std::nullopt if we haven't
+  /// attempted to load, nullptr if we failed to load, otherwise the loaded
+  /// dialect.
   std::optional<Dialect *> dialect;
 
   /// The bytecode interface of the dialect, or nullptr if the dialect does not
index a4860e3..1afd98f 100644 (file)
@@ -769,8 +769,8 @@ void LoadOp::print(OpAsmPrinter &p) {
 }
 
 // Extract the pointee type from the LLVM pointer type wrapped in MLIR. Return
-// the resulting type if any, null type if opaque pointers are used, and None
-// if the given type is not the pointer type.
+// the resulting type if any, null type if opaque pointers are used, and
+// std::nullopt if the given type is not the pointer type.
 static Optional<Type> getLoadStoreElementType(OpAsmParser &parser, Type type,
                                               SMLoc trailingTypeLoc) {
   auto llvmTy = type.dyn_cast<LLVM::LLVMPointerType>();
index 1f659d4..11bb980 100644 (file)
@@ -749,8 +749,8 @@ static Optional<SymbolTable::UseRange> getSymbolUsesImpl(FromT from) {
 /// symbol tables, and will also only return uses on 'from' if it does not
 /// also define a symbol table. This is because we treat the region as the
 /// boundary of the symbol table, and not the op itself. This function returns
-/// None if there are any unknown operations that may potentially be symbol
-/// tables.
+/// std::nullopt if there are any unknown operations that may potentially be
+/// symbol tables.
 auto SymbolTable::getSymbolUses(Operation *from) -> Optional<UseRange> {
   return getSymbolUsesImpl(from);
 }
index 2018ecc..57c77c7 100644 (file)
@@ -69,7 +69,7 @@ StringRef Attribute::getReturnType() const {
 }
 
 // Return the type constraint corresponding to the type of this attribute, or
-// None if this is not a TypedAttr.
+// std::nullopt if this is not a TypedAttr.
 std::optional<Type> Attribute::getValueType() const {
   if (auto *defInit = dyn_cast<llvm::DefInit>(def->getValueInit("valueType")))
     return Type(defInit->getDef());
index e942238..2fb3422 100644 (file)
@@ -495,7 +495,7 @@ struct ArgConverter {
     Block *origBlock;
 
     /// The conversion information for each of the arguments. The information is
-    /// None if the argument was dropped during conversion.
+    /// std::nullopt if the argument was dropped during conversion.
     SmallVector<Optional<ConvertedArgInfo>, 1> argInfo;
 
     /// The type converter used to convert the arguments.
index 9620a86..4199e97 100644 (file)
@@ -2434,7 +2434,7 @@ static bool isOptionallyParsed(FormatElement *el) {
 /// element that satisfies `isInvalid`, skipping any optionally-parsed elements.
 /// If an optional group is encountered, this function recurses into the 'then'
 /// and 'else' elements to check if they are invalid. Returns `success` if the
-/// range is known to be valid or `None` if scanning reached the end.
+/// range is known to be valid or `std::nullopt` if scanning reached the end.
 ///
 /// Since the guard element of an optional group is required, this function
 /// accepts an optional element pointer to mark it as required.