[Mlir-commits] [mlir] [mlir][acc] Add inline interface to acc dialect. (PR #127761)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 18 23:59:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-openacc
@llvm/pr-subscribers-openacc
Author: None (junfengd-nv)
<details>
<summary>Changes</summary>
Inliner interface could make inlining happens within OpenACC region. For example, the call site is as follows
```
acc.loop gang control(%arg2 : index) = (%c0_i64 : i64) to (%arg1 : i64) step (%c1_i64 : i64) {
%0 = arith.index_cast %arg2 : index to i64
func.call @<!-- -->_mlir_set(%arg0, %0, %0) : (memref<?xf64>, i64, i64) -> ()
acc.yield
}
```
Inliner will check whether the acc.loop operation is valid to inline any function calls. With this change, mlir-opt -inline could inline function "mlir_set" into acc.loop region to get better performance.
---
Full diff: https://github.com/llvm/llvm-project/pull/127761.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (+15)
``````````diff
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index 8f150cb33e6f3..18882439fa4b4 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -18,6 +18,7 @@
#include "mlir/IR/OpImplementation.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/DialectConversion.h"
+#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/LogicalResult.h"
@@ -76,6 +77,18 @@ struct LLVMPointerPointerLikeModel
LLVM::LLVMPointerType> {
Type getElementType(Type pointer) const { return Type(); }
};
+
+struct ACCInlinerInterface : public DialectInlinerInterface {
+ using DialectInlinerInterface::DialectInlinerInterface;
+ bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
+ IRMapping &valueMapping) const final {
+ return true;
+ }
+ bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
+ return true;
+ }
+ void handleTerminator(Operation *op, ValueRange valuesToRepl) const final {}
+};
} // namespace
//===----------------------------------------------------------------------===//
@@ -102,6 +115,8 @@ void OpenACCDialect::initialize() {
MemRefType::attachInterface<MemRefPointerLikeModel>(*getContext());
LLVM::LLVMPointerType::attachInterface<LLVMPointerPointerLikeModel>(
*getContext());
+
+ addInterfaces<ACCInlinerInterface>();
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/127761
More information about the Mlir-commits
mailing list