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

[Moore] Drop named_constant op in favor of dbg.variable #7624

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

fabianschuiki
Copy link
Contributor

Remove the NamedConstantOp and replace its uses with VariableOp from the debug dialect.

The op was originally added to track the value of constant parameters, localparams, and specparams in the IR. In ImportVerilog, such parameters would generate a corresponding named_constant op and all references to the parameter by name would be replaced with the named_constant's result.

This doesn't really work well for parameters defined outside a module, such as in packages or at the root of the Verilog source file. (Modules are isolated from above, preventing the use of named_constants from outside the module.) Therefore expressions would generally fall back to materializing constants directly where they were used.

Since the named constant ops are only there to track a constant value in the IR for the user's debugging convenience, using the debug dialect directly feels a lot more appropriate.

Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

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

LGTM 🎉! It's so perfect if we can implement a case like:

parameter P = 32;
module Foo;
  localparam  LP = P;
endmodule

@fabianschuiki
Copy link
Contributor Author

@hailongSun2000 circt-verilog --parse-only -g produces this:

module {
  %0 = moore.constant 32 : l32
  dbg.variable "P", %0 : !moore.l32
  moore.module @Foo() {
    %1 = moore.constant 32 : l32
    dbg.variable "LP", %1 : !moore.l32
    moore.output
  }
}

😃

@hailongSun2000
Copy link
Member

So nice!

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

Awesome that Debug works well here!

Remove the `NamedConstantOp` and replace its uses with `VariableOp` from
the debug dialect.

The op was originally added to track the value of constant parameters,
localparams, and specparams in the IR. In ImportVerilog, such parameters
would generate a corresponding `named_constant` op and all references to
the parameter by name would be replaced with the `named_constant`'s
result.

This doesn't really work well for parameters defined outside a module,
such as in packages or at the root of the Verilog source file. (Modules
are isolated from above, preventing the use of `named_constant`s from
outside the module.) Therefore expressions would generally fall back to
materializing constants directly where they were used.

Since the named constant ops are only there to track a constant value in
the IR for the user's debugging convenience, using the debug dialect
directly feels a lot more appropriate.
@fabianschuiki fabianschuiki force-pushed the fschuiki/moore-remove-named-constant branch from 18c8c5c to 1995680 Compare September 25, 2024 16:04
@fabianschuiki fabianschuiki merged commit 687f7fb into main Sep 25, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/moore-remove-named-constant branch September 25, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants