@@ -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)
@@ -211,7 +214,7 @@ def EmitC_BitwiseXorOp : EmitC_BinaryOp<"bitwise_xor", []> {
211
214
}];
212
215
}
213
216
214
- def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", []> {
217
+ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", [CExpression ]> {
215
218
let summary = "Opaque call operation";
216
219
let description = [{
217
220
The `call_opaque` operation represents a C++ function call. The callee
@@ -257,10 +260,10 @@ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", []> {
257
260
let hasVerifier = 1;
258
261
}
259
262
260
- def EmitC_CastOp : EmitC_Op<"cast", [
261
- DeclareOpInterfaceMethods<CastOpInterface> ,
262
- SameOperandsAndResultShape
263
- ]> {
263
+ def EmitC_CastOp : EmitC_Op<"cast",
264
+ [CExpression ,
265
+ DeclareOpInterfaceMethods<CastOpInterface>,
266
+ SameOperandsAndResultShape ]> {
264
267
let summary = "Cast operation";
265
268
let description = [{
266
269
The `cast` operation performs an explicit type conversion and is emitted
@@ -284,7 +287,7 @@ def EmitC_CastOp : EmitC_Op<"cast", [
284
287
let assemblyFormat = "$source attr-dict `:` type($source) `to` type($dest)";
285
288
}
286
289
287
- def EmitC_CmpOp : EmitC_BinaryOp<"cmp", []> {
290
+ def EmitC_CmpOp : EmitC_BinaryOp<"cmp", [CExpression ]> {
288
291
let summary = "Comparison operation";
289
292
let description = [{
290
293
With the `cmp` operation the comparison operators ==, !=, <, <=, >, >=, <=>
@@ -355,7 +358,7 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
355
358
let hasVerifier = 1;
356
359
}
357
360
358
- def EmitC_DivOp : EmitC_BinaryOp<"div", []> {
361
+ def EmitC_DivOp : EmitC_BinaryOp<"div", [CExpression ]> {
359
362
let summary = "Division operation";
360
363
let description = [{
361
364
With the `div` operation the arithmetic operator / (division) can
@@ -409,9 +412,8 @@ def EmitC_ExpressionOp : EmitC_Op<"expression",
409
412
int32_t v7 = foo(v1 + v2) * (v3 + v4);
410
413
```
411
414
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`.
415
+ The operations allowed within expression body are EmitC operations with the
416
+ CExpression trait.
415
417
416
418
When specified, the optional `do_not_inline` indicates that the expression is
417
419
to be emitted as seen above, i.e. as the rhs of an EmitC SSA value
@@ -427,14 +429,9 @@ def EmitC_ExpressionOp : EmitC_Op<"expression",
427
429
let assemblyFormat = "attr-dict (`noinline` $do_not_inline^)? `:` type($result) $region";
428
430
429
431
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
432
bool hasSideEffects() {
436
433
auto predicate = [](Operation &op) {
437
- assert(isCExpression(op ) && "Expected a C expression");
434
+ assert(op.hasTrait<OpTrait::emitc::CExpression>( ) && "Expected a C expression");
438
435
// Conservatively assume calls to read and write memory.
439
436
if (isa<emitc::CallOpaqueOp>(op))
440
437
return true;
@@ -837,7 +834,7 @@ def EmitC_LogicalOrOp : EmitC_BinaryOp<"logical_or", []> {
837
834
let assemblyFormat = "operands attr-dict `:` type(operands)";
838
835
}
839
836
840
- def EmitC_MulOp : EmitC_BinaryOp<"mul", []> {
837
+ def EmitC_MulOp : EmitC_BinaryOp<"mul", [CExpression ]> {
841
838
let summary = "Multiplication operation";
842
839
let description = [{
843
840
With the `mul` operation the arithmetic operator * (multiplication) can
@@ -861,7 +858,7 @@ def EmitC_MulOp : EmitC_BinaryOp<"mul", []> {
861
858
let results = (outs FloatIntegerIndexOrOpaqueType);
862
859
}
863
860
864
- def EmitC_RemOp : EmitC_BinaryOp<"rem", []> {
861
+ def EmitC_RemOp : EmitC_BinaryOp<"rem", [CExpression ]> {
865
862
let summary = "Remainder operation";
866
863
let description = [{
867
864
With the `rem` operation the arithmetic operator % (remainder) can
@@ -883,7 +880,7 @@ def EmitC_RemOp : EmitC_BinaryOp<"rem", []> {
883
880
let results = (outs IntegerIndexOrOpaqueType);
884
881
}
885
882
886
- def EmitC_SubOp : EmitC_BinaryOp<"sub", []> {
883
+ def EmitC_SubOp : EmitC_BinaryOp<"sub", [CExpression ]> {
887
884
let summary = "Subtraction operation";
888
885
let description = [{
889
886
With the `sub` operation the arithmetic operator - (subtraction) can
0 commit comments