-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Matthias Springer (matthias-springer) ChangesAdd 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:
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));
|
| if (kDumpMaterializationKind) | ||
| convertOp->setAttr("kind", builder.getI32IntegerAttr(kind)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
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.)