[Mlir-commits] [mlir] Enable printing newlines and indents in attribute and type printers (PR #87948)

Jacenty Andruszkiewicz llvmlistbot at llvm.org
Thu Apr 18 07:04:32 PDT 2024


Jacenty-And-Intel wrote:

Introducing new lines by types or attributes could be used in justified cases in custom printers where it would improve the readability of the IR. In some cases where there are multiple levels of nesting and lists of attributes, it could be difficult to get useful information while debugging. The indent in nested printers is tracked and would be preserved when the new line is added.

Example without formatting: 
```
#Dialect.Attribute<!Dialect.Type<name(...) nestedAttributes([#Dialect.FirstNestedAttribute<!Dialect.FirstNestedType<name(...) nestedAttributes([#Dialect.SecondNestedAttribute<!Dialect.SecondNestedType<name(...) value1(...) value2(...)>>,#Dialect.SecondNestedAttribute<!Dialect.SecondNestedType<name(...) value1(...) value2(...)>>])>>,#Dialect.FirstNestedAttribute<!Dialect.FirstNestedType<name(...) nestedAttributes([#Dialect.SecondNestedAttribute<!Dialect.SecondNestedType<name(...) value1(...) value2(...)>>])>>])>>
```

Same example with formatting:
```
#Dialect.Attribute<
  !Dialect.Type<
    name(...) nestedAttributes([
      #Dialect.FirstNestedAttribute<
        !Dialect.FirstNestedType<
          name(...) nestedAttributes([
            #Dialect.SecondNestedAttribute<
              !Dialect.SecondNestedType<
                name(...) value1(...) value2(...)
              >
            >,
            #Dialect.SecondNestedAttribute<
              !Dialect.SecondNestedType<
                name(...) value1(...) value2(...)
              >
            >
          ])
        >
      >,
      #Dialect.FirstNestedAttribute<
        !Dialect.FirstNestedType<
          name(...) nestedAttributes([
            #Dialect.SecondNestedAttribute<
              !Dialect.SecondNestedType<
                name(...) value1(...) value2(...)
              >
            >
          ])
        >
      >  
    ])
  >
>
```

https://github.com/llvm/llvm-project/pull/87948


More information about the Mlir-commits mailing list