Skip to content
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

[mlir][Transforms] Dialect conversion: Add flag to dump materialization kind #119532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthias-springer
Copy link
Member

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

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Dec 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

Changes

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

Comment on lines +1426 to +1427
if (kDumpMaterializationKind)
convertOp->setAttr("kind", builder.getI32IntegerAttr(kind));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a string representation here?

/// 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the only reason for this being a constant that needs to be modified is not to bloat ConversionConfig or is there some other motivation?

Seems fine to me either way, but if there is a future place where it is more suitable a TODO might be useful

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