@@ -47,11 +47,14 @@ class EmitC_BinaryOp<string mnemonic, list<Trait> traits = []> :
47
47
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
48
48
}
49
49
50
+ // EmitC OpTrait
51
+ def CExpression : NativeOpTrait<"emitc::CExpression">;
52
+
50
53
// Types only used in binary arithmetic operations.
51
54
def IntegerIndexOrOpaqueType : AnyTypeOf<[AnyInteger, Index, EmitC_OpaqueType]>;
52
55
def FloatIntegerIndexOrOpaqueType : AnyTypeOf<[AnyFloat, IntegerIndexOrOpaqueType]>;
53
56
54
- def EmitC_AddOp : EmitC_BinaryOp<"add", []> {
57
+ def EmitC_AddOp : EmitC_BinaryOp<"add", [CExpression ]> {
55
58
let summary = "Addition operation";
56
59
let description = [{
57
60
With the `add` operation the arithmetic operator + (addition) can
@@ -74,7 +77,7 @@ def EmitC_AddOp : EmitC_BinaryOp<"add", []> {
74
77
let hasVerifier = 1;
75
78
}
76
79
77
- def EmitC_ApplyOp : EmitC_Op<"apply", []> {
80
+ def EmitC_ApplyOp : EmitC_Op<"apply", [CExpression ]> {
78
81
let summary = "Apply operation";
79
82
let description = [{
80
83
With the `apply` operation the operators & (address of) and * (contents of)
@@ -103,7 +106,7 @@ def EmitC_ApplyOp : EmitC_Op<"apply", []> {
103
106
let hasVerifier = 1;
104
107
}
105
108
106
- def EmitC_BitwiseAndOp : EmitC_BinaryOp<"bitwise_and", []> {
109
+ def EmitC_BitwiseAndOp : EmitC_BinaryOp<"bitwise_and", [CExpression ]> {
107
110
let summary = "Bitwise and operation";
108
111
let description = [{
109
112
With the `bitwise_and` operation the bitwise operator & (and) can
@@ -121,7 +124,8 @@ def EmitC_BitwiseAndOp : EmitC_BinaryOp<"bitwise_and", []> {
121
124
}];
122
125
}
123
126
124
- def EmitC_BitwiseLeftShiftOp : EmitC_BinaryOp<"bitwise_left_shift", []> {
127
+ def EmitC_BitwiseLeftShiftOp : EmitC_BinaryOp<"bitwise_left_shift",
128
+ [CExpression]> {
125
129
let summary = "Bitwise left shift operation";
126
130
let description = [{
127
131
With the `bitwise_left_shift` operation the bitwise operator <<
@@ -139,7 +143,7 @@ def EmitC_BitwiseLeftShiftOp : EmitC_BinaryOp<"bitwise_left_shift", []> {
139
143
}];
140
144
}
141
145
142
- def EmitC_BitwiseNotOp : EmitC_UnaryOp<"bitwise_not", []> {
146
+ def EmitC_BitwiseNotOp : EmitC_UnaryOp<"bitwise_not", [CExpression ]> {
143
147
let summary = "Bitwise not operation";
144
148
let description = [{
145
149
With the `bitwise_not` operation the bitwise operator ~ (not) can
@@ -157,7 +161,7 @@ def EmitC_BitwiseNotOp : EmitC_UnaryOp<"bitwise_not", []> {
157
161
}];
158
162
}
159
163
160
- def EmitC_BitwiseOrOp : EmitC_BinaryOp<"bitwise_or", []> {
164
+ def EmitC_BitwiseOrOp : EmitC_BinaryOp<"bitwise_or", [CExpression ]> {
161
165
let summary = "Bitwise or operation";
162
166
let description = [{
163
167
With the `bitwise_or` operation the bitwise operator | (or)
@@ -175,7 +179,8 @@ def EmitC_BitwiseOrOp : EmitC_BinaryOp<"bitwise_or", []> {
175
179
}];
176
180
}
177
181
178
- def EmitC_BitwiseRightShiftOp : EmitC_BinaryOp<"bitwise_right_shift", []> {
182
+ def EmitC_BitwiseRightShiftOp : EmitC_BinaryOp<"bitwise_right_shift",
183
+ [CExpression]> {
179
184
let summary = "Bitwise right shift operation";
180
185
let description = [{
181
186
With the `bitwise_right_shift` operation the bitwise operator >>
@@ -193,7 +198,7 @@ def EmitC_BitwiseRightShiftOp : EmitC_BinaryOp<"bitwise_right_shift", []> {
193
198
}];
194
199
}
195
200
196
- def EmitC_BitwiseXorOp : EmitC_BinaryOp<"bitwise_xor", []> {
201
+ def EmitC_BitwiseXorOp : EmitC_BinaryOp<"bitwise_xor", [CExpression ]> {
197
202
let summary = "Bitwise xor operation";
198
203
let description = [{
199
204
With the `bitwise_xor` operation the bitwise operator ^ (xor)
@@ -211,7 +216,7 @@ def EmitC_BitwiseXorOp : EmitC_BinaryOp<"bitwise_xor", []> {
211
216
}];
212
217
}
213
218
214
- def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", []> {
219
+ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", [CExpression ]> {
215
220
let summary = "Opaque call operation";
216
221
let description = [{
217
222
The `call_opaque` operation represents a C++ function call. The callee
@@ -257,10 +262,10 @@ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", []> {
257
262
let hasVerifier = 1;
258
263
}
259
264
260
- def EmitC_CastOp : EmitC_Op<"cast", [
261
- DeclareOpInterfaceMethods<CastOpInterface> ,
262
- SameOperandsAndResultShape
263
- ]> {
265
+ def EmitC_CastOp : EmitC_Op<"cast",
266
+ [CExpression ,
267
+ DeclareOpInterfaceMethods<CastOpInterface>,
268
+ SameOperandsAndResultShape ]> {
264
269
let summary = "Cast operation";
265
270
let description = [{
266
271
The `cast` operation performs an explicit type conversion and is emitted
@@ -284,7 +289,7 @@ def EmitC_CastOp : EmitC_Op<"cast", [
284
289
let assemblyFormat = "$source attr-dict `:` type($source) `to` type($dest)";
285
290
}
286
291
287
- def EmitC_CmpOp : EmitC_BinaryOp<"cmp", []> {
292
+ def EmitC_CmpOp : EmitC_BinaryOp<"cmp", [CExpression ]> {
288
293
let summary = "Comparison operation";
289
294
let description = [{
290
295
With the `cmp` operation the comparison operators ==, !=, <, <=, >, >=, <=>
@@ -355,7 +360,7 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
355
360
let hasVerifier = 1;
356
361
}
357
362
358
- def EmitC_DivOp : EmitC_BinaryOp<"div", []> {
363
+ def EmitC_DivOp : EmitC_BinaryOp<"div", [CExpression ]> {
359
364
let summary = "Division operation";
360
365
let description = [{
361
366
With the `div` operation the arithmetic operator / (division) can
@@ -409,9 +414,8 @@ def EmitC_ExpressionOp : EmitC_Op<"expression",
409
414
int32_t v7 = foo(v1 + v2) * (v3 + v4);
410
415
```
411
416
412
- The operations allowed within expression body are `emitc.add`,
413
- `emitc.apply`, `emitc.call_opaque`, `emitc.cast`, `emitc.cmp`, `emitc.div`,
414
- `emitc.mul`, `emitc.rem`, and `emitc.sub`.
417
+ The operations allowed within expression body are EmitC operations with the
418
+ CExpression trait.
415
419
416
420
When specified, the optional `do_not_inline` indicates that the expression is
417
421
to be emitted as seen above, i.e. as the rhs of an EmitC SSA value
@@ -427,14 +431,9 @@ def EmitC_ExpressionOp : EmitC_Op<"expression",
427
431
let assemblyFormat = "attr-dict (`noinline` $do_not_inline^)? `:` type($result) $region";
428
432
429
433
let extraClassDeclaration = [{
430
- static bool isCExpression(Operation &op) {
431
- return isa<emitc::AddOp, emitc::ApplyOp, emitc::CallOpaqueOp,
432
- emitc::CastOp, emitc::CmpOp, emitc::DivOp, emitc::MulOp,
433
- emitc::RemOp, emitc::SubOp>(op);
434
- }
435
434
bool hasSideEffects() {
436
435
auto predicate = [](Operation &op) {
437
- assert(isCExpression(op ) && "Expected a C expression");
436
+ assert(op.hasTrait<OpTrait::emitc::CExpression>( ) && "Expected a C expression");
438
437
// Conservatively assume calls to read and write memory.
439
438
if (isa<emitc::CallOpaqueOp>(op))
440
439
return true;
@@ -518,7 +517,7 @@ def EmitC_ForOp : EmitC_Op<"for",
518
517
}
519
518
520
519
def EmitC_CallOp : EmitC_Op<"call",
521
- [CallOpInterface,
520
+ [CallOpInterface, CExpression,
522
521
DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
523
522
let summary = "call operation";
524
523
let description = [{
@@ -774,7 +773,7 @@ def EmitC_LiteralOp : EmitC_Op<"literal", [Pure]> {
774
773
let assemblyFormat = "$value attr-dict `:` type($result)";
775
774
}
776
775
777
- def EmitC_LogicalAndOp : EmitC_BinaryOp<"logical_and", []> {
776
+ def EmitC_LogicalAndOp : EmitC_BinaryOp<"logical_and", [CExpression ]> {
778
777
let summary = "Logical and operation";
779
778
let description = [{
780
779
With the `logical_and` operation the logical operator && (and) can
@@ -795,7 +794,7 @@ def EmitC_LogicalAndOp : EmitC_BinaryOp<"logical_and", []> {
795
794
let assemblyFormat = "operands attr-dict `:` type(operands)";
796
795
}
797
796
798
- def EmitC_LogicalNotOp : EmitC_UnaryOp<"logical_not", []> {
797
+ def EmitC_LogicalNotOp : EmitC_UnaryOp<"logical_not", [CExpression ]> {
799
798
let summary = "Logical not operation";
800
799
let description = [{
801
800
With the `logical_not` operation the logical operator ! (negation) can
@@ -816,7 +815,7 @@ def EmitC_LogicalNotOp : EmitC_UnaryOp<"logical_not", []> {
816
815
let assemblyFormat = "operands attr-dict `:` type(operands)";
817
816
}
818
817
819
- def EmitC_LogicalOrOp : EmitC_BinaryOp<"logical_or", []> {
818
+ def EmitC_LogicalOrOp : EmitC_BinaryOp<"logical_or", [CExpression ]> {
820
819
let summary = "Logical or operation";
821
820
let description = [{
822
821
With the `logical_or` operation the logical operator || (inclusive or)
@@ -837,7 +836,7 @@ def EmitC_LogicalOrOp : EmitC_BinaryOp<"logical_or", []> {
837
836
let assemblyFormat = "operands attr-dict `:` type(operands)";
838
837
}
839
838
840
- def EmitC_MulOp : EmitC_BinaryOp<"mul", []> {
839
+ def EmitC_MulOp : EmitC_BinaryOp<"mul", [CExpression ]> {
841
840
let summary = "Multiplication operation";
842
841
let description = [{
843
842
With the `mul` operation the arithmetic operator * (multiplication) can
@@ -861,7 +860,7 @@ def EmitC_MulOp : EmitC_BinaryOp<"mul", []> {
861
860
let results = (outs FloatIntegerIndexOrOpaqueType);
862
861
}
863
862
864
- def EmitC_RemOp : EmitC_BinaryOp<"rem", []> {
863
+ def EmitC_RemOp : EmitC_BinaryOp<"rem", [CExpression ]> {
865
864
let summary = "Remainder operation";
866
865
let description = [{
867
866
With the `rem` operation the arithmetic operator % (remainder) can
@@ -883,7 +882,7 @@ def EmitC_RemOp : EmitC_BinaryOp<"rem", []> {
883
882
let results = (outs IntegerIndexOrOpaqueType);
884
883
}
885
884
886
- def EmitC_SubOp : EmitC_BinaryOp<"sub", []> {
885
+ def EmitC_SubOp : EmitC_BinaryOp<"sub", [CExpression ]> {
887
886
let summary = "Subtraction operation";
888
887
let description = [{
889
888
With the `sub` operation the arithmetic operator - (subtraction) can
0 commit comments