Skip to content

Commit 2b2e860

Browse files
authored
Merge pull request #481 from Xilinx/jrickert.print_newline_skipped_attrs
Do not print unnecessary newlines if attributes are elided
2 parents 91ca2e1 + b3be25a commit 2b2e860

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,8 @@ void AsmPrinter::Impl::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
27912791

27922792
SmallString<16> separator = StringRef(", ");
27932793
if (printerFlags.getNewlineAfterAttrLimit() &&
2794-
attrs.size() > *printerFlags.getNewlineAfterAttrLimit()) {
2794+
std::distance(filteredAttrs.begin(), filteredAttrs.end()) >
2795+
*printerFlags.getNewlineAfterAttrLimit()) {
27952796

27962797
// Increase indent to match the visually match the "{ " below.
27972798
// currentIndent += 2;

mlir/test/IR/mlir-newline-after-attr.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
// CHECK-NEXT: ],
3030
"test.op"() {foo.dense_attr = dense<1> : tensor<3xi32>, foo.second_attr = dense<2> : tensor<3xi32>, Operands = [{foo.vect_attr_1_start = dense<0> : vector<3xindex>, foo.vect_attr_1_end = dense<0> : vector<3xindex>, foo.vect_attr_1_count = dense<1> : vector<3xindex>, foo.vect_attr_2_start = dense<0> : vector<3xindex>, foo.vect_attr_2_end = dense<0> : vector<3xindex>, foo.vect_attr_2_count = dense<1> : vector<3xindex>}, {foo.vect_attr_1_start = dense<0> : vector<3xindex>, foo.vect_attr_1_end = dense<0> : vector<3xindex>, foo.vect_attr_1_count = dense<1> : vector<3xindex>, foo.vect_attr_2_start = dense<0> : vector<3xindex>, foo.vect_attr_2_end = dense<0> : vector<3xindex>, foo.vect_attr_2_count = dense<1> : vector<3xindex>}]} : () -> ()
3131

32+
// const_shape skips over shape attr when printing. Check that we do not insert unnecessary newlines
33+
// CHECK{LITERAL}: shape.const_shape {foo.second_attr = dense<2> : tensor<3xi32>, foo.third_attr = dense<2> : tensor<3xi32>}[1, 1, 1] : tensor<3xindex>
34+
"shape.const_shape"() {shape = dense<1> : tensor<3xindex>, foo.second_attr = dense<2> : tensor<3xi32>, foo.third_attr = dense<2> : tensor<3xi32>} : () -> (tensor<3xindex>)

0 commit comments

Comments
 (0)