Skip to content

[ESI] Fix memory leak in wrap operation folders#9458

Merged
teqdruid merged 1 commit intomainfrom
teqdruid/fifo-wrap
Jan 15, 2026
Merged

[ESI] Fix memory leak in wrap operation folders#9458
teqdruid merged 1 commit intomainfrom
teqdruid/fifo-wrap

Conversation

@teqdruid
Copy link
Contributor

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

Testing:

The memory leak reported in #9367 should no longer occur. The test case from the issue should pass without leaking memory.

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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 from WrapValidReadyOp and WrapFIFOOp that violated MLIR's design by creating operations
  • Converted the logic to canonicalize() methods with proper PatternRewriter usage
  • Simplified to erase unused operations instead of creating NullSourceOp instances

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

@teqdruid teqdruid merged commit 44ad4f2 into main Jan 15, 2026
12 checks passed
@teqdruid teqdruid deleted the teqdruid/fifo-wrap branch January 15, 2026 23:21
@teqdruid teqdruid added the ESI label Jan 15, 2026
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.

Memory leak in HW Aggregate to Comb conversion

2 participants