Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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/include/mlir/Interfaces/FunctionInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallString.h"

Expand Down
23 changes: 23 additions & 0 deletions mlir/include/mlir/Interfaces/FunctionInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
}
}

// FunctionOpInterface is tied to a ReturnLike.
Operation *terminator = entryBlock.getTerminator();
if (terminator->hasTrait<OpTrait::ReturnLike>()) {
return $_op.emitOpError("The body of a FunctionOpInterface must")
<< "have a ReturnLike terminator.";
}

// Match ReturnLike's operand types and FunctionOpInterface's
// result types.
auto returnOperandTypes = terminator->getOperandTypes();
auto funcResultTypes = $_op->getResultTypes();
if (funcResultTypes.size() != returnOperandTypes.size()) {
return $_op.emitOpError("The number of a FunctionOpInterface's")
<< "result must match that of the ReturnLike operands.";
}

for (unsigned i = 0; i < funcResultTypes.size(); ++i) {
if (funcResultTypes[i] != returnOperandTypes[i]) {
return $_op.emitOpError("The result types of a FunctionOpInterface")
<< "must match the operand types of the ReturnLike.";
}
}

return success();
}]>,
InterfaceMethod<[{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
if (!returnOp)
return funcOp->emitError()
<< "cannot bufferize a FuncOp with tensors and "
"without a unique ReturnOp";
<< "cannot bufferize a FunctionOpInterface with tensors and "
"without a unique ReturnLike";
}

// Collect function calls and populate the caller map.
Expand Down
Loading