[Mlir-commits] [mlir] 2a68213 - [mlir][sparse] Adding nodiscard annotations to `isWF`/`isValid` predicates

wren romano llvmlistbot at llvm.org
Mon Jul 31 14:40:12 PDT 2023


Author: wren romano
Date: 2023-07-31T14:40:05-07:00
New Revision: 2a682138584ec803578ba49aec93bdc66ab4dc95

URL: https://github.com/llvm/llvm-project/commit/2a682138584ec803578ba49aec93bdc66ab4dc95
DIFF: https://github.com/llvm/llvm-project/commit/2a682138584ec803578ba49aec93bdc66ab4dc95.diff

LOG: [mlir][sparse] Adding nodiscard annotations to `isWF`/`isValid` predicates

Depends On D156001

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D156007

Added: 
    

Modified: 
    mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
    mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
index a58ddcd4677414..9d8a4454364acd 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
@@ -114,7 +114,7 @@ class DimLvlExpr {
 
   /// Checks whether the variables bound/used by this spec are valid
   /// with respect to the given ranks.
-  bool isValid(Ranks const &ranks) const;
+  [[nodiscard]] bool isValid(Ranks const &ranks) const;
 
   void print(llvm::raw_ostream &os) const;
   void print(AsmPrinter &printer) const;
@@ -224,7 +224,7 @@ class DimSpec final {
   /// respect to the given ranks.  Note that null `DimExpr` is considered
   /// to be vacuously valid, and therefore calling `setExpr` invalidates
   /// the result of this predicate.
-  bool isValid(Ranks const &ranks) const;
+  [[nodiscard]] bool isValid(Ranks const &ranks) const;
 
   // TODO(wrengr): Use it or loose it.
   bool isFunctionOf(Var var) const;
@@ -273,7 +273,7 @@ class LvlSpec final {
   //
   // NOTE: Once we introduce "counting expressions" this will need
   // a more sophisticated implementation than `DimSpec::isValid` does.
-  bool isValid(Ranks const &ranks) const;
+  [[nodiscard]] bool isValid(Ranks const &ranks) const;
 
   // TODO(wrengr): Use it or loose it.
   bool isFunctionOf(Var var) const;
@@ -297,7 +297,7 @@ class DimLvlMap final {
 
   // Checks for integrity of variable-binding structure.
   // This is already called by the ctor.
-  bool isWF() const;
+  [[nodiscard]] bool isWF() const;
 
 public:
   DimLvlMap(unsigned symRank, ArrayRef<DimSpec> dimSpecs,

diff  --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
index cf5bc6d753de4f..f23d554aee6c24 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
@@ -60,7 +60,7 @@ namespace ir_detail {
 /// representation.
 enum class VarKind { Symbol = 1, Dimension = 0, Level = 2 };
 
-constexpr bool isWF(VarKind vk) {
+[[nodiscard]] constexpr bool isWF(VarKind vk) {
   const auto vk_ = to_underlying(vk);
   return 0 <= vk_ && vk_ <= 2;
 }
@@ -145,7 +145,7 @@ class Var {
   //
   // This must be public for `VarInfo` to use it (whereas we don't want
   // to expose the `impl` field via friendship).
-  static constexpr bool isWF_Num(Num n) { return n <= kMaxNum; }
+  [[nodiscard]] static constexpr bool isWF_Num(Num n) { return n <= kMaxNum; }
 
 protected:
   /// The underlying implementation of `Var`.  Note that this must be kept
@@ -297,10 +297,10 @@ class Ranks final {
   constexpr unsigned getDimRank() const { return getRank(VarKind::Dimension); }
   constexpr unsigned getLvlRank() const { return getRank(VarKind::Level); }
 
-  constexpr bool isValid(Var var) const {
+  [[nodiscard]] constexpr bool isValid(Var var) const {
     return var.getNum() < getRank(var.getKind());
   }
-  bool isValid(DimLvlExpr expr) const;
+  [[nodiscard]] bool isValid(DimLvlExpr expr) const;
 };
 static_assert(IsZeroCostAbstraction<Ranks>);
 


        


More information about the Mlir-commits mailing list