Skip to content

Conversation

maerhart
Copy link
Member

@maerhart maerhart commented Jul 1, 2025

No description provided.

@maerhart maerhart added the RTG Involving the `rtg` dialect label Jul 1, 2025
@maerhart maerhart force-pushed the maerhart-rtg-validateop branch from 63999cb to f3e2283 Compare July 1, 2025 13:04
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

LGTM! I don't fully grok yet how this will be used in practice, but having an op as a hook to potentially substitute actual values from a simulation run or some other analysis sounds like a useful thing 👍


let arguments = (ins AnyType:$ref,
AnyType:$defaultValue,
OptionalAttr<StrAttr>:$id);
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we can use distinct attr for id if the uniqueness matters?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I'm not sure if there's really a benefit in doing so. I use this attribute to insert an assembly label that includes this ID which an ISA simulator can use to print a mapping for the form <id>=<value> to a file. In a second compilation run an can then parse this file and match the IDs with the validate ops to hardcode the simulated value. Between those two compilation runs I just store the IR in the state before lowering the validate ops to labels in a file. Using the distinct attribute would unique things while in in-memory representation, but it doesn't seem to really help me generating a unique string that I can give the ISA simulator.

In a compilation flow where the simulator can be run within a compiler pass and doesn't need the two separate compilation runs, we don't need an ID at all.

Furthermore, during elaboration a validate op may be duplicated (e.g. because it's in an scf.for body). In that case, we'd have to create and assign a new distinct attr. I currently keep the IDs set to nullopt until just before lowering the validate ops and do the unique name generation there.

I think there would be a benefit in using it if multiple validate ops are supposed to refer to the same ID and the user is allowed to provide a prefix/suffix for the ID. Which I'm currently not doing.

Let me know if I'm missing something.

@maerhart maerhart merged commit 89cacf0 into main Jul 2, 2025
7 checks passed
@maerhart maerhart deleted the maerhart-rtg-validateop branch July 2, 2025 08:19
TaoBi22 pushed a commit to TaoBi22/circt that referenced this pull request Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RTG Involving the `rtg` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants