Skip to content

Commit 9e8a737

Browse files
authored
[mlir][doc] Fix reported Builtin (syntax) issues (#74635)
Fixes #62489. Some notes for each number: - 1 `bool-literal` should be reasonably clear from context. - 2 Fixed. - 3 This is now fixed. `loc(fused[])` is valid, but `loc(fused["foo",])` is not. - 4 This operation uses `assemblyFormat` so the syntax is correct (assuming ODS is correct). - 5 This operation uses `assemblyFormat` so the syntax is correct (assuming ODS is correct). - 6 Added an example. - 7 The suggested fix is in line with other `assemblyFormat` examples. - 8 Added syntax and an example. - 9 I don't know what this is referring too. - 10 Added example. - 11 and 12 suggestion seems wrong as the `ShapedTypeInterface` could be extended by clients, so is not limited to tensors or vectors. - 13 is already reasonably clear with the example, I think. - 14 is already reasonably clear with the example, I think. - 15 Added an example from the `opaque_locations.mlir` tests. - 16 The answer to this seems to change over time and depend on the use case? Suggestions by reviewers are welcome.
1 parent e4c7ee3 commit 9e8a737

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

mlir/include/mlir/IR/BuiltinAttributes.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,15 @@ def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
454454
Examples:
455455

456456
```mlir
457-
// A tensor referencing a builtin dialect resource, `resource_1`, with two
458-
// unsigned i32 elements.
459-
dense_resource<resource_1> : tensor<2xui32>
457+
"example.user_op"() {attr = dense_resource<blob1> : tensor<3xi64> } : () -> ()
458+
459+
{-#
460+
dialect_resources: {
461+
builtin: {
462+
blob1: "0x08000000010000000000000002000000000000000300000000000000"
463+
}
464+
}
465+
#-}
460466
```
461467
}];
462468
let parameters = (ins

mlir/include/mlir/IR/BuiltinLocationAttributes.td

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def FusedLoc : Builtin_LocationAttr<"FusedLoc"> {
112112
Syntax:
113113

114114
```
115-
fused-location ::= `fused` fusion-metadata? `[` location (location `,`)* `]`
116115
fusion-metadata ::= `<` attribute-value `>`
116+
fused-location ::= `fused` fusion-metadata? `[` (location (`,` location)* )? `]`
117117
```
118118

119119
An instance of a `fused` location represents a grouping of several other
@@ -126,7 +126,7 @@ def FusedLoc : Builtin_LocationAttr<"FusedLoc"> {
126126
Example:
127127

128128
```mlir
129-
loc(fused["mysource.cc":10:8, "mysource.cc":22:8)
129+
loc(fused["mysource.cc":10:8, "mysource.cc":22:8])
130130
loc(fused<"CSE">["mysource.cc":10:8, "mysource.cc":22:8])
131131
```
132132
}];
@@ -159,7 +159,7 @@ def NameLoc : Builtin_LocationAttr<"NameLoc"> {
159159
This can be useful for representing the locations of variable, or node,
160160
definitions.
161161

162-
Example:
162+
#### Example:
163163

164164
```mlir
165165
loc("CSE"("mysource.cc":10:8))
@@ -191,6 +191,13 @@ def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> {
191191
structure that is external to MLIR and an optional location that can be used
192192
if the first one is not suitable. Since it contains an external structure,
193193
only the optional location is used during serialization.
194+
195+
#### Example:
196+
197+
```mlir
198+
%0 = "example.operation"() : () -> i32 loc("mysource")
199+
%1 = arith.constant 4 : index loc(callsite("mysum" at "mysource.cc":10:8))
200+
```
194201
}];
195202
let parameters = (ins "uintptr_t":$underlyingLocation,
196203
"TypeID":$underlyingTypeID,

mlir/include/mlir/IR/BuiltinTypes.td

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def Builtin_Complex : Builtin_Type<"Complex", "complex"> {
4747
element type, which is composed of a real and imaginary value of that
4848
element type. The element must be a floating point or integer scalar type.
4949

50-
Examples:
50+
#### Example:
5151

5252
```mlir
5353
complex<f32>
@@ -251,6 +251,16 @@ def Builtin_Function : Builtin_Type<"Function", "function"> {
251251

252252
The function type can be thought of as a function signature. It consists of
253253
a list of formal parameter types and a list of formal result types.
254+
255+
#### Example:
256+
257+
```mlir
258+
func.func @add_one(%arg0 : i64) -> i64 {
259+
%c1 = arith.constant 1 : i64
260+
%0 = arith.addi %arg0, %c1 : i64
261+
return %0 : i64
262+
}
263+
```
254264
}];
255265
let parameters = (ins "ArrayRef<Type>":$inputs, "ArrayRef<Type>":$results);
256266
let builders = [
@@ -392,10 +402,10 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
392402
Syntax:
393403

394404
```
395-
memref-type ::= `memref` `<` dimension-list-ranked type
396-
(`,` layout-specification)? (`,` memory-space)? `>`
397405
layout-specification ::= attribute-value
398406
memory-space ::= attribute-value
407+
memref-type ::= `memref` `<` dimension-list-ranked type
408+
(`,` layout-specification)? (`,` memory-space)? `>`
399409
```
400410

401411
A `memref` type is a reference to a region of memory (similar to a buffer
@@ -667,8 +677,23 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
667677
def Builtin_None : Builtin_Type<"None", "none"> {
668678
let summary = "A unit type";
669679
let description = [{
680+
Syntax:
681+
682+
```
683+
none-type ::= `none`
684+
```
685+
670686
NoneType is a unit type, i.e. a type with exactly one possible value, where
671687
its value does not have a defined dynamic representation.
688+
689+
#### Example:
690+
691+
```mlir
692+
func.func @none_type() {
693+
%none_val = "foo.unknown_op"() : () -> none
694+
return
695+
}
696+
```
672697
}];
673698
let extraClassDeclaration = [{
674699
static NoneType get(MLIRContext *context);
@@ -692,7 +717,7 @@ def Builtin_Opaque : Builtin_Type<"Opaque", "opaque"> {
692717
represented in their raw string form, and can only usefully be tested for
693718
type equality.
694719

695-
Examples:
720+
#### Example:
696721

697722
```mlir
698723
opaque<"llvm", "struct<(i32, float)>">
@@ -761,7 +786,7 @@ def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
761786
zero sizes are not allowed in some other types, such tensors should be
762787
optimized away before lowering tensors to vectors.
763788

764-
Examples:
789+
#### Example:
765790

766791
```mlir
767792
// Known rank but unknown dimensions.
@@ -846,7 +871,7 @@ def Builtin_Tuple : Builtin_Type<"Tuple", "tuple"> {
846871
provides no standard operations for operating on `tuple` types
847872
([rationale](../../Rationale/Rationale/#tuple-types)).
848873

849-
Examples:
874+
#### Example:
850875

851876
```mlir
852877
// Empty tuple.
@@ -917,7 +942,7 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
917942
See [MemRefType](#memreftype) for more information on
918943
memref types.
919944

920-
Examples:
945+
#### Examples:
921946

922947
```mlir
923948
memref<*f32>
@@ -990,7 +1015,7 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
9901015
unknown rank. See [RankedTensorType](#rankedtensortype)
9911016
for more information on tensor types.
9921017

993-
Examples:
1018+
#### Examples:
9941019

9951020
```mlir
9961021
tensor<*xf32>
@@ -1051,7 +1076,7 @@ def Builtin_Vector : Builtin_Type<"Vector", "vector", [ShapedTypeInterface], "Ty
10511076
declarations, `vector<0x42xi32>` is invalid because it is interpreted as a
10521077
2D vector with shape `(0, 42)` and zero shapes are not allowed.
10531078

1054-
Examples:
1079+
#### Examples:
10551080

10561081
```mlir
10571082
// A 2D fixed-length vector of 3x42 i32 elements.

0 commit comments

Comments
 (0)