Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jiahanxie353
Copy link
Contributor

This patch adds a new oldMemRefVals field to keep track of the original memref values that should be erased, as opposed to the old approach that derives oldMemRefVals simply from memoryToBanks map:

DenseSet<Value> oldMemRefVals;

The issue with the original approach is that some keys in the memoryToBanks map might become dangling references because they are replaced:

rewriter.replaceOp(loadOp, switchOp.getResult(0));

We add loadOp.memref() to oldMemRefVals only when the value is a BlockArgument because only the BlockArgument will remain in the cleanUpOldMemRefs function; and the values that are not BlockArgument will all gets replaced and naturally no longer exists, thus not requiring any additional clean-ups.

auto defaultValue = rewriter.create<arith::ConstantOp>(loc, zeroAttr);
rewriter.create<scf::YieldOp>(loc, defaultValue.getResult());

if (isa<BlockArgument>(loadOp.getMemref()))
Copy link
Member

Choose a reason for hiding this comment

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

We add loadOp.memref() to oldMemRefVals only when the value is a BlockArgument because only the BlockArgument will remain in the cleanUpOldMemRefs function; and the values that are not BlockArgument will all gets replaced and naturally no longer exists, thus not requiring any additional clean-ups.

It probably would be good to add this as a (bit more concise) comment here. It isn't clear otherwise to someone reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just added!

Copy link
Member

@cgyurgyik cgyurgyik left a comment

Choose a reason for hiding this comment

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

I've added some suggested changes, do with them as you please. LGTM

…sed because they will become dangling reference if their load operations are replaced
…tement; add more comments regarding old memref values
@jiahanxie353
Copy link
Contributor Author

I've added some suggested changes, do with them as you please. LGTM

committing them, thanks for the review!

@jiahanxie353 jiahanxie353 merged commit 1c5826f into llvm:main Jan 9, 2025
4 checks passed
TaoBi22 pushed a commit to TaoBi22/circt that referenced this pull request Jul 17, 2025
…ues that need to be cleaned up after memory banking is complete (llvm#8039)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants