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

[HGLDD] Emit HW struct and array types #6816

Open
fabianschuiki opened this issue Mar 12, 2024 · 7 comments
Open

[HGLDD] Emit HW struct and array types #6816

fabianschuiki opened this issue Mar 12, 2024 · 7 comments
Labels
Debug good first issue Good for newcomers

Comments

@fabianschuiki
Copy link
Contributor

The EmitHGLDD target can emit the necessary HGLDD JSON bits to encode arrays and structs when it sees dbg.array and dbg.struct operations, but it ignores dbg.variable ops with !hw.array and !hw.struct types. Supporting these native HW types and creating the corresponding JSON structures should be fairly straightforward.

@Nerotos
Copy link

Nerotos commented May 6, 2024

Hello, I would be interested in giving this a shot.

@fabianschuiki
Copy link
Contributor Author

That sounds great! You'll probably want to look at the part of HGLDD emission that handles the StructOp from the debug dialect, and do more or less the same thing for VariableOps that have an !hw.struct type.

@Nerotos
Copy link

Nerotos commented May 22, 2024

Finally had a chance to look into it. Just make sure I understand it correctly, I would have to make a check like this here:

  if (auto variableOp = dyn_cast<debug::VariableOp>(op)){
    // Only tracked structs are considered here
    if (isa<hw::StructType>(variableOp.getValue().getType())){
      auto value= dyn_cast<hw::StructType>(variableOp.getValue());
      auto name = variableOp.getName();
    }
  }

Or am I misunderstanding the VariableOp here?

@Nerotos
Copy link

Nerotos commented May 26, 2024

@fabianschuiki Could you give me a hint how I can access the underlying hw.struct ? Using op.getValue() just returns a general mlir::Value and I can't figure out how to use that to access the fields.

@fabianschuiki
Copy link
Contributor Author

You can use dedicated operations like hw.struct_extract to take that general Value and access a field of the struct. By looking at the struct type, you can get a list of all fields that you might want to extract and look at.

@Nerotos
Copy link

Nerotos commented Jun 9, 2024

@fabianschuiki Thanks! But don't I need a builder to create the hw.struct_extract? At least, that is the only way I know of how you can do this, and there doesn't seem to be one in the EmitHGLDD.cpp file.

@fabianschuiki
Copy link
Contributor Author

Ah that's a great point! Yeah you're right, because we're emitting an HGLDD JSON file here, and the SV file has already been generated, there is no way to generate any extract ops. So in case you see an hw::StructType, you'd have to go through the field names of the struct and fill those into the HGLDD JSON as separate fields, similar to how it's done for the dbg.struct op. But you don't have actual values to point to, but instead have to fill in a hierarchical name for the expressions of each field, something like {"op": ".", "operands": ["someStructValueName", "fieldName"]}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Debug good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants