-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][Transforms] Dialect conversion: Add flag to dump materialization kind #119532
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
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));
|
ad27f5f to
6eb92b1
Compare
|
I forgot about this PR, but I think it's still useful. Can you take another look? |
6eb92b1 to
0bf14af
Compare
0bf14af to
3dc17c3
Compare
Add a debugging flag to the dialect conversion to dump the materialization kind. This flag is useful to find out whether a missing materialization rule is for source or target materializations.
Also add missing test coverage for the
buildMaterializationsflag.