Skip to content
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

[mlir] allow inlining complex ops #77514

Merged
merged 1 commit into from Jan 10, 2024
Merged

Conversation

okkwon
Copy link
Contributor

@okkwon okkwon commented Jan 9, 2024

Complex ops are pure ops just like the arithmetic ops so they can be inlined.

@llvmbot llvmbot added mlir mlir:complex MLIR complex dialect labels Jan 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 9, 2024

@llvm/pr-subscribers-mlir-complex

@llvm/pr-subscribers-mlir

Author: Okwan Kwon (okkwon)

Changes

Complex ops are pure ops just like the arithmetic ops so they can be inlined.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp (+14)
diff --git a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
index e54b3a71bbc33e..ca57171af156f9 100644
--- a/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
+++ b/mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp
@@ -11,6 +11,7 @@
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/DialectImplementation.h"
+#include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/TypeSwitch.h"
 
@@ -18,6 +19,18 @@ using namespace mlir;
 
 #include "mlir/Dialect/Complex/IR/ComplexOpsDialect.cpp.inc"
 
+namespace {
+/// This class defines the interface for handling inlining for complex
+/// dialect operations.
+struct ComplexInlinerInterface : public DialectInlinerInterface {
+  using DialectInlinerInterface::DialectInlinerInterface;
+  /// All complex dialect ops can be inlined.
+  bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
+    return true;
+  }
+};
+} // namespace
+
 void complex::ComplexDialect::initialize() {
   addOperations<
 #define GET_OP_LIST
@@ -28,6 +41,7 @@ void complex::ComplexDialect::initialize() {
 #include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
       >();
   declarePromisedInterface<ComplexDialect, ConvertToLLVMPatternInterface>();
+  addInterfaces<ComplexInlinerInterface>();
 }
 
 Operation *complex::ComplexDialect::materializeConstant(OpBuilder &builder,

Complex ops are pure ops just like arithmetic ops so they can be inlined.
Copy link
Member

@Lewuathe Lewuathe left a comment

Choose a reason for hiding this comment

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

Thanks for adding test!

@okkwon okkwon merged commit 7cc9ae9 into llvm:main Jan 10, 2024
4 checks passed
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
Complex ops are pure ops just like the arithmetic ops so they can be
inlined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:complex MLIR complex dialect mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants