@@ -867,14 +867,48 @@ Syntax:
867
867
``` {.ebnf}
868
868
attribute-dict ::= `{` `}`
869
869
| `{` attribute-entry (`,` attribute-entry)* `}`
870
- attribute-entry ::= `:`? bare-id `:` attribute-value
870
+ attribute-entry ::= dialect-attribute-entry | dependent-attribute-entry
871
+ dialect-attribute-entry ::= dialect-namespace `.` bare-id `:` attribute-value
872
+ dependent-attribute-entry ::= dependent-attribute-name `:` attribute-value
873
+ dependent-attribute-name ::= (letter|[_]) (letter|digit|[_$])*
871
874
```
872
875
873
876
Attributes are the mechanism for specifying constant data in MLIR in places
874
877
where a variable is never allowed - e.g. the index of a
875
- [ ` dim ` operation] ( #'dim'-operation ) , or the stride of a convolution.
878
+ [ ` dim ` operation] ( #'dim'-operation ) , or the stride of a convolution. They
879
+ consist of a name and a [ concrete attribute value] ( #attribute-values ) . It is
880
+ possible to attach attributes to operations, functions, and function arguments.
881
+ The set of expected attributes, their structure, and their interpretation are
882
+ all contextually dependent on what they are attached to.
876
883
877
- Attributes have a name, and their values are represented by the following forms:
884
+ There are two main classes of attributes; dependent and dialect. Dependent
885
+ attributes derive their structure and meaning from what they are attached to,
886
+ e.g the meaning of the ` index ` attribute on a ` dim ` operation is defined by the
887
+ ` dim ` operation. Dialect attributes, on the other hand, derive their context and
888
+ meaning from a specific dialect. An example of a dialect attribute may be a
889
+ ` swift.self ` function argument attribute that indicates an argument is the
890
+ self/context parameter. The context of this attribute is defined by the ` swift `
891
+ dialect and not the function argument.
892
+
893
+ ### Function and Argument Attributes
894
+
895
+ Functions and function arguments in MLIR may have optional attributes attached
896
+ to them. The sole constraint for these attributes is that they must be dialect
897
+ specific attributes. This is because functions, and function arguments, are a
898
+ generic entities and thus cannot apply any meaningful context necessary for
899
+ dependent attributes. This has the added benefit of avoiding collisions between
900
+ common attribute names, such as ` noalias ` .
901
+
902
+ ### Operation Attributes
903
+
904
+ Operations, unlike functions and function arguments, may include both dialect
905
+ specific and dependent attributes. This is because an operation represents a
906
+ distinct semantic context, and can thus provide a single source of meaning to
907
+ dependent attributes.
908
+
909
+ ### Attribute Values {#attribute-values}
910
+
911
+ Attributes values are represented by the following forms:
878
912
879
913
``` {.ebnf}
880
914
attribute-value ::= affine-map-attribute
@@ -889,11 +923,7 @@ attribute-value ::= affine-map-attribute
889
923
| type-attribute
890
924
```
891
925
892
- It is possible to attach attributes to instructions and functions, and the set
893
- of expected attributes, their structure, and the definition of that meaning is
894
- contextually dependent on the operation they are attached to.
895
-
896
- ### AffineMap Attribute {#affine-map-attribute}
926
+ #### AffineMap Attribute {#affine-map-attribute}
897
927
898
928
Syntax:
899
929
@@ -903,7 +933,7 @@ affine-map-attribute ::= affine-map
903
933
904
934
An affine-map attribute is an attribute that represents a affine-map object.
905
935
906
- ### Array Attribute {#array-attribute}
936
+ #### Array Attribute {#array-attribute}
907
937
908
938
Syntax:
909
939
@@ -914,7 +944,7 @@ array-attribute ::= `[` (attribute-value (`,` attribute-value)*)? `]`
914
944
An array attribute is an attribute that represents a collection of attribute
915
945
values.
916
946
917
- ### Boolean Attribute {#bool-attribute}
947
+ #### Boolean Attribute {#bool-attribute}
918
948
919
949
Syntax:
920
950
@@ -925,7 +955,7 @@ bool-attribute ::= bool-literal
925
955
A boolean attribute is a literal attribute that represents a one-bit boolean
926
956
value, true or false.
927
957
928
- ### Elements Attributes {#elements-attributes}
958
+ #### Elements Attributes {#elements-attributes}
929
959
930
960
Syntax:
931
961
@@ -939,7 +969,7 @@ elements-attribute ::= dense-elements-attribute
939
969
An elements attribute is a literal attribute that represents a constant
940
970
[ vector] ( #vector-type ) or [ tensor] ( #tensor-type ) value.
941
971
942
- #### Dense Elements Attribute {#dense-elements-attribute}
972
+ ##### Dense Elements Attribute {#dense-elements-attribute}
943
973
944
974
Syntax:
945
975
@@ -953,7 +983,7 @@ constant vector or tensor value has been packed to the element bitwidth. The
953
983
element type of the vector or tensor constant must be of integer, index, or
954
984
floating point type.
955
985
956
- #### Opaque Elements Attribute {#opaque-elements-attribute}
986
+ ##### Opaque Elements Attribute {#opaque-elements-attribute}
957
987
958
988
Syntax:
959
989
970
1000
971
1001
Note: The parsed string literal must be in hexadecimal form.
972
1002
973
- #### Sparse Elements Attribute {#sparse-elements-attribute}
1003
+ ##### Sparse Elements Attribute {#sparse-elements-attribute}
974
1004
975
1005
Syntax:
976
1006
@@ -1000,7 +1030,7 @@ Example:
1000
1030
/// [0, 0, 0, 0]]
1001
1031
```
1002
1032
1003
- #### Splat Elements Attribute {#splat-elements-attribute}
1033
+ ##### Splat Elements Attribute {#splat-elements-attribute}
1004
1034
1005
1035
Syntax:
1006
1036
@@ -1012,7 +1042,7 @@ splat-elements-attribute ::= `splat` `<` ( tensor-type | vector-type ) `,`
1012
1042
A splat elements attribute is an elements attribute that represents a tensor or
1013
1043
vector constant where all elements have the same value.
1014
1044
1015
- ### Integer Attribute {#integer-attribute}
1045
+ #### Integer Attribute {#integer-attribute}
1016
1046
1017
1047
Syntax:
1018
1048
@@ -1024,7 +1054,7 @@ An integer attribute is a literal attribute that represents an integral value of
1024
1054
the specified integer or index type. The default type for this attribute, if one
1025
1055
is not specified, is a 64-bit integer.
1026
1056
1027
- ### Integer Set Attribute {#integer-set-attribute}
1057
+ #### Integer Set Attribute {#integer-set-attribute}
1028
1058
1029
1059
Syntax:
1030
1060
@@ -1034,7 +1064,7 @@ integer-set-attribute ::= affine-map
1034
1064
1035
1065
An integer-set attribute is an attribute that represents a integer-set object.
1036
1066
1037
- ### Float Attribute {#float-attribute}
1067
+ #### Float Attribute {#float-attribute}
1038
1068
1039
1069
Syntax:
1040
1070
@@ -1045,7 +1075,7 @@ float-attribute ::= float-literal (`:` float-type)?
1045
1075
A float attribute is a literal attribute that represents a floating point value
1046
1076
of the specified [ float type] ( #floating-point-types ) .
1047
1077
1048
- ### Function Attribute {#function-attribute}
1078
+ #### Function Attribute {#function-attribute}
1049
1079
1050
1080
Syntax:
1051
1081
@@ -1056,7 +1086,7 @@ function-attribute ::= function-id `:` function-type
1056
1086
A function attribute is a literal attribute that represents a reference to the
1057
1087
given function object.
1058
1088
1059
- ### String Attribute {#string-attribute}
1089
+ #### String Attribute {#string-attribute}
1060
1090
1061
1091
Syntax:
1062
1092
@@ -1066,7 +1096,7 @@ string-attribute ::= string-literal
1066
1096
1067
1097
A string attribute is an attribute that represents a string literal value.
1068
1098
1069
- ### Type Attribute {#type-attribute}
1099
+ #### Type Attribute {#type-attribute}
1070
1100
1071
1101
Syntax:
1072
1102
0 commit comments