Skip to content

Commit 4c2f90f

Browse files
authored
[MLIR][LLVM] Turn the inliner interface into a promised interface (#103927)
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.
1 parent 1115dee commit 4c2f90f

File tree

9 files changed

+24
-20
lines changed

9 files changed

+24
-20
lines changed

flang/include/flang/Optimizer/Support/InitFIR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace fir::support {
4646
inline void registerNonCodegenDialects(mlir::DialectRegistry &registry) {
4747
registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
4848
mlir::func::registerInlinerExtension(registry);
49+
mlir::LLVM::registerInlinerInterface(registry);
4950
}
5051

5152
/// Register all the dialects used by flang.

mlir/examples/toy/Ch6/toyc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
1414
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15+
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
1516
#include "toy/AST.h"
1617
#include "toy/Dialect.h"
1718
#include "toy/Lexer.h"
@@ -299,6 +300,7 @@ int main(int argc, char **argv) {
299300
// If we aren't dumping the AST, then we are compiling with/to MLIR.
300301
mlir::DialectRegistry registry;
301302
mlir::func::registerAllExtensions(registry);
303+
mlir::LLVM::registerInlinerInterface(registry);
302304

303305
mlir::MLIRContext context(registry);
304306
// Load our Dialect in this MLIR Context.

mlir/examples/toy/Ch7/toyc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
1414
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15+
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
1516
#include "toy/AST.h"
1617
#include "toy/Dialect.h"
1718
#include "toy/Lexer.h"
@@ -300,6 +301,7 @@ int main(int argc, char **argv) {
300301
// If we aren't dumping the AST, then we are compiling with/to MLIR.
301302
mlir::DialectRegistry registry;
302303
mlir::func::registerAllExtensions(registry);
304+
mlir::LLVM::registerInlinerInterface(registry);
303305

304306
mlir::MLIRContext context(registry);
305307
// Load our Dialect in this MLIR Context.
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
//===- LLVMInlining.h - Registration of LLVMInlinerInterface ----*- C++ -*-===//
1+
//===- InlinerInterfaceImpl.h - Inlining for LLVM the dialect ---*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect
10-
// during initialization.
9+
// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect.
1110
//
1211
//===----------------------------------------------------------------------===//
1312

14-
#ifndef DIALECT_LLVMIR_IR_LLVMINLINING_H
15-
#define DIALECT_LLVMIR_IR_LLVMINLINING_H
13+
#ifndef MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
14+
#define MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
1615

1716
namespace mlir {
18-
namespace LLVM {
19-
20-
class LLVMDialect;
17+
class DialectRegistry;
2118

22-
namespace detail {
19+
namespace LLVM {
2320

2421
/// Register the `LLVMInlinerInterface` implementation of
2522
/// `DialectInlinerInterface` with the LLVM dialect.
26-
void addLLVMInlinerInterface(LLVMDialect *dialect);
27-
28-
} // namespace detail
23+
void registerInlinerInterface(DialectRegistry &registry);
2924

3025
} // namespace LLVM
3126
} // namespace mlir
3227

33-
#endif // DIALECT_LLVMIR_IR_LLVMINLINING_H
28+
#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H

mlir/include/mlir/InitAllDialects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
4444
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
4545
#include "mlir/Dialect/LLVMIR/ROCDLDialect.h"
46+
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
4647
#include "mlir/Dialect/Linalg/IR/Linalg.h"
4748
#include "mlir/Dialect/Linalg/Transforms/AllInterfaces.h"
4849
#include "mlir/Dialect/Linalg/Transforms/RuntimeOpVerification.h"
@@ -164,6 +165,7 @@ inline void registerAllDialects(DialectRegistry &registry) {
164165
cf::registerBufferizableOpInterfaceExternalModels(registry);
165166
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
166167
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
168+
LLVM::registerInlinerInterface(registry);
167169
linalg::registerAllDialectInterfaceImplementations(registry);
168170
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
169171
memref::registerAllocationOpInterfaceExternalModels(registry);

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ add_mlir_dialect_library(MLIRLLVMDialect
44
IR/FunctionCallUtils.cpp
55
IR/LLVMAttrs.cpp
66
IR/LLVMDialect.cpp
7-
IR/LLVMInlining.cpp
87
IR/LLVMInterfaces.cpp
98
IR/LLVMMemorySlot.cpp
109
IR/LLVMTypes.cpp

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15-
#include "LLVMInlining.h"
1615
#include "TypeDetail.h"
1716
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
1817
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
@@ -24,6 +23,7 @@
2423
#include "mlir/IR/MLIRContext.h"
2524
#include "mlir/IR/Matchers.h"
2625
#include "mlir/Interfaces/FunctionImplementation.h"
26+
#include "mlir/Transforms/InliningUtils.h"
2727

2828
#include "llvm/ADT/SCCIterator.h"
2929
#include "llvm/ADT/TypeSwitch.h"
@@ -3252,7 +3252,7 @@ void LLVMDialect::initialize() {
32523252
// clang-format off
32533253
addInterfaces<LLVMOpAsmDialectInterface>();
32543254
// clang-format on
3255-
detail::addLLVMInlinerInterface(this);
3255+
declarePromisedInterface<DialectInlinerInterface, LLVMDialect>();
32563256
}
32573257

32583258
#define GET_OP_CLASSES

mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
33
DIExpressionLegalization.cpp
44
DIExpressionRewriter.cpp
55
DIScopeForLLVMFuncOp.cpp
6+
InlinerInterfaceImpl.cpp
67
LegalizeForExport.cpp
78
OptimizeForNVVM.cpp
89
RequestCWrappers.cpp

mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp renamed to mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- LLVMInlining.cpp - LLVM inlining interface and logic -----*- C++ -*-===//
1+
//===- InlinerInterfaceImpl.cpp - Inlining for LLVM the dialect -----------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "LLVMInlining.h"
14+
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
1515
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1616
#include "mlir/IR/Matchers.h"
1717
#include "mlir/Interfaces/DataLayoutInterfaces.h"
@@ -850,6 +850,8 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
850850

851851
} // end anonymous namespace
852852

853-
void LLVM::detail::addLLVMInlinerInterface(LLVM::LLVMDialect *dialect) {
854-
dialect->addInterfaces<LLVMInlinerInterface>();
853+
void mlir::LLVM::registerInlinerInterface(DialectRegistry &registry) {
854+
registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
855+
dialect->addInterfaces<LLVMInlinerInterface>();
856+
});
855857
}

0 commit comments

Comments
 (0)