@@ -87,32 +87,78 @@ class CIR_Op<string mnemonic, list<Trait> traits = []> :
87
87
//===----------------------------------------------------------------------===//
88
88
89
89
def CIR_CastKind : CIR_I32EnumAttr<"CastKind", "cast kind", [
90
- // The enumaration value isn't in sync with clang.
91
- I32EnumAttrCase<"int_to_bool", 0>,
92
- I32EnumAttrCase<"array_to_ptrdecay", 1>,
93
- I32EnumAttrCase<"integral", 2>,
94
- I32EnumAttrCase<"bitcast", 3>,
95
- I32EnumAttrCase<"floating", 4>,
96
- I32EnumAttrCase<"ptr_to_bool", 5>,
97
- I32EnumAttrCase<"float_to_int", 6>,
98
- I32EnumAttrCase<"int_to_ptr", 7>,
99
- I32EnumAttrCase<"ptr_to_int", 8>,
100
- I32EnumAttrCase<"float_to_bool", 9>,
101
- I32EnumAttrCase<"bool_to_int", 10>,
102
- I32EnumAttrCase<"int_to_float", 11>,
103
- I32EnumAttrCase<"bool_to_float", 12>,
104
- I32EnumAttrCase<"address_space", 13>,
105
- I32EnumAttrCase<"float_to_complex", 14>,
106
- I32EnumAttrCase<"int_to_complex", 15>,
107
- I32EnumAttrCase<"float_complex_to_real", 16>,
108
- I32EnumAttrCase<"int_complex_to_real", 17>,
109
- I32EnumAttrCase<"float_complex_to_bool", 18>,
110
- I32EnumAttrCase<"int_complex_to_bool", 19>,
111
- I32EnumAttrCase<"float_complex", 20>,
112
- I32EnumAttrCase<"float_complex_to_int_complex", 21>,
113
- I32EnumAttrCase<"int_complex", 22>,
114
- I32EnumAttrCase<"int_complex_to_float_complex", 23>,
115
- I32EnumAttrCase<"member_ptr_to_bool", 24>
90
+ I32EnumAttrCase<"bitcast", 1>,
91
+ // CK_LValueBitCast
92
+ // CK_LValueToRValueBitCast
93
+ // CK_LValueToRValue
94
+ // CK_NoOp
95
+ // CK_BaseToDerived
96
+ // CK_DerivedToBase
97
+ // CK_UncheckedDerivedToBase
98
+ // CK_Dynamic
99
+ // CK_ToUnion
100
+ I32EnumAttrCase<"array_to_ptrdecay", 11>,
101
+ // CK_FunctionToPointerDecay
102
+ // CK_NullToPointer
103
+ // CK_NullToMemberPointer
104
+ // CK_BaseToDerivedMemberPointer
105
+ // CK_DerivedToBaseMemberPointer
106
+ I32EnumAttrCase<"member_ptr_to_bool", 17>,
107
+ // CK_ReinterpretMemberPointer
108
+ // CK_UserDefinedConversion
109
+ // CK_ConstructorConversion
110
+ I32EnumAttrCase<"int_to_ptr", 21>,
111
+ I32EnumAttrCase<"ptr_to_int", 22>,
112
+ I32EnumAttrCase<"ptr_to_bool", 23>,
113
+ // CK_ToVoid
114
+ // CK_MatrixCast
115
+ // CK_VectorSplat
116
+ I32EnumAttrCase<"integral", 27>,
117
+ I32EnumAttrCase<"int_to_bool", 28>,
118
+ I32EnumAttrCase<"int_to_float", 29>,
119
+ // CK_FloatingToFixedPoint
120
+ // CK_FixedPointToFloating
121
+ // CK_FixedPointCast
122
+ // CK_FixedPointToIntegral
123
+ // CK_IntegralToFixedPoint
124
+ // CK_FixedPointToBoolean
125
+ I32EnumAttrCase<"float_to_int", 36>,
126
+ I32EnumAttrCase<"float_to_bool", 37>,
127
+ I32EnumAttrCase<"bool_to_int", 38>,
128
+ I32EnumAttrCase<"floating", 39>,
129
+ // CK_CPointerToObjCPointerCast
130
+ // CK_BlockPointerToObjCPointerCast
131
+ // CK_AnyPointerToBlockPointerCast
132
+ // CK_ObjCObjectLValueCast
133
+ I32EnumAttrCase<"float_to_complex", 44>,
134
+ I32EnumAttrCase<"float_complex_to_real", 45>,
135
+ I32EnumAttrCase<"float_complex_to_bool", 46>,
136
+ I32EnumAttrCase<"float_complex", 47>,
137
+ I32EnumAttrCase<"float_complex_to_int_complex", 48>,
138
+ I32EnumAttrCase<"int_to_complex", 49>,
139
+ I32EnumAttrCase<"int_complex_to_real", 50>,
140
+ I32EnumAttrCase<"int_complex_to_bool", 51>,
141
+ I32EnumAttrCase<"int_complex", 52>,
142
+ I32EnumAttrCase<"int_complex_to_float_complex", 53>,
143
+ // CK_ARCProduceObject
144
+ // CK_ARCConsumeObject
145
+ // CK_ARCReclaimReturnedObject
146
+ // CK_ARCExtendBlockObject
147
+ // CK_AtomicToNonAtomic
148
+ // CK_NonAtomicToAtomic
149
+ // CK_CopyAndAutoreleaseBlockObject
150
+ // CK_BuiltinFnToFnPtr
151
+ // CK_ZeroToOCLOpaqueType
152
+ I32EnumAttrCase<"address_space", 63>,
153
+ // CK_IntToOCLSampler
154
+ // CK_HLSLVectorTruncation
155
+ // CK_HLSLArrayRValue
156
+ // CK_HLSLElementwiseCast
157
+ // CK_HLSLAggregateSplatCast
158
+
159
+ // Enums below are specific to CIR and don't have a correspondence to classic
160
+ // codegen:
161
+ I32EnumAttrCase<"bool_to_float", 1000>,
116
162
]>;
117
163
118
164
def CastOp : CIR_Op<"cast",
@@ -121,39 +167,48 @@ def CastOp : CIR_Op<"cast",
121
167
// FIXME: not all conversions are free of side effects.
122
168
let summary = "Conversion between values of different types";
123
169
let description = [{
124
- Apply C/C++ usual conversions rules between values. Currently supported kinds:
170
+ Apply the usual C/C++ conversion rules between values. This operation models
171
+ a subset of conversions as defined in Clang's `OperationKinds.def`
172
+ (`llvm-project/clang/include/clang/AST/OperationKinds.def`).
173
+
174
+ Note: not all conversions are implemented using `cir.cast`. For instance,
175
+ lvalue-to-rvalue conversion is modeled as a `cir.load` instead. Currently
176
+ supported kinds:
125
177
126
- - `array_to_ptrdecay`
127
178
- `bitcast`
179
+ - `array_to_ptrdecay`
180
+ - `member_ptr_to_bool
181
+ - `int_to_ptr`
182
+ - `ptr_to_int`
183
+ - `ptr_to_bool`
128
184
- `integral`
129
185
- `int_to_bool`
130
186
- `int_to_float`
131
- - `floating`
132
187
- `float_to_int`
133
188
- `float_to_bool`
134
- - `ptr_to_int`
135
- - `ptr_to_bool`
136
189
- `bool_to_int`
137
- - `bool_to_float`
138
- - `address_space`
190
+ - `floating`
139
191
- `float_to_complex`
140
- - `int_to_complex`
141
192
- `float_complex_to_real`
142
- - `int_complex_to_real`
143
193
- `float_complex_to_bool`
144
- - `int_complex_to_bool`
145
194
- `float_complex`
146
195
- `float_complex_to_int_complex`
196
+ - `int_to_complex`
197
+ - `int_complex_to_real`
198
+ - `int_complex_to_bool`
147
199
- `int_complex`
148
200
- `int_complex_to_float_complex`
201
+ - `address_space`
202
+
203
+ CIR also supports some additional conversions that are not part of the classic
204
+ Clang codegen:
205
+
206
+ - `bool_to_float`
149
207
150
- This is effectively a subset of the rules from
151
- `llvm-project/clang/include/clang/AST/OperationKinds.def`; but note that some
152
- of the conversions aren't implemented in terms of `cir.cast`, `lvalue-to-rvalue`
153
- for instance is modeled as a regular `cir.load`.
208
+ Example:
154
209
155
210
```mlir
156
- %4 = cir.cast (int_to_bool, %3 : i32), !cir.bool
211
+ %4 = cir.cast(int_to_bool, %3 : i32), !cir.bool
157
212
...
158
213
%x = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<i32 x 10>>), !cir.ptr<i32>
159
214
```
@@ -1846,10 +1901,10 @@ def CmpThreeWayOp : CIR_Op<"cmp3way", [Pure, SameTypeOperands]> {
1846
1901
//===----------------------------------------------------------------------===//
1847
1902
1848
1903
def CIR_CaseOpKind : CIR_I32EnumAttr<"CaseOpKind", "case kind", [
1849
- I32EnumAttrCase<"Default", 1 , "default">,
1850
- I32EnumAttrCase<"Equal", 2 , "equal">,
1851
- I32EnumAttrCase<"Anyof", 3 , "anyof">,
1852
- I32EnumAttrCase<"Range", 4 , "range">
1904
+ I32EnumAttrCase<"Default", 0 , "default">,
1905
+ I32EnumAttrCase<"Equal", 1 , "equal">,
1906
+ I32EnumAttrCase<"Anyof", 2 , "anyof">,
1907
+ I32EnumAttrCase<"Range", 3 , "range">
1853
1908
]>;
1854
1909
1855
1910
def CaseOp : CIR_Op<"case", [
@@ -3107,6 +3162,7 @@ def VecCreateOp : CIR_Op<"vec.create", [Pure]> {
3107
3162
}];
3108
3163
3109
3164
let hasVerifier = 1;
3165
+ let hasFolder = 1;
3110
3166
}
3111
3167
3112
3168
//===----------------------------------------------------------------------===//
@@ -3169,7 +3225,7 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, SameTypeOperands]> {
3169
3225
//===----------------------------------------------------------------------===//
3170
3226
3171
3227
def VecTernaryOp : CIR_Op<"vec.ternary",
3172
- [Pure, AllTypesMatch<["result", "vec1 ", "vec2 "]>]> {
3228
+ [Pure, AllTypesMatch<["result", "lhs ", "rhs "]>]> {
3173
3229
let summary = "The `cond ? a : b` ternary operator for vector types";
3174
3230
let description = [{
3175
3231
The `cir.vec.ternary` operation represents the C/C++ ternary operator,
@@ -3188,16 +3244,18 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
3188
3244
3189
3245
let arguments = (ins
3190
3246
CIR_VectorOfIntType:$cond,
3191
- CIR_VectorType:$vec1 ,
3192
- CIR_VectorType:$vec2
3247
+ CIR_VectorType:$lhs ,
3248
+ CIR_VectorType:$rhs
3193
3249
);
3194
3250
3195
3251
let results = (outs CIR_VectorType:$result);
3196
3252
let assemblyFormat = [{
3197
- `(` $cond `,` $vec1 `,` $vec2 `)` `:` qualified(type($cond)) `,`
3198
- qualified(type($vec1 )) attr-dict
3253
+ `(` $cond `,` $lhs `,` $rhs `)` `:` qualified(type($cond)) `,`
3254
+ qualified(type($lhs )) attr-dict
3199
3255
}];
3256
+
3200
3257
let hasVerifier = 1;
3258
+ let hasFolder = 1;
3201
3259
}
3202
3260
3203
3261
//===----------------------------------------------------------------------===//
@@ -3595,7 +3653,9 @@ def FuncOp : CIR_Op<"func", [
3595
3653
OptionalAttr<GlobalCtorAttr>:$global_ctor,
3596
3654
OptionalAttr<GlobalDtorAttr>:$global_dtor,
3597
3655
OptionalAttr<ArrayAttr>:$annotations,
3598
- OptionalAttr<AnyASTFunctionDeclAttr>:$ast
3656
+ OptionalAttr<AnyASTFunctionDeclAttr>:$ast,
3657
+ OptionalAttr<CXXCtorAttr>:$cxx_ctor,
3658
+ OptionalAttr<CXXDtorAttr>:$cxx_dtor
3599
3659
);
3600
3660
3601
3661
let regions = (region AnyRegion:$body);
@@ -3765,11 +3825,11 @@ def DeleteArrayOp : CIR_Op<"delete.array">,
3765
3825
//===----------------------------------------------------------------------===//
3766
3826
3767
3827
def CIR_SideEffect : CIR_I32EnumAttr<
3768
- "SideEffect", "allowed side effects of a function",[
3769
- I32EnumAttrCase<"All", 1 , "all">,
3770
- I32EnumAttrCase<"Pure", 2 , "pure">,
3771
- I32EnumAttrCase<"Const", 3 , "const">
3772
- ]> {
3828
+ "SideEffect", "allowed side effects of a function", [
3829
+ I32EnumAttrCase<"All", 0 , "all">,
3830
+ I32EnumAttrCase<"Pure", 1 , "pure">,
3831
+ I32EnumAttrCase<"Const", 2 , "const">
3832
+ ]> {
3773
3833
let description = [{
3774
3834
The side effect attribute specifies the possible side effects of the callee
3775
3835
of a call operation. This is an enumeration attribute and all possible
0 commit comments