[Mlir-commits] [mlir] [mlir] allow inlining complex ops (PR #77514)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 9 11:11:21 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-complex

@llvm/pr-subscribers-mlir

Author: Okwan Kwon (okkwon)

<details>
<summary>Changes</summary>

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
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,

``````````

</details>


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


More information about the Mlir-commits mailing list