[all-commits] [llvm/llvm-project] 5ae19f: [mlir] Allow trailing digit for alias in AsmPrinte...

Hongren Zheng via All-commits all-commits at lists.llvm.org
Thu Mar 6 08:35:22 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5ae19fad3f1a73577cb8446b2b88eea5b3d0c8f0
      https://github.com/llvm/llvm-project/commit/5ae19fad3f1a73577cb8446b2b88eea5b3d0c8f0
  Author: Hongren Zheng <i at zenithal.me>
  Date:   2025-03-07 (Fri, 07 Mar 2025)

  Changed paths:
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/test/IR/print-attr-type-aliases.mlir
    M mlir/test/IR/recursive-type.mlir
    M mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp

  Log Message:
  -----------
  [mlir] Allow trailing digit for alias in AsmPrinter (#127993)

When generating aliases from `OpAsm{Dialect,Type,Attr}Interface`, the
result would be sanitized and if the alias provided by the interface has
a trailing digit, AsmPrinter would attach an underscore to it to
presumably prevent confliction.

#### Motivation

There are two reasons to motivate the change from the old behavior to
the proposed behavior

1. If the type/attribute can generate unique alias from its content,
then the extra trailing underscore added by AsmPrinter will be strange

```mlir
  func.func @add(%ct: !ct_L0_) -> !ct_L0_
    %ct_0 = bgv.add %ct, %ct : (!ct_L0_, !ct_L0_) -> !ct_L0_
    %ct_1 = bgv.add %ct_0, %ct_0 : (!ct_L0_, !ct_L0_) -> !ct_L0_
    %ct_2 = bgv.add %ct_1, %ct_1 : (!ct_L0_, !ct_L0_) -> !ct_L0_
    return %ct_2 : !ct_L0_
  }
```

Which aesthetically would be better if we have `(!ct_L0, !ct_L0) ->
!ct_L0`

2. The Value name behavior is that, for the first instance, use no
suffix `_N`, which can be similarly applied to alias name. See the IR
above where the first one is called `%ct` and others are called `%ct_N`.
See `uniqueValueName` for detail.

#### Conflict detection


```mlir
!test.type<a = 3> // suggest !name0
!test.type<a = 4> // suggest !name0
!test.another<b = 3> // suggest !name0_
!test.another<b = 4> // suggest !name0_
```

The conflict detection is based on `nameCounts` in `initializeAliases`,
where

In the original way, the first two will get sanitized to `!name0_` and
`initializeAlias` can assign unique id `0, 1, 2, 3` to them.

In the current way, the `initializeAlias` uses `usedAliases` to track
which name has been used, and use such information to generate a suffix
id that will make the printed alias name unique.

The result for the above example is `!name0, !name0_1, !name0_,
!name0_2` now.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list