diff options
author | Matthias Springer <me@m-sp.org> | 2024-02-23 17:26:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-23 17:26:39 +0100 |
commit | 5840aa95e3c2d93f400e638e7cbf167a693c75f5 (patch) | |
tree | 8858aba54511911c7d2e4ab031c22dd2bd033a4e | |
parent | 55bc0488af077acb47be70542718d1bc17f3de4f (diff) |
[mlir][Transforms] Fix crash in dialect conversion (#82783)
This is a follow-up to #82333. It is possible that the target block of a
`BlockTypeConversionRewrite` is detached, so the `MLIRContext` cannot be
taken from the block.
-rw-r--r-- | mlir/lib/Transforms/Utils/DialectConversion.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp index d015bd529012..857b601acbc3 100644 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -1034,15 +1034,15 @@ void BlockTypeConversionRewrite::rollback() { LogicalResult BlockTypeConversionRewrite::materializeLiveConversions( function_ref<Operation *(Value)> findLiveUser) { - auto builder = OpBuilder::atBlockBegin(block, /*listener=*/&rewriterImpl); - // Process the remapping for each of the original arguments. for (auto it : llvm::enumerate(origBlock->getArguments())) { - OpBuilder::InsertionGuard g(builder); + BlockArgument origArg = it.value(); + // Note: `block` may be detached, so OpBuilder::atBlockBegin cannot be used. + OpBuilder builder(it.value().getContext(), /*listener=*/&rewriterImpl); + builder.setInsertionPointToStart(block); // If the type of this argument changed and the argument is still live, we // need to materialize a conversion. - BlockArgument origArg = it.value(); if (rewriterImpl.mapping.lookupOrNull(origArg, origArg.getType())) continue; Operation *liveUser = findLiveUser(origArg); @@ -1321,7 +1321,7 @@ LogicalResult ConversionPatternRewriterImpl::convertNonEntryRegionTypes( Block *ConversionPatternRewriterImpl::applySignatureConversion( Block *block, const TypeConverter *converter, TypeConverter::SignatureConversion &signatureConversion) { - MLIRContext *ctx = block->getParentOp()->getContext(); + MLIRContext *ctx = eraseRewriter.getContext(); // If no arguments are being changed or added, there is nothing to do. unsigned origArgCount = block->getNumArguments(); |