Skip to content

[mlir][EmitC] Add builders for call_opaque op #80879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

simon-camp
Copy link
Contributor

@simon-camp simon-camp commented Feb 6, 2024

This allows to omit the default valued attributes and therefore write more compact code.

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-emitc

Author: Simon Camphausen (simon-camp)

Changes

Add builders for the call_opaque op that has default valued attributes at the end. These can then be omitted during op creation.


Full diff: https://github.com/llvm/llvm-project/pull/80879.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/EmitC/IR/EmitC.td (+21)
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 39cc360cef41d4..b264a582df5aad 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -122,6 +122,27 @@ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", []> {
     Variadic<AnyType>:$operands
   );
   let results = (outs Variadic<AnyType>);
+  let builders = [
+    OpBuilder<(ins
+      "::mlir::TypeRange":$resultTypes,
+      "::llvm::StringRef":$callee,
+      "::mlir::ValueRange":$operands,
+      CArg<"::mlir::ArrayAttr", "{}">:$args,
+      CArg<"::mlir::ArrayAttr", "{}">:$template_args), [{
+        build($_builder, $_state, resultTypes, callee, args, template_args, operands);
+      }]
+    >,
+    OpBuilder<(ins
+      "::mlir::TypeRange":$resultTypes,
+      "::mlir::StringAttr":$callee,
+      "::mlir::ValueRange":$operands,
+      CArg<"::mlir::ArrayAttr", "{}">:$args,
+      CArg<"::mlir::ArrayAttr", "{}">:$template_args), [{
+        build($_builder, $_state, resultTypes, callee, args, template_args, operands);
+      }]
+    >
+  ];
+
   let assemblyFormat = [{
     $callee `(` $operands `)` attr-dict `:` functional-type($operands, results)
   }];

@simon-camp simon-camp marked this pull request as draft February 7, 2024 08:25
@simon-camp simon-camp force-pushed the emitc.call_opaque.builder branch 2 times, most recently from 49918bc to c9c1b01 Compare February 7, 2024 08:29
@simon-camp simon-camp marked this pull request as ready for review February 7, 2024 08:29
This allows to omit the default valued attributes and therefore write more compact code.
@simon-camp simon-camp force-pushed the emitc.call_opaque.builder branch from c9c1b01 to e9b4f9a Compare February 7, 2024 15:03
Copy link
Member

@AlexDenisov AlexDenisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I was about to suggest reordering optional op arguments (to move them to the end), but this is even better!

@simon-camp
Copy link
Contributor Author

Thank you, I was about to suggest reordering optional op arguments (to move them to the end), but this is even better!

That's what I did first and then I realized it would break all downstream users 😄

@simon-camp simon-camp merged commit 8f2378d into llvm:main Feb 8, 2024
@simon-camp simon-camp deleted the emitc.call_opaque.builder branch February 8, 2024 10:27
mgehre-amd pushed a commit to Xilinx/llvm-project that referenced this pull request Mar 11, 2024
This allows to omit the default valued attributes and therefore write
more compact code.
benvanik pushed a commit to iree-org/iree that referenced this pull request Aug 5, 2024
…17600)

llvm/llvm-project#80879 introduced custom build
methods for the `emitc.call_opaque` op for common cases.

Signed-off-by: Simon Camphausen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants