Skip to content

Commit 17ba4f4

Browse files
committed
Revert "[mlir][Transforms] Dialect conversion: Skip materializations when running without converter (#101318)"
This reverts commit 2aa96fc. This was merged without a test. Also it seems it was only fixing an issue for users which used a particular workaround that is not actually needed anymore (skipping UnrealizedConversionCast operands).
1 parent 7088a5e commit 17ba4f4

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

+16-22
Original file line numberDiff line numberDiff line change
@@ -1316,43 +1316,37 @@ Block *ConversionPatternRewriterImpl::applySignatureConversion(
13161316
continue;
13171317
}
13181318

1319-
// This is a 1->1+ mapping.
1319+
// This is a 1->1+ mapping. 1->N mappings are not fully supported in the
1320+
// dialect conversion. Therefore, we need an argument materialization to
1321+
// turn the replacement block arguments into a single SSA value that can be
1322+
// used as a replacement.
13201323
auto replArgs =
13211324
newBlock->getArguments().slice(inputMap->inputNo, inputMap->size);
1322-
1323-
// When there is no type converter, assume that the new block argument
1324-
// types are legal. This is reasonable to assume because they were
1325-
// specified by the user.
1326-
// FIXME: This won't work for 1->N conversions because multiple output
1327-
// types are not supported in parts of the dialect conversion. In such a
1328-
// case, we currently use the original block argument type (produced by
1329-
// the argument materialization).
1330-
if (!converter && replArgs.size() == 1) {
1331-
mapping.map(origArg, replArgs[0]);
1332-
appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
1333-
continue;
1334-
}
1335-
1336-
// 1->N mappings are not fully supported in the dialect conversion.
1337-
// Therefore, we need an argument materialization to turn the replacement
1338-
// block arguments into a single SSA value (of the original type) that can
1339-
// be used as a replacement.
13401325
Value argMat = buildUnresolvedMaterialization(
13411326
MaterializationKind::Argument, newBlock, newBlock->begin(),
13421327
origArg.getLoc(), /*inputs=*/replArgs, origArgType, converter);
13431328
mapping.map(origArg, argMat);
13441329
appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
13451330

1346-
// Now legalize the type by building a target materialization.
13471331
Type legalOutputType;
1348-
if (converter)
1332+
if (converter) {
13491333
legalOutputType = converter->convertType(origArgType);
1334+
} else if (replArgs.size() == 1) {
1335+
// When there is no type converter, assume that the new block argument
1336+
// types are legal. This is reasonable to assume because they were
1337+
// specified by the user.
1338+
// FIXME: This won't work for 1->N conversions because multiple output
1339+
// types are not supported in parts of the dialect conversion. In such a
1340+
// case, we currently use the original block argument type (produced by
1341+
// the argument materialization).
1342+
legalOutputType = replArgs[0].getType();
1343+
}
13501344
if (legalOutputType && legalOutputType != origArgType) {
13511345
Value targetMat = buildUnresolvedTargetMaterialization(
13521346
origArg.getLoc(), argMat, legalOutputType, converter);
13531347
mapping.map(argMat, targetMat);
1354-
appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
13551348
}
1349+
appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
13561350
}
13571351

13581352
appendRewrite<BlockTypeConversionRewrite>(newBlock, block, converter);

mlir/test/Transforms/test-legalize-type-conversion.mlir

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ func.func @test_block_argument_not_converted() {
103103
// Make sure argument type changes aren't implicitly forwarded.
104104
func.func @test_signature_conversion_no_converter() {
105105
"test.signature_conversion_no_converter"() ({
106-
// expected-error@below {{failed to materialize conversion for block argument #0 that remained live after conversion, type was 'f32'}}
106+
// expected-error@below {{failed to legalize unresolved materialization from ('f64') to 'f32' that remained live after conversion}}
107107
^bb0(%arg0: f32):
108-
// expected-note@below{{see existing live user here}}
109108
"test.type_consumer"(%arg0) : (f32) -> ()
110109
"test.return"(%arg0) : (f32) -> ()
111110
}) : () -> ()

0 commit comments

Comments
 (0)