Skip to content

[mlir][Vector] Add initial support for inlining in the presence of vector ops #70942

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 1 commit into from
Nov 1, 2023
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
16 changes: 16 additions & 0 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/ValueBoundsOpInterface.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -348,6 +349,19 @@ struct BitmaskEnumStorage : public AttributeStorage {
// VectorDialect
//===----------------------------------------------------------------------===//

namespace {
/// This class defines the interface for handling inlining with vector dialect
/// operations.
struct VectorInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;

/// All vector dialect ops can be inlined.
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
return true;
}
};
} // namespace

void VectorDialect::initialize() {
addAttributes<
#define GET_ATTRDEF_LIST
Expand All @@ -358,6 +372,8 @@ void VectorDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/Vector/IR/VectorOps.cpp.inc"
>();

addInterfaces<VectorInlinerInterface>();
}

/// Materialize a single constant operation from a given attribute value with
Expand Down
14 changes: 14 additions & 0 deletions mlir/test/Dialect/Vector/inlining.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: mlir-opt %s -inline | FileCheck %s

func.func @inner_func_inlinable(%v: f32) -> vector<4xf32> {
%1 = vector.broadcast %v : f32 to vector<4xf32>
return %1 : vector<4xf32>
}

// CHECK-LABEL: func.func @test_inline(
// CHECK-NOT: func.call
// CHECK-NEXT: vector.broadcast
func.func @test_inline(%v: f32) -> vector<4xf32> {
%0 = call @inner_func_inlinable(%v) : (f32) -> vector<4xf32>
return %0 : vector<4xf32>
}