Skip to content

Conversation

@matthias-springer
Copy link
Member

Add extra assertions to make sure that a value in the conversion value mapping is not overwritten during applySignatureConversion.

Depends on #121644.

Fixes two minor issues in `findOrBuildReplacementValue`:
* Remove a redundant `mapping.map`.
* Map `repl` instead of `value`. We used to overwrite an existing mapping, which may introduce extra materializations.

Note: We generally do not want to overwrite mappings, but create a chain of mappings. There are still a few more places, where a mapping is overwritten. Once those are fixed, I will put an assertion into `ConversionValueMapping::map`.
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Jan 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 4, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

Changes

Add extra assertions to make sure that a value in the conversion value mapping is not overwritten during applySignatureConversion.

Depends on #121644.


Full diff: https://github.com/llvm/llvm-project/pull/121646.diff

1 Files Affected:

  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+8)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 4904d3ce3f8635..3201fad613d294 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1364,6 +1364,14 @@ Block *ConversionPatternRewriterImpl::applySignatureConversion(
   if (hasRewrite<BlockTypeConversionRewrite>(rewrites, block))
     llvm::report_fatal_error("block was already converted");
 #endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
+#ifndef NDEBUG
+  // This check detects the following cases:
+  // * Attempting to convert the same block multiple times.
+  // * Block argument replaced, then attempting to convert the block.
+  for (BlockArgument arg : block->getArguments())
+    assert(mapping.lookupOrNull(arg).empty() &&
+           "cannot convert block whose arguments have been replaced");
+#endif // NDEBUG
 
   OpBuilder::InsertionGuard g(rewriter);
 

@matthias-springer matthias-springer marked this pull request as draft January 4, 2025 13:47
…onversion

Add extra assertions to make sure that a value in the conversion value mapping is not overwritten during `applySignatureConversion`.
@matthias-springer matthias-springer force-pushed the users/matthias-springer/fix_mapping_2 branch from f0edd03 to bf57b8d Compare January 4, 2025 14:06
Base automatically changed from users/matthias-springer/fix_mapping_1 to main January 6, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants