Skip to content
Closed
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
4 changes: 3 additions & 1 deletion mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ namespace {
struct FuncInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;

static constexpr const char* NoInlineAttrName = "noinline";
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, would it make sense to have this as a proper ODS attribute on FuncOp and CallOp? LLVM dialect already has one

OptionalAttr<UnitAttr>:$no_inline,
.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it'd be good to integrate this directly into the dialect if possible (makes it much cleaner to target). Otherwise you're at the whims of attribute propagation.


//===--------------------------------------------------------------------===//
// Analysis Hooks
//===--------------------------------------------------------------------===//

/// All call operations can be inlined.
bool isLegalToInline(Operation *call, Operation *callable,
bool wouldBeCloned) const final {
return true;
return !call->hasAttr(NoInlineAttrName) && !callable->hasAttr(NoInlineAttrName);
}

/// All operations can be inlined.
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Transforms/inlining.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ func.func @inline_with_arg(%arg0 : i32) -> i32 {
return %0 : i32
}

// CHECK-LABEL: func @noinline_with_arg
func.func @noinline_with_arg(%arg0 : i32) -> i32 {
// CHECK-NEXT: func_with_arg
// CHECK-NEXT: return

%0 = call @func_with_arg(%arg0) {"noinline"=""} : (i32) -> i32
return %0 : i32
}

// Inline a function that has multiple return operations.
func.func @func_with_multi_return(%a : i1) -> (i32) {
cf.cond_br %a, ^bb1, ^bb2
Expand Down
Loading