[Mlir-commits] [mlir] [mlir][Transforms] Dialect conversion: Add flag to dump materialization kind (PR #119532)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 11 01:57:36 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-core
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
Add a debugging flag to the dialect conversion to dump the materialization kind. This flag is meant to help users to migrate 1:1 conversion patterns to 1:N conversion patterns. (To understand what kind of materializations are created in which place.)
---
Full diff: https://github.com/llvm/llvm-project/pull/119532.diff
1 Files Affected:
- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+9-1)
``````````diff
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index cedf645e2985da..300805ae99b2be 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -29,6 +29,12 @@ using namespace mlir::detail;
#define DEBUG_TYPE "dialect-conversion"
+/// Debugging flag. If set to "true", the materialization kind is attached as
+/// an attribute to builtin.unrealized_conversion_cast ops. This flag takes
+/// effect only if ConversionConfig::buildMaterialization = false. (Otherwise,
+/// the annotated ops are replaced with materializations.)
+static const bool kDumpMaterializationKind = false;
+
/// A utility function to log a successful result for the given reason.
template <typename... Args>
static void logSuccess(llvm::ScopedPrinter &os, StringRef fmt, Args &&...args) {
@@ -650,7 +656,7 @@ class CreateOperationRewrite : public OperationRewrite {
};
/// The type of materialization.
-enum MaterializationKind {
+enum MaterializationKind : int8_t {
/// This materialization materializes a conversion for an illegal block
/// argument type, to the original one.
Argument,
@@ -1417,6 +1423,8 @@ ValueRange ConversionPatternRewriterImpl::buildUnresolvedMaterialization(
builder.setInsertionPoint(ip.getBlock(), ip.getPoint());
auto convertOp =
builder.create<UnrealizedConversionCastOp>(loc, outputTypes, inputs);
+ if (kDumpMaterializationKind)
+ convertOp->setAttr("kind", builder.getI32IntegerAttr(kind));
if (valueToMap) {
assert(outputTypes.size() == 1 && "1:N mapping is not supported");
mapping.map(valueToMap, convertOp.getResult(0));
``````````
</details>
https://github.com/llvm/llvm-project/pull/119532
More information about the Mlir-commits
mailing list