diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h @@ -122,6 +122,7 @@ /// with respect to the given ranks. [[nodiscard]] bool isValid(Ranks const &ranks) const; + std::string str() const; void print(llvm::raw_ostream &os) const; void print(AsmPrinter &printer) const; void dump() const; @@ -251,6 +252,7 @@ bool isFunctionOf(VarSet const &vars) const; void getFreeVars(VarSet &vars) const; + std::string str(bool wantElision = true) const; void print(llvm::raw_ostream &os, bool wantElision = true) const; void print(AsmPrinter &printer, bool wantElision = true) const; void dump() const; @@ -306,6 +308,7 @@ bool isFunctionOf(VarSet const &vars) const; void getFreeVars(VarSet &vars) const; + std::string str(bool wantElision = true) const; void print(llvm::raw_ostream &os, bool wantElision = true) const; void print(AsmPrinter &printer, bool wantElision = true) const; void dump() const; @@ -339,6 +342,7 @@ AffineMap getDimToLvlMap(MLIRContext *context) const; AffineMap getLvlToDimMap(MLIRContext *context) const; + std::string str(bool wantElision = true) const; void print(llvm::raw_ostream &os, bool wantElision = true) const; void print(AsmPrinter &printer, bool wantElision = true) const; void dump() const; diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp @@ -98,6 +98,12 @@ print(llvm::errs()); llvm::errs() << "\n"; } +std::string DimLvlExpr::str() const { + std::string str; + llvm::raw_string_ostream os(str); + print(os); + return os.str(); +} void DimLvlExpr::print(AsmPrinter &printer) const { print(printer.getStream()); } @@ -220,6 +226,12 @@ print(llvm::errs(), /*wantElision=*/false); llvm::errs() << "\n"; } +std::string DimSpec::str(bool wantElision) const { + std::string str; + llvm::raw_string_ostream os(str); + print(os, wantElision); + return os.str(); +} void DimSpec::print(AsmPrinter &printer, bool wantElision) const { print(printer.getStream(), wantElision); } @@ -260,6 +272,12 @@ print(llvm::errs(), /*wantElision=*/false); llvm::errs() << "\n"; } +std::string LvlSpec::str(bool wantElision) const { + std::string str; + llvm::raw_string_ostream os(str); + print(os, wantElision); + return os.str(); +} void LvlSpec::print(AsmPrinter &printer, bool wantElision) const { print(printer.getStream(), wantElision); } @@ -345,6 +363,12 @@ print(llvm::errs(), /*wantElision=*/false); llvm::errs() << "\n"; } +std::string DimLvlMap::str(bool wantElision) const { + std::string str; + llvm::raw_string_ostream os(str); + print(os, wantElision); + return os.str(); +} void DimLvlMap::print(AsmPrinter &printer, bool wantElision) const { print(printer.getStream(), wantElision); } diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h @@ -197,6 +197,7 @@ template constexpr std::optional dyn_cast() const; + std::string str() const; void print(llvm::raw_ostream &os) const; void print(AsmPrinter &printer) const; void dump() const; diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp @@ -25,6 +25,13 @@ // `Var` implementation. //===----------------------------------------------------------------------===// +std::string Var::str() const { + std::string str; + llvm::raw_string_ostream os(str); + print(os); + return os.str(); +} + void Var::print(AsmPrinter &printer) const { print(printer.getStream()); } void Var::print(llvm::raw_ostream &os) const {