[Mlir-commits] [mlir] [mlir] Add concept of alias blocks (PR #65503)

Markus Böck llvmlistbot at llvm.org
Mon Sep 18 10:43:14 PDT 2023


================
@@ -880,3 +882,26 @@ version using readAttribute and readType methods.
 There is no restriction on what kind of information a dialect is allowed to
 encode to model its versioning. Currently, versioning is supported only for
 bytecode formats.
+
+## Alias Block Definitions
+
+An alias block is a list of subsequent attribute or type alias definitions that
+are conceptually parsed as one unit.
+This allows any alias definition within the block to reference any other alias 
+definition within the block, regardless if defined lexically later or earlier in
+the block.
+
+```mlir
+// Alias block consisting of #array, !integer_type and #integer_attr.
+#array = [#integer_attr, !integer_type]
----------------
zero9178 wrote:

Not really. It's essentially a use-before-def. Aliases within a block are allowed to reference other aliases within the block prior to their definition. 
So in this case `#integer_attr` and `!integer_type` are declared afterwards, not prior.

If it were a forward declaration then I'd think it'd look something like:
```mlir
// "forward" declaration
#array = []
!integer_type = i32
#integer_attr = 8 : !integer_type
#array = [#integer_attr, !integer_type]
```
this would in my opinion not be very intuative and for the larger issue I am trying to solve, that is using aliases with cyclic attributes and types, less ergonomic:
```mlir
!type = !llvm.struct<"test">
!body = !llvm.ptr<!type>
!type = !llvm.struct<"test", (!body)>
```
instead of just
```mlir
!type = !llvm.struct<"test", !body>
!body = !llvm.ptr<!type>
```
(llvm dialect only used for illustrative purposes)

This would also require an API/Interface for mutable attributes and types to return a "forward" declaration


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


More information about the Mlir-commits mailing list