[ESI] Fix memory leak in wrap operation folders#9458
Merged
Conversation
Fixes #9367 The WrapValidReadyOp and WrapFIFOOp fold() methods were creating new operations (NullSourceOp), which violates MLIR's design principle that fold methods must never create operations. This caused memory leaks as the operations weren't properly tracked by the rewriter. Changes: - Removed fold() methods from WrapValidReadyOp and WrapFIFOOp - Moved no-users handling to canonicalize() methods which can properly create operations using PatternRewriter - Simplified canonicalizers to just erase unused operations instead of creating NullSourceOp - Added handling for edge case where channel has no consumers but ready/rden signals do have consumers - drive them to appropriate constants (true for ready, false for rden) - Removed hasFolder traits from operation definitions in tablegen
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak in ESI wrap operations by removing fold() methods that incorrectly created operations. The changes convert the folding logic to proper canonicalization patterns that use PatternRewriter.
Changes:
- Removed
fold()methods fromWrapValidReadyOpandWrapFIFOOpthat violated MLIR's design by creating operations - Converted the logic to
canonicalize()methods with properPatternRewriterusage - Simplified to erase unused operations instead of creating
NullSourceOpinstances
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/Dialect/ESI/ESIFolds.cpp | Replaced fold() methods with canonicalize() implementations for WrapValidReadyOp and WrapFIFOOp |
| include/circt/Dialect/ESI/ESIChannels.td | Removed hasFolder traits and added/ensured hasCanonicalizeMethod traits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9367
The
WrapValidReadyOpandWrapFIFOOpfold()methods were creating new operations (NullSourceOp), which violates MLIR's design principle that fold methods must never create operations. This caused memory leaks as the operations weren't properly tracked by the rewriter.Changes:
fold()methods fromWrapValidReadyOpandWrapFIFOOpcanonicalize()methods which can properly create operations usingPatternRewriterNullSourceOphasFoldertraits from operation definitions in tablegenTesting:
The memory leak reported in #9367 should no longer occur. The test case from the issue should pass without leaking memory.