Skip to content

Commit dd88f99

Browse files
committed
[mlir][Transforms] Dialect conversion: add missing argument
materialization. When replacing a block argument, previously to #117513, we would automatically insert a N->1 argument materialization. After #117513, this is no longer the case for 1->1 mappings. As a result, no materialization is added until `ReplaceBlockArgRewrite` is committed, where `findOrBuildReplacementValue` inserts a source materialization. The switch from an argument materialization to a source materialization causes legalization to fail.
1 parent ac8bb73 commit dd88f99

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,12 +1375,18 @@ Block *ConversionPatternRewriterImpl::applySignatureConversion(
13751375
// used as a replacement.
13761376
auto replArgs =
13771377
newBlock->getArguments().slice(inputMap->inputNo, inputMap->size);
1378+
auto insertPoint = OpBuilder::InsertPoint(newBlock, newBlock->begin());
13781379
if (replArgs.size() == 1) {
1379-
mapping.map(origArg, replArgs.front());
1380+
// We need an argument materialization to replace the block argument.
1381+
Value argMat = buildUnresolvedMaterialization(
1382+
MaterializationKind::Argument, insertPoint, origArg.getLoc(),
1383+
/*valueToMap=*/origArg, /*inputs=*/replArgs,
1384+
/*outputType=*/origArg.getType(), /*originalType=*/Type(), converter);
1385+
mapping.map(origArg, argMat);
13801386
} else {
1381-
insertNTo1Materialization(
1382-
OpBuilder::InsertPoint(newBlock, newBlock->begin()), origArg.getLoc(),
1383-
/*replacements=*/replArgs, /*outputValue=*/origArg, converter);
1387+
insertNTo1Materialization(insertPoint, origArg.getLoc(),
1388+
/*replacements=*/replArgs,
1389+
/*originalValue=*/origArg, converter);
13841390
}
13851391
appendRewrite<ReplaceBlockArgRewrite>(block, origArg, converter);
13861392
}

0 commit comments

Comments
 (0)