diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h --- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h @@ -198,7 +198,7 @@ }; /// 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 --- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td @@ -74,6 +74,8 @@ ); 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 --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -209,14 +209,18 @@ 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,