[llvm-branch-commits] [mlir] [mlir][Transforms] Detect mapping overwrites during block signature conversion (PR #121646)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 4 04:56:21 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

<details>
<summary>Changes</summary>

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
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);
 

``````````

</details>


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


More information about the llvm-branch-commits mailing list