Skip to content

[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

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang/include/flang/Optimizer/Support/InitFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace fir::support {
inline void registerNonCodegenDialects(mlir::DialectRegistry &registry) {
registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
mlir::func::registerInlinerExtension(registry);
mlir::LLVM::registerInlinerInterface(registry);
}

/// Register all the dialects used by flang.
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch6/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

mlir::MLIRContext context(registry);
// Load our Dialect in this MLIR Context.
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch7/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

mlir::MLIRContext context(registry);
// Load our Dialect in this MLIR Context.
Expand Down
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
//===- 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.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// 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 registerInlinerInterface(DialectRegistry &registry);

} // namespace LLVM
} // namespace mlir

#endif // DIALECT_LLVMIR_IR_LLVMINLINING_H
#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
2 changes: 2 additions & 0 deletions mlir/include/mlir/InitAllDialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -163,6 +164,7 @@ inline void registerAllDialects(DialectRegistry &registry) {
cf::registerBufferizableOpInterfaceExternalModels(registry);
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
LLVM::registerInlinerInterface(registry);
linalg::registerAllDialectInterfaceImplementations(registry);
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
memref::registerAllocationOpInterfaceExternalModels(registry);
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/LLVMIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
DIExpressionLegalization.cpp
DIExpressionRewriter.cpp
DIScopeForLLVMFuncOp.cpp
InlinerInterfaceImpl.cpp
LegalizeForExport.cpp
OptimizeForNVVM.cpp
RequestCWrappers.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down Expand Up @@ -850,6 +850,8 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {

} // end anonymous namespace

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