[Mlir-commits] [mlir] 11a4f5b - [mlir][sparse] minor code changes

Aart Bik llvmlistbot at llvm.org
Mon Jun 26 12:58:01 PDT 2023


Author: Aart Bik
Date: 2023-06-26T12:57:52-07:00
New Revision: 11a4f5bdfb3f4ec1aee0ecbc9985bf6f5ea29f6d

URL: https://github.com/llvm/llvm-project/commit/11a4f5bdfb3f4ec1aee0ecbc9985bf6f5ea29f6d
DIFF: https://github.com/llvm/llvm-project/commit/11a4f5bdfb3f4ec1aee0ecbc9985bf6f5ea29f6d.diff

LOG: [mlir][sparse] minor code changes

Submitting for Wren

Reviewed By: K-Wu

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
    mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
    mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index 825ee2d453220..522f2cd99b865 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -198,7 +198,7 @@ enum class LevelFormat : uint8_t {
 };
 
 /// Returns string representation of the given dimension level type.
-inline std::string toMLIRString(DimLevelType dlt) {
+constexpr const char *toMLIRString(DimLevelType dlt) {
   switch (dlt) {
   // TODO: should probably raise an error instead of printing it...
   case DimLevelType::Undef:

diff  --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
index d6c971b0cd36e..df37ceee1cb85 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
@@ -74,6 +74,8 @@ def SparseTensorDimSliceAttr : SparseTensor_Attr<"SparseTensorDimSlice", []> {
   );
 
   let extraClassDeclaration = [{
+    void print(llvm::raw_ostream &os) const;
+
     /// Special value for dynamic offset/size/stride.
     static constexpr int64_t kDynamic = -1;
     static constexpr bool isDynamic(int64_t v) { return v == kDynamic; }

diff  --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 490e35dfa2d05..3b56c7b8d6294 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -209,14 +209,18 @@ std::string SparseTensorDimSliceAttr::getStaticString(int64_t v) {
   return isDynamic(v) ? "?" : std::to_string(v);
 }
 
+void SparseTensorDimSliceAttr::print(llvm::raw_ostream &os) const {
+  os << '(';
+  os << getStaticString(getOffset());
+  os << ", ";
+  os << getStaticString(getSize());
+  os << ", ";
+  os << getStaticString(getStride());
+  os << ')';
+}
+
 void SparseTensorDimSliceAttr::print(AsmPrinter &printer) const {
-  printer << "(";
-  printer << getStaticString(getOffset());
-  printer << ", ";
-  printer << getStaticString(getSize());
-  printer << ", ";
-  printer << getStaticString(getStride());
-  printer << ")";
+  print(printer.getStream());
 }
 
 static ParseResult parseOptionalStaticSlice(int64_t &result,


        


More information about the Mlir-commits mailing list