-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][Transforms] Dialect Conversion: No target mat. for 1:N replacement #117513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -849,8 +849,7 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener { | |||
/// function will be deleted when full 1:N support has been added. | ||||
/// | ||||
/// This function inserts an argument materialization back to the original | ||||
/// type, followed by a target materialization to the legalized type (if | ||||
/// applicable). | ||||
/// type. | ||||
void insertNTo1Materialization(OpBuilder::InsertPoint ip, Location loc, | ||||
ValueRange replacements, Value originalValue, | ||||
const TypeConverter *converter); | ||||
|
@@ -1376,9 +1375,13 @@ Block *ConversionPatternRewriterImpl::applySignatureConversion( | |||
// used as a replacement. | ||||
auto replArgs = | ||||
newBlock->getArguments().slice(inputMap->inputNo, inputMap->size); | ||||
insertNTo1Materialization( | ||||
OpBuilder::InsertPoint(newBlock, newBlock->begin()), origArg.getLoc(), | ||||
/*replacements=*/replArgs, /*outputValue=*/origArg, converter); | ||||
if (replArgs.size() == 1) { | ||||
mapping.map(origArg, replArgs.front()); | ||||
} else { | ||||
insertNTo1Materialization( | ||||
OpBuilder::InsertPoint(newBlock, newBlock->begin()), origArg.getLoc(), | ||||
/*replacements=*/replArgs, /*outputValue=*/origArg, converter); | ||||
} | ||||
appendRewrite<ReplaceBlockArgRewrite>(block, origArg, converter); | ||||
} | ||||
|
||||
|
@@ -1437,36 +1440,12 @@ void ConversionPatternRewriterImpl::insertNTo1Materialization( | |||
// Insert argument materialization back to the original type. | ||||
Type originalType = originalValue.getType(); | ||||
UnrealizedConversionCastOp argCastOp; | ||||
Value argMat = buildUnresolvedMaterialization( | ||||
buildUnresolvedMaterialization( | ||||
MaterializationKind::Argument, ip, loc, /*valueToMap=*/originalValue, | ||||
/*inputs=*/replacements, originalType, /*originalType=*/Type(), converter, | ||||
&argCastOp); | ||||
/*inputs=*/replacements, originalType, | ||||
/*originalType=*/Type(), converter, &argCastOp); | ||||
if (argCastOp) | ||||
nTo1TempMaterializations.insert(argCastOp); | ||||
|
||||
// Insert target materialization to the legalized type. | ||||
Type legalOutputType; | ||||
if (converter) { | ||||
legalOutputType = converter->convertType(originalType); | ||||
} else if (replacements.size() == 1) { | ||||
// When there is no type converter, assume that the replacement value | ||||
// types are legal. This is reasonable to assume because they were | ||||
// specified by the user. | ||||
// FIXME: This won't work for 1->N conversions because multiple output | ||||
// types are not supported in parts of the dialect conversion. In such a | ||||
// case, we currently use the original value type. | ||||
legalOutputType = replacements[0].getType(); | ||||
} | ||||
if (legalOutputType && legalOutputType != originalType) { | ||||
UnrealizedConversionCastOp targetCastOp; | ||||
buildUnresolvedMaterialization( | ||||
MaterializationKind::Target, computeInsertPoint(argMat), loc, | ||||
/*valueToMap=*/argMat, /*inputs=*/argMat, | ||||
/*outputType=*/legalOutputType, /*originalType=*/originalType, | ||||
converter, &targetCastOp); | ||||
if (targetCastOp) | ||||
nTo1TempMaterializations.insert(targetCastOp); | ||||
} | ||||
} | ||||
|
||||
Value ConversionPatternRewriterImpl::findOrBuildReplacementValue( | ||||
|
@@ -2864,6 +2843,9 @@ void TypeConverter::SignatureConversion::remapInput(unsigned origInputNo, | |||
|
||||
LogicalResult TypeConverter::convertType(Type t, | ||||
SmallVectorImpl<Type> &results) const { | ||||
assert(this && "expected non-null type converter"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This assert only protects against a case that is already in UB as far as C++ is concerned and would e.g. get optimized out in release builds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is not really needed, but I spent an hour debugging patterns that run without type converters (running in debug mode). (Can also be helpful for finding bugs in the dialect conversion framework.) When |
||||
assert(t && "expected non-null type"); | ||||
|
||||
{ | ||||
std::shared_lock<decltype(cacheMutex)> cacheReadLock(cacheMutex, | ||||
std::defer_lock); | ||||
|
Uh oh!
There was an error while loading. Please reload this page.