Skip to content

[mlir] Fix debug output for passes that modify top-level operation. #80022

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

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

Jezurko
Copy link
Contributor

@Jezurko Jezurko commented Jan 30, 2024

Make it so that when the top-level (root) operation itself is being modified, it is also used as the root for debug output in PatternApplicator.
Fix #80021

Make it so that when the top-level (root) operation itself is being
modified, it is also used as the root for debug output in
PatternApplicator.
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the mlir label Jan 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2024

@llvm/pr-subscribers-mlir

Author: Robert Konicar (Jezurko)

Changes

Make it so that when the top-level (root) operation itself is being modified, it is also used as the root for debug output in PatternApplicator.
Fix #80021


Full diff: https://github.com/llvm/llvm-project/pull/80022.diff

1 Files Affected:

  • (modified) mlir/lib/Rewrite/PatternApplicator.cpp (+3-1)
diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index 0064eb84aba84..686aef2e68e11 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -40,7 +40,9 @@ static void logImpossibleToMatch(const Pattern &pattern) {
 
 /// Log IR after pattern application.
 static Operation *getDumpRootOp(Operation *op) {
-  return op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
+  return op->hasTrait<mlir::OpTrait::IsIsolatedFromAbove>()
+             ? op
+             : op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
 }
 static void logSucessfulPatternApplication(Operation *op) {
   llvm::dbgs() << "// *** IR Dump After Pattern Application ***\n";

Comment on lines 43 to 45
return op->hasTrait<mlir::OpTrait::IsIsolatedFromAbove>()
? op
: op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
Copy link
Collaborator

@joker-eph joker-eph Jan 30, 2024

Choose a reason for hiding this comment

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

If you wish to fix the nullptr, I would likely write it as:

Suggested change
return op->hasTrait<mlir::OpTrait::IsIsolatedFromAbove>()
? op
: op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
Operation *isolatedParent = op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
if (isolatedParent) return isolatedParent;
return op;

(That would preserve the current behavior in general)

Copy link
Member

Choose a reason for hiding this comment

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

This change makes sense to me. If there is no isolated-from-above parent, we are modifying the top-level module and we should dump it directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this is better. I have pushed an update

@joker-eph joker-eph merged commit 78e0cca into llvm:main Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MLIR] Debugging output for passes dereferences nullptr in some cases
4 participants