Skip to content

Commit 3f22547

Browse files
committed
Revert "[mlir][Linalg] Improve region support in Linalg ops."
This reverts commit 973e133. It triggers an issue in gcc5 that require investigation, the build is broken with: /tmp/ccdpj3B9.s: Assembler messages: /tmp/ccdpj3B9.s:5821: Error: symbol `_ZNSt17_Function_handlerIFvjjEUljjE2_E9_M_invokeERKSt9_Any_dataOjS6_' is already defined /tmp/ccdpj3B9.s:5860: Error: symbol `_ZNSt14_Function_base13_Base_managerIUljjE2_E10_M_managerERSt9_Any_dataRKS3_St18_Manager_operation' is already defined
1 parent a7538fe commit 3f22547

File tree

11 files changed

+280
-316
lines changed

11 files changed

+280
-316
lines changed

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,20 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
10561056
//===------------------------------------------------------------------===//
10571057
// Other static interface methods.
10581058
//===------------------------------------------------------------------===//
1059+
StaticInterfaceMethod<
1060+
/*desc=*/[{
1061+
Create an operation of the current type with the given location,
1062+
operands, and attributes.
1063+
}],
1064+
/*retTy=*/"Operation *",
1065+
/*methodName=*/"create",
1066+
(ins "OpBuilder &":$builder, "Location":$loc, "TypeRange":$resultTypes,
1067+
"ValueRange":$operands,
1068+
"ArrayRef<NamedAttribute>":$attributes), [{
1069+
return builder.create<ConcreteOp>(
1070+
loc, resultTypes, operands, attributes);
1071+
}]
1072+
>,
10591073
InterfaceMethod<
10601074
/*desc=*/[{
10611075
Clone the current operation with the given location and operands. This
@@ -1068,13 +1082,14 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
10681082
(ins "OpBuilder &":$b, "Location":$loc, "TypeRange":$resultTypes,
10691083
"ValueRange":$operands),
10701084
[{
1071-
BlockAndValueMapping bvm;
1072-
OperationState state(
1073-
loc, ConcreteOp::getOperationName(), operands, resultTypes,
1074-
$_op->getAttrs());
1075-
for (Region &r : $_op->getRegions())
1076-
r.cloneInto(state.addRegion(), bvm);
1077-
return b.createOperation(state);
1085+
BlockAndValueMapping map;
1086+
unsigned numRegions = $_op->getNumRegions();
1087+
Operation *res = create(b, loc, resultTypes, operands, $_op->getAttrs());
1088+
assert(res->getNumRegions() == numRegions && "inconsistent # regions");
1089+
for (unsigned ridx = 0; ridx < numRegions; ++ridx)
1090+
$_op->getRegion(ridx).cloneInto(
1091+
&res->getRegion(ridx), map);
1092+
return res;
10781093
}]
10791094
>,
10801095
StaticInterfaceMethod<
@@ -1083,7 +1098,7 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
10831098
Returns a null function if this named op does not define a region
10841099
builder.
10851100
}],
1086-
/*retTy=*/"std::function<void(Block &, ValueRange)>",
1101+
/*retTy=*/"std::function<void(Block &)>",
10871102
/*methodName=*/"getRegionBuilder",
10881103
(ins),
10891104
[{ return ConcreteOp::getRegionBuilder(); }]

mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ def CopyOp : LinalgStructured_Op<"copy", [CopyOpInterface]> {
110110
AnyStridedMemRef:$output,
111111
OptionalAttr<AffineMapAttr>:$inputPermutation,
112112
OptionalAttr<AffineMapAttr>:$outputPermutation);
113-
let regions = (region AnyRegion:$region);
114113

115-
let builders = [
116-
OpBuilderDAG<(ins "Value":$input, "Value":$output,
117-
CArg<"AffineMap", "AffineMap()">:$inputPermutation,
118-
CArg<"AffineMap", "AffineMap()">:$outputPermutation,
119-
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>];
114+
// TODO: this should go away once the usage of OptionalAttr triggers emission
115+
// of builders with default arguments left unspecified.
116+
let builders = [OpBuilderDAG<(ins "Value":$input, "Value":$output),
117+
[{
118+
return build(
119+
$_builder, $_state, input, output, AffineMapAttr(), AffineMapAttr());
120+
}]>];
120121

121122
let extraClassDeclaration = structuredOpsDecls # [{
122123
ValueRange inputs() { return getOperands().take_front(); }
@@ -145,31 +146,24 @@ def CopyOp : LinalgStructured_Op<"copy", [CopyOpInterface]> {
145146
Value getSource() { return input();}
146147
Value getTarget() { return output(); }
147148

148-
static void regionBuilder(Block &block, ValueRange captures);
149-
static std::function<void(Block &block, ValueRange captures)>
150-
getRegionBuilder() {
151-
return &regionBuilder;
149+
static std::function<void(Block &)> getRegionBuilder() {
150+
return nullptr;
152151
}
153-
static unsigned getNumRegionArgs() { return 2; }
154152
}];
155153
let verifier = [{ return ::verify(*this); }];
156154

157155
let assemblyFormat = [{
158-
`(` $input `,` $output `)` attr-dict `:`
159-
type($input) `,` type($output)
160-
custom<CopyOpRegion>($region, ref(type($input)), ref(type($input)))
156+
`(` operands `)` attr-dict `:` type(operands)
161157
}];
162158

163159
let hasFolder = 1;
164160
let hasCanonicalizer = 1;
165-
let skipDefaultBuilders = 1;
166161
}
167162

168163
def FillOp : LinalgStructured_Op<"fill", []> {
169164
let arguments = (ins AnyShaped:$output,
170165
AnyTypeOf<[AnyFloat, AnySignlessInteger, AnyVector]>:$value);
171166
let results = (outs Optional<AnyRankedTensor>:$result);
172-
let regions = (region AnyRegion:$region);
173167
let extraClassDeclaration = structuredOpsDecls # [{
174168
ValueRange inputs() { return {}; }
175169
ValueRange outputs() { return getOperands().take_front(); }
@@ -189,18 +183,13 @@ def FillOp : LinalgStructured_Op<"fill", []> {
189183
extractOrIdentityMap(llvm::None, getNumParallelLoops(), context)});
190184
}
191185

192-
static void regionBuilder(Block &block, ValueRange captures);
193-
static std::function<void(Block &block, ValueRange captures)>
194-
getRegionBuilder() {
195-
return &regionBuilder;
186+
static std::function<void(Block &)> getRegionBuilder() {
187+
return nullptr;
196188
}
197-
static unsigned getNumRegionArgs() { return 1; }
198189
}];
199190

200191
let assemblyFormat = [{
201-
`(` $output `,` $value `)` attr-dict `:`
202-
type($output) `,` type($value) (`->` type($result)^)?
203-
custom<FillOpRegion>($region, ref(type($output)), ref($value))
192+
`(` operands `)` attr-dict `:` type(operands) (`->` type($result)^)?
204193
}];
205194

206195
let builders = [
@@ -279,8 +268,7 @@ class PoolingBase_Op<string mnemonic, list<OpTrait> props>
279268
return padding().getValue().getValue<int64_t>({i, 1});
280269
}
281270

282-
static std::function<void(Block &, ValueRange captures)> getRegionBuilder()
283-
{
271+
static std::function<void(Block &)> getRegionBuilder() {
284272
return nullptr;
285273
}
286274
}];
@@ -531,7 +519,7 @@ class GenericOpBase<string mnemonic> : LinalgStructuredBase_Op<mnemonic, [
531519
library_call()->str() : "op_has_no_registered_library_name";
532520
}
533521

534-
static std::function<void(Block &, ValueRange)> getRegionBuilder() {
522+
static std::function<void(Block &)> getRegionBuilder() {
535523
return nullptr;
536524
}
537525
}];

mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,7 @@ LogicalResult mlir::linalg::CopyTransposeRewrite::matchAndRewrite(
154154
if (in == op.input() && out == op.output())
155155
return failure();
156156

157-
auto libraryCallName = getLibraryCallSymbolRef(op, rewriter);
158-
if (!libraryCallName)
159-
return failure();
160-
161-
rewriter.replaceOpWithNewOp<mlir::CallOp>(
162-
op, libraryCallName.getValue(), TypeRange(),
163-
createTypeCanonicalizedMemRefOperands(rewriter, op.getLoc(), {in, out}));
157+
rewriter.replaceOpWithNewOp<CopyOp>(op, in, out);
164158
return success();
165159
}
166160

mlir/lib/Dialect/Linalg/EDSC/Builders.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Operation *mlir::edsc::makeGenericLinalgOp(
2727
ArrayRef<StructuredIndexed> outputs, TypeRange resultTensorTypes,
2828
function_ref<void(ValueRange)> regionBuilder, ArrayRef<Value> otherValues,
2929
ArrayRef<Attribute> otherAttributes) {
30+
OpBuilder &builder = edsc::ScopedContext::getBuilderRef();
31+
3032
// Build maps
3133
SmallVector<SmallVector<AffineExpr, 4>, 4> exprsList;
3234
exprsList.reserve(inputs.size() + outputs.size());
@@ -52,10 +54,13 @@ Operation *mlir::edsc::makeGenericLinalgOp(
5254
resultTensorTypes,
5355
inputValues,
5456
outputValues,
55-
maps,
56-
iteratorStrTypes,
57-
""/*doc*/,
58-
""/*library_call*/)
57+
builder.getAffineMapArrayAttr(maps),
58+
builder.getStrArrayAttr(iteratorStrTypes),
59+
StringAttr() /*doc*/,
60+
StringAttr() /*library_call*/,
61+
ArrayAttr() /*sparse*/
62+
/* TODO: other attributes in op */
63+
)
5964
.getOperation();
6065
// clang-format on
6166

0 commit comments

Comments
 (0)