[mlir][linalg] Don't drop existing attributes when creating ops

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D108219
This commit is contained in:
Lei Zhang 2021-08-17 15:44:31 -04:00
parent 02e73d4b57
commit 4c15ad2321
2 changed files with 11 additions and 1 deletions

View File

@ -729,6 +729,15 @@ struct DeduplicateGenericOpInputs : public OpRewritePattern<GenericOp> {
outputOperands, rewriter.getAffineMapArrayAttr(newIndexingMaps),
genericOp.iterator_types(), genericOp.docAttr(),
genericOp.library_callAttr());
// Copy over unknown attributes. They might be load bearing for some flow.
ArrayRef<StringRef> odsAttrs = genericOp.getAttributeNames();
for (NamedAttribute kv : genericOp->getAttrs()) {
if (!llvm::is_contained(odsAttrs, kv.first.c_str())) {
newOp->setAttr(kv.first, kv.second);
}
}
rewriter.inlineRegionBefore(genericOp.region(), newOp.region(),
newOp.region().begin());

View File

@ -8,11 +8,12 @@
// CHECK-LABEL: @basic
func @basic(%arg0: tensor<?xf32>) -> tensor<?xf32> {
// CHECK: linalg.generic{{.*}}[#[[$MAP]], #[[$MAP]]]
// CHECK: attrs = {someattr}
// CHECK: ^bb0(%[[BBARG:.*]]: f32, %{{.*}}: f32):
// CHECK: addf %[[BBARG]], %[[BBARG]]
%0 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel"]}
ins(%arg0, %arg0 : tensor<?xf32>, tensor<?xf32>)
outs(%arg0 : tensor<?xf32>) {
outs(%arg0 : tensor<?xf32>) attrs = {someattr} {
^bb0(%arg1: f32, %arg2: f32, %arg3: f32):
%1 = addf %arg1, %arg2 : f32
linalg.yield %1 : f32