Skip to content

[mlir] Make the ml_program dialect allow all of its operations to be inlined. #85479

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
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 mlir/lib/Dialect/MLProgram/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ add_mlir_dialect_library(MLIRMLProgramDialect
MLIRControlFlowInterfaces
MLIRFunctionInterfaces
MLIRInferTypeOpInterface
MLIRTransforms
MLIRIR
)
15 changes: 14 additions & 1 deletion mlir/lib/Dialect/MLProgram/IR/MLProgramDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "mlir/Dialect/MLProgram/IR/MLProgram.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/Transforms/InliningUtils.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the utils needed for the interface?

#include "llvm/ADT/TypeSwitch.h"

using namespace mlir;
Expand All @@ -24,6 +25,18 @@ using namespace mlir::ml_program;
#include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc"

namespace {

struct MLProgramInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;

bool isLegalToInline(Operation *, Region *, bool,
IRMapping &) const override {
// We have no specific opinion on whether ops defined in this dialect should
// be inlined.
return true;
}
};

struct MLProgramOpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;

Expand Down Expand Up @@ -53,5 +66,5 @@ void ml_program::MLProgramDialect::initialize() {
#include "mlir/Dialect/MLProgram/IR/MLProgramOps.cpp.inc"
>();

addInterfaces<MLProgramOpAsmDialectInterface>();
addInterfaces<MLProgramInlinerInterface, MLProgramOpAsmDialectInterface>();
}
19 changes: 19 additions & 0 deletions mlir/test/Dialect/MLProgram/inlining.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: mlir-opt %s -inline | FileCheck %s

// Verifies that regions with operations from the ml_program dialect can
// be inlined.

ml_program.global private @global(dense<4> : tensor<4xi32>) : tensor<4xi32>

// CHECK: @inline_into
func.func @inline_into() -> tensor<4xi32> {
// CHECK-NOT: @inline_from
// CHECK: ml_program.global_load_const
%0 = call @inline_from() : () -> tensor<4xi32>
return %0 : tensor<4xi32>
}

func.func @inline_from() -> tensor<4xi32> {
%0 = ml_program.global_load_const @global : tensor<4xi32>
return %0 : tensor<4xi32>
}