-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLIR][LLVM] Turn the inliner interface into a promised interface #103927
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
Conversation
This commit changes the LLVM dialect's inliner interface to no longer be registered at dialect initialization. Instead, it is now a promised interface, that needs to be registered explicitly. This change is desired to avoid pulling in a lot of dependencies into the `MLIRLLVMDialect` library, especially considering future patches that plan to extend it further with strong IR analysis.
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-mlir Author: Christian Ulmann (Dinistro) ChangesThis commit changes the LLVM dialect's inliner interface to no longer be registered at dialect initialization. Instead, it is now a promised interface, that needs to be registered explicitly. This change is desired to avoid pulling in a lot of dependencies into the Full diff: https://github.com/llvm/llvm-project/pull/103927.diff 7 Files Affected:
diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h
index 48cc1cbc645684..0192d7fdbea099 100644
--- a/flang/include/flang/Optimizer/Support/InitFIR.h
+++ b/flang/include/flang/Optimizer/Support/InitFIR.h
@@ -46,6 +46,7 @@ namespace fir::support {
inline void registerNonCodegenDialects(mlir::DialectRegistry ®istry) {
registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
mlir::func::registerInlinerExtension(registry);
+ mlir::LLVM::registerLLVMInlinerInterface(registry);
}
/// Register all the dialects used by flang.
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.h b/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
similarity index 64%
rename from mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.h
rename to mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
index c6f75d5657c3be..9c94cf6512195f 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
@@ -1,4 +1,4 @@
-//===- LLVMInlining.h - Registration of LLVMInlinerInterface ----*- C++ -*-===//
+//===- InlinerInterfaceImpl.h - Inlining for LLVM the dialect ---*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,28 +6,23 @@
//
//===----------------------------------------------------------------------===//
//
-// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect
-// during initialization.
+// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect.
//
//===----------------------------------------------------------------------===//
-#ifndef DIALECT_LLVMIR_IR_LLVMINLINING_H
-#define DIALECT_LLVMIR_IR_LLVMINLINING_H
+#ifndef MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
+#define MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
namespace mlir {
-namespace LLVM {
-
-class LLVMDialect;
+class DialectRegistry;
-namespace detail {
+namespace LLVM {
/// Register the `LLVMInlinerInterface` implementation of
/// `DialectInlinerInterface` with the LLVM dialect.
-void addLLVMInlinerInterface(LLVMDialect *dialect);
-
-} // namespace detail
+void registerLLVMInlinerInterface(DialectRegistry ®istry);
} // namespace LLVM
} // namespace mlir
-#endif // DIALECT_LLVMIR_IR_LLVMINLINING_H
+#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h
index 549c26c72d8a1e..cdece616e4cf7c 100644
--- a/mlir/include/mlir/InitAllDialects.h
+++ b/mlir/include/mlir/InitAllDialects.h
@@ -43,6 +43,7 @@
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Dialect/LLVMIR/ROCDLDialect.h"
+#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Transforms/AllInterfaces.h"
#include "mlir/Dialect/Linalg/Transforms/RuntimeOpVerification.h"
@@ -163,6 +164,7 @@ inline void registerAllDialects(DialectRegistry ®istry) {
cf::registerBufferizableOpInterfaceExternalModels(registry);
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
+ LLVM::registerLLVMInlinerInterface(registry);
linalg::registerAllDialectInterfaceImplementations(registry);
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
memref::registerAllocationOpInterfaceExternalModels(registry);
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index 392065b859ee54..fce24b556036f3 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -4,7 +4,6 @@ add_mlir_dialect_library(MLIRLLVMDialect
IR/FunctionCallUtils.cpp
IR/LLVMAttrs.cpp
IR/LLVMDialect.cpp
- IR/LLVMInlining.cpp
IR/LLVMInterfaces.cpp
IR/LLVMMemorySlot.cpp
IR/LLVMTypes.cpp
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 90610118a45cd2..476281d44e4306 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
-#include "LLVMInlining.h"
#include "TypeDetail.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
@@ -24,6 +23,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/FunctionImplementation.h"
+#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/TypeSwitch.h"
@@ -3200,7 +3200,7 @@ void LLVMDialect::initialize() {
// clang-format off
addInterfaces<LLVMOpAsmDialectInterface>();
// clang-format on
- detail::addLLVMInlinerInterface(this);
+ declarePromisedInterface<DialectInlinerInterface, LLVMDialect>();
}
#define GET_OP_CLASSES
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
index 728885fcbeaf38..d4ff0955c5d0e2 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
@@ -3,6 +3,7 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
DIExpressionLegalization.cpp
DIExpressionRewriter.cpp
DIScopeForLLVMFuncOp.cpp
+ InlinerInterfaceImpl.cpp
LegalizeForExport.cpp
OptimizeForNVVM.cpp
RequestCWrappers.cpp
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
similarity index 99%
rename from mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
rename to mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
index 137c1962b100af..55bf99f4228ae4 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
@@ -1,4 +1,4 @@
-//===- LLVMInlining.cpp - LLVM inlining interface and logic -----*- C++ -*-===//
+//===- InlinerInterfaceImpl.cpp - Inlining for LLVM the dialect -----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
//
//===----------------------------------------------------------------------===//
-#include "LLVMInlining.h"
+#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
@@ -850,6 +850,8 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
} // end anonymous namespace
-void LLVM::detail::addLLVMInlinerInterface(LLVM::LLVMDialect *dialect) {
- dialect->addInterfaces<LLVMInlinerInterface>();
+void mlir::LLVM::registerLLVMInlinerInterface(DialectRegistry ®istry) {
+ registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
+ dialect->addInterfaces<LLVMInlinerInterface>();
+ });
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
void addLLVMInlinerInterface(LLVMDialect *dialect); | ||
|
||
} // namespace detail | ||
void registerLLVMInlinerInterface(DialectRegistry ®istry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void registerLLVMInlinerInterface(DialectRegistry ®istry); | |
void registerInlinerInterface(DialectRegistry ®istry); |
Nit: since it is in the LLVM namespace it may make sense to drop it in the function name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Impl
naming seems weird, especially in a public header file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be the standard for such kind of things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/2372 Here is the relevant piece of the build log for the reference:
|
This seems to be a build timeout and should not be related to this PR. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/2442 Here is the relevant piece of the build log for the reference:
|
This commit changes the LLVM dialect's inliner interface to no longer be registered at dialect initialization. Instead, it is now a promised interface, that needs to be registered explicitly. This change is desired to avoid pulling in a lot of dependencies into the
MLIRLLVMDialect
library, especially considering future patches that plan to extend it further with strong IR analysis.