[Mlir-commits] [mlir] [mlir][sparse] Change sparse_tensor.print format (PR #91528)
Aart Bik
llvmlistbot at llvm.org
Wed May 8 14:29:37 PDT 2024
================
@@ -842,6 +844,31 @@ struct PrintRewriter : public OpRewritePattern<PrintOp> {
rewriter.create<vector::PrintOp>(loc, vector::PrintPunctuation::Close);
}
+ // Helper method to print the ending of memref (no punctuation after the last
+ // element).
+ static void printEnding(PatternRewriter &rewriter, Location loc, Value indVar,
+ Value step, Value upperBound, bool isComplex,
+ Value val) {
+ auto bound = rewriter.create<arith::AddIOp>(loc, indVar, step);
+ Value cond = rewriter.create<arith::CmpIOp>(loc, arith::CmpIPredicate::eq,
+ bound, upperBound);
+ scf::IfOp ifOp = rewriter.create<scf::IfOp>(loc, cond, /*else*/ true);
+ if (isComplex) {
----------------
aartbik wrote:
Use this
// Actual contents printing.
auto val = rewriter.create<memref::LoadOp>(loc, vec, idxs);
if (llvm::isa<ComplexType>(val.getType())) {
// Since the vector dialect does not support complex types in any op,
// we split those into (real, imag) pairs here.
Value real = rewriter.create<complex::ReOp>(loc, val);
Value imag = rewriter.create<complex::ImOp>(loc, val);
rewriter.create<vector::PrintOp>(loc, vector::PrintPunctuation::Open);
rewriter.create<vector::PrintOp>(loc, real,
vector::PrintPunctuation::Comma);
rewriter.create<vector::PrintOp>(loc, imag,
vector::PrintPunctuation::Close);
} else {
rewriter.create<vector::PrintOp>(loc, val, vector::PrintPunctuation::NoPunctuation);
}
// YOUR IF I < SIZE -1 LOGIC HERE!
rewriter.create<vector::PrintOp>(loc, vector::PrintPunctuation::Comma);
and then generate the IF at the marked place
https://github.com/llvm/llvm-project/pull/91528
More information about the Mlir-commits
mailing list