Skip to content
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

FAQ entry about value names #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

FAQ entry about value names #180

wants to merge 1 commit into from

Conversation

ftynse
Copy link
Member

@ftynse ftynse commented Mar 12, 2024

This question gets asked a lot so clarify that names are not part of the IR.

@@ -179,3 +179,7 @@ use in `test.op`), whereas iterating on the "users" of `%0` would yield directly
twice a user of `%0`, it's up to the call site to use a set to unique these if needed.
[The tutorial on use-def chains](https://mlir.llvm.org/docs/Tutorials/UnderstandingTheIRStructure/#traversing-the-def-use-chains) may help understand the details as well.

## How to programmatically obtain the "name" of the SSA value (`%foo`)?

It is impossible in general. The values names are _not part of the IR_ and are only there to make textual representation of the IR easier for humans to read. They are generated by the IR printer on-the-fly and may differ depending on the printer configuration. It is, however, possible to ask the printer to generate specific names by having the operation that defines the value implement [`OpAsmOpInterface`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/OpAsmInterface.td).
Copy link
Member

Choose a reason for hiding this comment

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

But even if you specify a name, when there is a clash, the printer will insert a counter to the end (ex. %foo1) to avoid clashes. So even in that case, it is not possible to always get the name.

Perhaps just allude to the fact that those are not names, but counters, would make it easier to understand.

Copy link
Contributor

@joker-eph joker-eph Mar 12, 2024

Choose a reason for hiding this comment

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

I would use "identifier" instead of "counters" I think (the latter makes me think it’s numerical)

(but maybe "identifier" does not help to express clearly what you're looking for by going away from "name")

Copy link
Member Author

Choose a reason for hiding this comment

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

Identifier implies identity... Rephrased to mention specifically that one can control the prefix.

Copy link
Contributor

Choose a reason for hiding this comment

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

"identity" seems right though: in the textual format it is supposed to be exactly this isn't it?

@@ -179,3 +179,7 @@ use in `test.op`), whereas iterating on the "users" of `%0` would yield directly
twice a user of `%0`, it's up to the call site to use a set to unique these if needed.
[The tutorial on use-def chains](https://mlir.llvm.org/docs/Tutorials/UnderstandingTheIRStructure/#traversing-the-def-use-chains) may help understand the details as well.

## How to programmatically obtain the "name" of the SSA value (`%foo`)?

It is impossible in general. The values names are _not part of the IR_ and are only there to make textual representation of the IR easier for humans to read. They are generated by the IR printer on-the-fly and may differ depending on the printer configuration. It is, however, possible to ask the printer to generate specific names by having the operation that defines the value implement [`OpAsmOpInterface`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/OpAsmInterface.td).
Copy link
Member

Choose a reason for hiding this comment

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

I'd not say its impossible (you can create the AsmState, print, retrieve, create map and well, technically, reuse the AsmState to ensure it is kept, but given the naming is deterministic, if you are doing a non-local variant it should remain the same). That's not the problem, the problem is folks having an expectation that it is consistent across mutations etc. The expectation of these being "attached" names that are somehow fixed is more problematic.

@joker-eph
Copy link
Contributor

Can you mdformat?

This question gets asked a lot so clarify that names are not part of the IR.
@ftynse
Copy link
Member Author

ftynse commented Mar 20, 2024

Github doesn't seem to pick up the changes, here's the branch: main...ftynse-patch-1

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.

None yet

4 participants