Skip to content

Commit 6acb433

Browse files
committed
Merge branch 'mlir-call-attrs-iface' into mlir-call-attrs-llvm
2 parents 879b03d + 3328f68 commit 6acb433

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

mlir/include/mlir/Interfaces/CallImplementation.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
namespace mlir {
2222

23-
class OpWithArgumentAttributesInterface;
24-
2523
namespace call_interface_impl {
2624

2725
/// Parse a function or call result list.
@@ -65,8 +63,7 @@ ParseResult parseFunctionSignature(OpAsmParser &parser,
6563
/// -> function-result-list
6664
/// ssa-function-arg-list ::= ssa-function-arg (`,` ssa-function-arg)*
6765
/// ssa-function-arg ::= `%`name `:` type attribute-dict?
68-
void printFunctionSignature(OpAsmPrinter &p,
69-
OpWithArgumentAttributesInterface op,
66+
void printFunctionSignature(OpAsmPrinter &p, ArgumentAttributesOpInterface op,
7067
TypeRange argTypes, bool isVariadic,
7168
TypeRange resultTypes, Region *body = nullptr,
7269
bool printEmptyResult = true);

mlir/include/mlir/Interfaces/CallInterfaces.td

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ include "mlir/IR/OpBase.td"
2020

2121
/// Interface for operations with arguments attributes (both call-like
2222
/// and callable operations).
23-
def OpWithArgumentAttributesInterface : OpInterface<"OpWithArgumentAttributesInterface"> {
23+
def ArgumentAttributesOpInterface : OpInterface<"ArgumentAttributesOpInterface"> {
2424
let description = [{
25-
A call-like or callable operation that may define attributes for its arguments.
25+
A call-like or callable operation that can hold attributes for its arguments
26+
and results.
2627
}];
2728
let cppNamespace = "::mlir";
2829
let methods = [
@@ -32,40 +33,34 @@ def OpWithArgumentAttributesInterface : OpInterface<"OpWithArgumentAttributesInt
3233
number to the number of arguments. Alternatively, the method can
3334
return null to indicate that the region has no argument attributes.
3435
}],
35-
"::mlir::ArrayAttr", "getArgAttrsAttr", (ins),
36-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return nullptr; }]>,
36+
"::mlir::ArrayAttr", "getArgAttrsAttr">,
3737
InterfaceMethod<[{
3838
Get the array of result attribute dictionaries. The method should return
3939
an array attribute containing only dictionary attributes equal in number
4040
to the number of results. Alternatively, the method can return
4141
null to indicate that the region has no result attributes.
4242
}],
43-
"::mlir::ArrayAttr", "getResAttrsAttr", (ins),
44-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return nullptr; }]>,
43+
"::mlir::ArrayAttr", "getResAttrsAttr">,
4544
InterfaceMethod<[{
4645
Set the array of argument attribute dictionaries.
4746
}],
48-
"void", "setArgAttrsAttr", (ins "::mlir::ArrayAttr":$attrs),
49-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return; }]>,
47+
"void", "setArgAttrsAttr", (ins "::mlir::ArrayAttr":$attrs)>,
5048
InterfaceMethod<[{
5149
Set the array of result attribute dictionaries.
5250
}],
53-
"void", "setResAttrsAttr", (ins "::mlir::ArrayAttr":$attrs),
54-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return; }]>,
51+
"void", "setResAttrsAttr", (ins "::mlir::ArrayAttr":$attrs)>,
5552
InterfaceMethod<[{
5653
Remove the array of argument attribute dictionaries. This is the same as
5754
setting all argument attributes to an empty dictionary. The method should
5855
return the removed attribute.
5956
}],
60-
"::mlir::Attribute", "removeArgAttrsAttr", (ins),
61-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return nullptr; }]>,
57+
"::mlir::Attribute", "removeArgAttrsAttr">,
6258
InterfaceMethod<[{
6359
Remove the array of result attribute dictionaries. This is the same as
6460
setting all result attributes to an empty dictionary. The method should
6561
return the removed attribute.
6662
}],
67-
"::mlir::Attribute", "removeResAttrsAttr", (ins),
68-
/*methodBody=*/[{}], /*defaultImplementation=*/[{ return nullptr; }]>,
63+
"::mlir::Attribute", "removeResAttrsAttr">
6964
];
7065
}
7166

@@ -74,8 +69,7 @@ def OpWithArgumentAttributesInterface : OpInterface<"OpWithArgumentAttributesInt
7469
// a call-like operation. This represents the destination of the call.
7570

7671
/// Interface for call-like operations.
77-
def CallOpInterface : OpInterface<"CallOpInterface",
78-
[OpWithArgumentAttributesInterface]> {
72+
def CallOpInterface : OpInterface<"CallOpInterface"> {
7973
let description = [{
8074
A call-like operation is one that transfers control from one sub-routine to
8175
another. These operations may be traditional direct calls `call @foo`, or
@@ -138,8 +132,7 @@ def CallOpInterface : OpInterface<"CallOpInterface",
138132
}
139133

140134
/// Interface for callable operations.
141-
def CallableOpInterface : OpInterface<"CallableOpInterface",
142-
[OpWithArgumentAttributesInterface]> {
135+
def CallableOpInterface : OpInterface<"CallableOpInterface"> {
143136
let description = [{
144137
A callable operation is one who represents a potential sub-routine, and may
145138
be a target for a call-like operation (those providing the CallOpInterface

mlir/include/mlir/Interfaces/FunctionInterfaces.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include "mlir/Interfaces/CallInterfaces.td"
2222
//===----------------------------------------------------------------------===//
2323

2424
def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
25-
Symbol, CallableOpInterface
25+
Symbol, CallableOpInterface, ArgumentAttributesOpInterface
2626
]> {
2727
let cppNamespace = "::mlir";
2828
let description = [{

mlir/lib/Interfaces/CallImplementation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void printFunctionResultList(OpAsmPrinter &p, TypeRange types,
9595
}
9696

9797
void call_interface_impl::printFunctionSignature(
98-
OpAsmPrinter &p, OpWithArgumentAttributesInterface op, TypeRange argTypes,
98+
OpAsmPrinter &p, ArgumentAttributesOpInterface op, TypeRange argTypes,
9999
bool isVariadic, TypeRange resultTypes, Region *body,
100100
bool printEmptyResult) {
101101
bool isExternal = !body || body->empty();

mlir/lib/Transforms/Utils/InliningUtils.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ static void handleArgumentImpl(InlinerInterface &interface, OpBuilder &builder,
193193
SmallVector<DictionaryAttr> argAttrs(
194194
callable.getCallableRegion()->getNumArguments(),
195195
builder.getDictionaryAttr({}));
196-
if (ArrayAttr arrayAttr = callable.getArgAttrsAttr()) {
197-
assert(arrayAttr.size() == argAttrs.size());
198-
for (auto [idx, attr] : llvm::enumerate(arrayAttr))
199-
argAttrs[idx] = cast<DictionaryAttr>(attr);
200-
}
196+
if (auto argAttrsOpInterface =
197+
dyn_cast<ArgumentAttributesOpInterface>(callable.getOperation()))
198+
if (ArrayAttr arrayAttr = argAttrsOpInterface.getArgAttrsAttr()) {
199+
assert(arrayAttr.size() == argAttrs.size());
200+
for (auto [idx, attr] : llvm::enumerate(arrayAttr))
201+
argAttrs[idx] = cast<DictionaryAttr>(attr);
202+
}
201203

202204
// Run the argument attribute handler for the given argument and attribute.
203205
for (auto [blockArg, argAttr] :
@@ -218,11 +220,13 @@ static void handleResultImpl(InlinerInterface &interface, OpBuilder &builder,
218220
// Unpack the result attributes if there are any.
219221
SmallVector<DictionaryAttr> resAttrs(results.size(),
220222
builder.getDictionaryAttr({}));
221-
if (ArrayAttr arrayAttr = callable.getResAttrsAttr()) {
222-
assert(arrayAttr.size() == resAttrs.size());
223-
for (auto [idx, attr] : llvm::enumerate(arrayAttr))
224-
resAttrs[idx] = cast<DictionaryAttr>(attr);
225-
}
223+
if (auto argAttrsOpInterface =
224+
dyn_cast<ArgumentAttributesOpInterface>(callable.getOperation()))
225+
if (ArrayAttr arrayAttr = argAttrsOpInterface.getResAttrsAttr()) {
226+
assert(arrayAttr.size() == resAttrs.size());
227+
for (auto [idx, attr] : llvm::enumerate(arrayAttr))
228+
resAttrs[idx] = cast<DictionaryAttr>(attr);
229+
}
226230

227231
// Run the result attribute handler for the given result and attribute.
228232
SmallVector<DictionaryAttr> resultAttributes;

0 commit comments

Comments
 (0)