mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 05:56:05 +00:00

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.