8000 [FIRRTL] Introduce notation of discardable annotation by uenoku · Pull Request #5240 · llvm/circt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[FIRRTL] Introduce notation of discardable annotation #5240

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

Closed
wants to merge 3 commits into from

Conversation

uenoku
Copy link
Member
@uenoku uenoku commented May 22, 2023

This PR is separated from: #5226

By default, annotations in the FIRRTL dialect prevent dead code elimination.
However, certain annotations, like OMTracker created by OMReferenceTarget, are considered to have a "weak"
reference to their target. This means that the compiler has the option to delete
the target if it is determined to be dead. To indicate this property, we consider
an annotation with circt.discardable field as discardable, e.g:

%b = firrtl.wire {circt.discardable, class = "freechips.rocketchip.objectmodel.OMIRTracker", id = 0 : i64}

On top of this PR, #5226 changes IMDCE to remove non-local discardable annotations. We can also improve other passes by utilizing discardable annotations.

@uenoku uenoku requested review from seldridge and darthscsi May 22, 2023 15:32
@@ -1495,6 +1495,14 @@ Example:
}
```

## Discardable Annotaions

By default, annotations in the FIRRTL dialect prevent dead code elimination (DCE).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This is specific to dead-code elim in particular. Does this literally only impact whether a value is considered "live" (if the annotation pointing to it is also live)? That does seem more straightforward re:scope.

"Discardable" suggests that it could be dropped, perhaps for no reason (?), but certainly by various optimizations such as canonicalizers. Is this right?

Are there requirements to preserve this /if/ the target is preserved in some sense (something something notions of equality/identity)? For example, could we CSE a value with this annotation, or discard it during a transform if inconvenient to preserve? Where in the spectrum between "if this exists (asterisks on what precisely that means), the annotation will be on it I promise" vs "this is like a namehint, we do what we can but ultimately who can say and if you need this for correctness do it a different way"?

Targeting DCE specifically mostly avoids these questions, although it seems like defining the semantics this way is very specific to our implementation and notion of "DCE".

Do annotations block, e.g., IMCP, generally (if not, do discardable annotations block IMCP?)? Presumably if we can DCE this we can also constant-prop through it.

Copy link
Member Author

Choose a reason for hiding this comment

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

"Discardable" suggests that it could be dropped, perhaps for no reason (?), but certainly by various optimizations such as canonicalizers. Is this right?

Yes, my intention was canonicalizer or folder can also drop the annotation if there is no user of the annotation target.\

For example, could we CSE a value with this annotation, or discard it during a transform if inconvenient to preserve?

I want to prohibit these operations.

Where in the spectrum between "if this exists (asterisks on what precisely that means), the annotation will be on it I promise" vs "this is like a namehint, we do what we can but ultimately who can say and if you need this for correctness do it a different way"?

The former semantics is exactly what I want to represent.

Do annotations block, e.g., IMCP, generally (if not, do discardable annotations block IMCP?)? Presumably if we can DCE this we can also constant-prop through it.

Annotations usually don't block IMCP. Only dontTouch annotation blocks the IMCP.

Copy link
Contributor
@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for working to find good grounding for this behavior re:annotations!!

Little uncertain about this, or how it might extend beyond "how does this annotation impact our implementation of DCE" hopefully can sort that out.

@uenoku uenoku closed this Oct 21, 2024
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
0