@@ -1316,37 +1316,43 @@ Block *ConversionPatternRewriterImpl::applySignatureConversion(
1316
1316
continue ;
1317
1317
}
1318
1318
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.
1319
+ // This is a 1->1+ mapping.
1323
1320
auto replArgs =
1324
1321
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.
1325
1340
Value argMat = buildUnresolvedMaterialization (
1326
1341
MaterializationKind::Argument, newBlock, newBlock->begin (),
1327
1342
origArg.getLoc (), /* inputs=*/ replArgs, origArgType, converter);
1328
1343
mapping.map (origArg, argMat);
1329
1344
appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
1330
1345
1346
+ // Now legalize the type by building a target materialization.
1331
1347
Type legalOutputType;
1332
- if (converter) {
1348
+ if (converter)
1333
1349
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
- }
1344
1350
if (legalOutputType && legalOutputType != origArgType) {
1345
1351
Value targetMat = buildUnresolvedTargetMaterialization (
1346
1352
origArg.getLoc (), argMat, legalOutputType, converter);
1347
1353
mapping.map (argMat, targetMat);
1354
+ appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
1348
1355
}
1349
- appendRewrite<ReplaceBlockArgRewrite>(block, origArg);
1350
1356
}
1351
1357
1352
1358
appendRewrite<BlockTypeConversionRewrite>(newBlock, block, converter);
0 commit comments