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 @@ -118,6 +118,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; @@ -235,6 +236,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; @@ -290,6 +292,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; @@ -323,6 +326,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 @@ -71,6 +71,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()); } @@ -193,6 +199,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); } @@ -233,6 +245,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); } @@ -318,6 +336,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 {