@@ -14,6 +14,7 @@ include "TestInterfaces.td"
14
14
include "mlir/Dialect/DLTI/DLTIBase.td"
15
15
include "mlir/Dialect/Linalg/IR/LinalgInterfaces.td"
16
16
include "mlir/IR/EnumAttr.td"
17
+ include "mlir/IR/FunctionInterfaces.td"
17
18
include "mlir/IR/OpBase.td"
18
19
include "mlir/IR/OpAsmInterface.td"
19
20
include "mlir/IR/PatternBase.td"
@@ -482,6 +483,72 @@ def ConversionCallOp : TEST_Op<"conversion_call_op",
482
483
}];
483
484
}
484
485
486
+ def ConversionFuncOp : TEST_Op<"conversion_func_op", [CallableOpInterface,
487
+ FunctionOpInterface]> {
488
+ let arguments = (ins SymbolNameAttr:$sym_name,
489
+ TypeAttrOf<FunctionType>:$function_type,
490
+ OptionalAttr<DictArrayAttr>:$arg_attrs,
491
+ OptionalAttr<DictArrayAttr>:$res_attrs,
492
+ OptionalAttr<StrAttr>:$sym_visibility);
493
+ let regions = (region AnyRegion:$body);
494
+
495
+ let extraClassDeclaration = [{
496
+ //===------------------------------------------------------------------===//
497
+ // CallableOpInterface
498
+ //===------------------------------------------------------------------===//
499
+
500
+ /// Returns the region on the current operation that is callable. This may
501
+ /// return null in the case of an external callable object, e.g. an external
502
+ /// function.
503
+ ::mlir::Region *getCallableRegion() {
504
+ return isExternal() ? nullptr : &getBody();
505
+ }
506
+
507
+ /// Returns the results types that the callable region produces when
508
+ /// executed.
509
+ ::mlir::ArrayRef<::mlir::Type> getCallableResults() {
510
+ return getFunctionType().getResults();
511
+ }
512
+
513
+ /// Returns the argument attributes for all callable region arguments or
514
+ /// null if there are none.
515
+ ::mlir::ArrayAttr getCallableArgAttrs() {
516
+ return getArgAttrs().value_or(nullptr);
517
+ }
518
+
519
+ /// Returns the result attributes for all callable region results or
520
+ /// null if there are none.
521
+ ::mlir::ArrayAttr getCallableResAttrs() {
522
+ return getResAttrs().value_or(nullptr);
523
+ }
524
+
525
+ //===------------------------------------------------------------------===//
526
+ // FunctionOpInterface Methods
527
+ //===------------------------------------------------------------------===//
528
+
529
+ /// Returns the argument types of this async function.
530
+ ::mlir::ArrayRef<::mlir::Type> getArgumentTypes() {
531
+ return getFunctionType().getInputs();
532
+ }
533
+
534
+ /// Returns the result types of this async function.
535
+ ::mlir::ArrayRef<::mlir::Type> getResultTypes() {
536
+ return getFunctionType().getResults();
537
+ }
538
+
539
+ /// Returns the number of results of this async function
540
+ unsigned getNumResults() {return getResultTypes().size();}
541
+
542
+ //===------------------------------------------------------------------===//
543
+ // SymbolOpInterface Methods
544
+ //===------------------------------------------------------------------===//
545
+
546
+ bool isDeclaration() { return isExternal(); }
547
+ }];
548
+
549
+ let hasCustomAssemblyFormat = 1;
550
+ }
551
+
485
552
def FunctionalRegionOp : TEST_Op<"functional_region_op",
486
553
[CallableOpInterface]> {
487
554
let regions = (region AnyRegion:$body);
0 commit comments