[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.
This commit is contained in:
parent
1115dee248
commit
4c2f90f362
@ -46,6 +46,7 @@ namespace fir::support {
|
|||||||
inline void registerNonCodegenDialects(mlir::DialectRegistry ®istry) {
|
inline void registerNonCodegenDialects(mlir::DialectRegistry ®istry) {
|
||||||
registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
|
registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
|
||||||
mlir::func::registerInlinerExtension(registry);
|
mlir::func::registerInlinerExtension(registry);
|
||||||
|
mlir::LLVM::registerInlinerInterface(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register all the dialects used by flang.
|
/// Register all the dialects used by flang.
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
|
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
|
||||||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
||||||
|
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
|
||||||
#include "toy/AST.h"
|
#include "toy/AST.h"
|
||||||
#include "toy/Dialect.h"
|
#include "toy/Dialect.h"
|
||||||
#include "toy/Lexer.h"
|
#include "toy/Lexer.h"
|
||||||
@ -299,6 +300,7 @@ int main(int argc, char **argv) {
|
|||||||
// If we aren't dumping the AST, then we are compiling with/to MLIR.
|
// If we aren't dumping the AST, then we are compiling with/to MLIR.
|
||||||
mlir::DialectRegistry registry;
|
mlir::DialectRegistry registry;
|
||||||
mlir::func::registerAllExtensions(registry);
|
mlir::func::registerAllExtensions(registry);
|
||||||
|
mlir::LLVM::registerInlinerInterface(registry);
|
||||||
|
|
||||||
mlir::MLIRContext context(registry);
|
mlir::MLIRContext context(registry);
|
||||||
// Load our Dialect in this MLIR Context.
|
// Load our Dialect in this MLIR Context.
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
|
#include "mlir/Dialect/Func/Extensions/AllExtensions.h"
|
||||||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
||||||
|
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
|
||||||
#include "toy/AST.h"
|
#include "toy/AST.h"
|
||||||
#include "toy/Dialect.h"
|
#include "toy/Dialect.h"
|
||||||
#include "toy/Lexer.h"
|
#include "toy/Lexer.h"
|
||||||
@ -300,6 +301,7 @@ int main(int argc, char **argv) {
|
|||||||
// If we aren't dumping the AST, then we are compiling with/to MLIR.
|
// If we aren't dumping the AST, then we are compiling with/to MLIR.
|
||||||
mlir::DialectRegistry registry;
|
mlir::DialectRegistry registry;
|
||||||
mlir::func::registerAllExtensions(registry);
|
mlir::func::registerAllExtensions(registry);
|
||||||
|
mlir::LLVM::registerInlinerInterface(registry);
|
||||||
|
|
||||||
mlir::MLIRContext context(registry);
|
mlir::MLIRContext context(registry);
|
||||||
// Load our Dialect in this MLIR Context.
|
// Load our Dialect in this MLIR Context.
|
||||||
|
@ -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.
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
// See https://llvm.org/LICENSE.txt for license information.
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
@ -6,28 +6,23 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect
|
// Allows registering the LLVM DialectInlinerInterface with the LLVM dialect.
|
||||||
// during initialization.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef DIALECT_LLVMIR_IR_LLVMINLINING_H
|
#ifndef MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
|
||||||
#define DIALECT_LLVMIR_IR_LLVMINLINING_H
|
#define MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
|
class DialectRegistry;
|
||||||
|
|
||||||
namespace LLVM {
|
namespace LLVM {
|
||||||
|
|
||||||
class LLVMDialect;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
/// Register the `LLVMInlinerInterface` implementation of
|
/// Register the `LLVMInlinerInterface` implementation of
|
||||||
/// `DialectInlinerInterface` with the LLVM dialect.
|
/// `DialectInlinerInterface` with the LLVM dialect.
|
||||||
void addLLVMInlinerInterface(LLVMDialect *dialect);
|
void registerInlinerInterface(DialectRegistry ®istry);
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
} // namespace LLVM
|
} // namespace LLVM
|
||||||
} // namespace mlir
|
} // namespace mlir
|
||||||
|
|
||||||
#endif // DIALECT_LLVMIR_IR_LLVMINLINING_H
|
#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
|
@ -43,6 +43,7 @@
|
|||||||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
||||||
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
|
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
|
||||||
#include "mlir/Dialect/LLVMIR/ROCDLDialect.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/IR/Linalg.h"
|
||||||
#include "mlir/Dialect/Linalg/Transforms/AllInterfaces.h"
|
#include "mlir/Dialect/Linalg/Transforms/AllInterfaces.h"
|
||||||
#include "mlir/Dialect/Linalg/Transforms/RuntimeOpVerification.h"
|
#include "mlir/Dialect/Linalg/Transforms/RuntimeOpVerification.h"
|
||||||
@ -164,6 +165,7 @@ inline void registerAllDialects(DialectRegistry ®istry) {
|
|||||||
cf::registerBufferizableOpInterfaceExternalModels(registry);
|
cf::registerBufferizableOpInterfaceExternalModels(registry);
|
||||||
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
|
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
|
||||||
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
|
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
|
||||||
|
LLVM::registerInlinerInterface(registry);
|
||||||
linalg::registerAllDialectInterfaceImplementations(registry);
|
linalg::registerAllDialectInterfaceImplementations(registry);
|
||||||
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
|
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
|
||||||
memref::registerAllocationOpInterfaceExternalModels(registry);
|
memref::registerAllocationOpInterfaceExternalModels(registry);
|
||||||
|
@ -4,7 +4,6 @@ add_mlir_dialect_library(MLIRLLVMDialect
|
|||||||
IR/FunctionCallUtils.cpp
|
IR/FunctionCallUtils.cpp
|
||||||
IR/LLVMAttrs.cpp
|
IR/LLVMAttrs.cpp
|
||||||
IR/LLVMDialect.cpp
|
IR/LLVMDialect.cpp
|
||||||
IR/LLVMInlining.cpp
|
|
||||||
IR/LLVMInterfaces.cpp
|
IR/LLVMInterfaces.cpp
|
||||||
IR/LLVMMemorySlot.cpp
|
IR/LLVMMemorySlot.cpp
|
||||||
IR/LLVMTypes.cpp
|
IR/LLVMTypes.cpp
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
||||||
#include "LLVMInlining.h"
|
|
||||||
#include "TypeDetail.h"
|
#include "TypeDetail.h"
|
||||||
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
|
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
|
||||||
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
|
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
|
||||||
@ -24,6 +23,7 @@
|
|||||||
#include "mlir/IR/MLIRContext.h"
|
#include "mlir/IR/MLIRContext.h"
|
||||||
#include "mlir/IR/Matchers.h"
|
#include "mlir/IR/Matchers.h"
|
||||||
#include "mlir/Interfaces/FunctionImplementation.h"
|
#include "mlir/Interfaces/FunctionImplementation.h"
|
||||||
|
#include "mlir/Transforms/InliningUtils.h"
|
||||||
|
|
||||||
#include "llvm/ADT/SCCIterator.h"
|
#include "llvm/ADT/SCCIterator.h"
|
||||||
#include "llvm/ADT/TypeSwitch.h"
|
#include "llvm/ADT/TypeSwitch.h"
|
||||||
@ -3252,7 +3252,7 @@ void LLVMDialect::initialize() {
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
addInterfaces<LLVMOpAsmDialectInterface>();
|
addInterfaces<LLVMOpAsmDialectInterface>();
|
||||||
// clang-format on
|
// clang-format on
|
||||||
detail::addLLVMInlinerInterface(this);
|
declarePromisedInterface<DialectInlinerInterface, LLVMDialect>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_OP_CLASSES
|
#define GET_OP_CLASSES
|
||||||
|
@ -3,6 +3,7 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
|
|||||||
DIExpressionLegalization.cpp
|
DIExpressionLegalization.cpp
|
||||||
DIExpressionRewriter.cpp
|
DIExpressionRewriter.cpp
|
||||||
DIScopeForLLVMFuncOp.cpp
|
DIScopeForLLVMFuncOp.cpp
|
||||||
|
InlinerInterfaceImpl.cpp
|
||||||
LegalizeForExport.cpp
|
LegalizeForExport.cpp
|
||||||
OptimizeForNVVM.cpp
|
OptimizeForNVVM.cpp
|
||||||
RequestCWrappers.cpp
|
RequestCWrappers.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.
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
// See https://llvm.org/LICENSE.txt for license information.
|
// 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/Dialect/LLVMIR/LLVMDialect.h"
|
||||||
#include "mlir/IR/Matchers.h"
|
#include "mlir/IR/Matchers.h"
|
||||||
#include "mlir/Interfaces/DataLayoutInterfaces.h"
|
#include "mlir/Interfaces/DataLayoutInterfaces.h"
|
||||||
@ -850,6 +850,8 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
|
|||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
void LLVM::detail::addLLVMInlinerInterface(LLVM::LLVMDialect *dialect) {
|
void mlir::LLVM::registerInlinerInterface(DialectRegistry ®istry) {
|
||||||
dialect->addInterfaces<LLVMInlinerInterface>();
|
registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
|
||||||
|
dialect->addInterfaces<LLVMInlinerInterface>();
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user