From 11a4f5bdfb3f4ec1aee0ecbc9985bf6f5ea29f6d Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Mon, 26 Jun 2023 12:09:33 -0700 Subject: [PATCH] [mlir][sparse] minor code changes Submitting for Wren Reviewed By: K-Wu Differential Revision: https://reviews.llvm.org/D153804 --- .../mlir/Dialect/SparseTensor/IR/Enums.h | 2 +- .../SparseTensor/IR/SparseTensorAttrDefs.td | 2 ++ .../SparseTensor/IR/SparseTensorDialect.cpp | 18 +++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h index 825ee2d45322..522f2cd99b86 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 d6c971b0cd36..df37ceee1cb8 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 490e35dfa2d0..3b56c7b8d629 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,