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

[FIRRTL] Generic intrinsic parsing/emitter support #6897

Merged

Conversation

dtzSiFive
Copy link
Contributor

Add parsing and emitter support for FIRRTL intrinsic.

Refactor parameter parsing on (ext/int)modules as these use same syntax.

Snippet from parse-basic.fir without FileCheck directives:

circuit GenericIntrinsics:
  public module GenericIntrinsics:
    input clock : Clock
    input data : UInt<32>
    input c : UInt<1>

    ; Statements
    intrinsic(circt_verif_assert, c)
    intrinsic(circt_fpga_probe, data, clock)

    ; Expressions
    node n = intrinsic(circt_plusargs_value<FORMAT = "foo"> : { found : UInt<1>, result : UInt<5> })
    node n2 = intrinsic(circt_plusargs_test<FORMAT = "bar"> : UInt<3>)

    ; Statement with unused return value.
    intrinsic(circt_clock_gate : Clock, clock, c)

    ; Nesting, statement and expression forms.
    intrinsic(circt_verif_assert, intrinsic(circt_isX: UInt<1>, data))

And somewhat similarly from the emit-basic test:

  public module GenericIntrinsic :
    input clk : Clock
    input c : UInt<1>
    output s : UInt<32>
    output io1 : UInt<1>
    output io2 : UInt<1>
    output io3 : UInt<1>
    output io4 : UInt<5>

    connect s, intrinsic(circt_sizeof : UInt<32>, clk)
    connect io1, intrinsic(circt_isX : UInt<1>, clk)
    connect io2, intrinsic(circt_plusargs_test<FORMAT = "foo"> : UInt<1>)
    intrinsic(circt_clock_gate : Clock, clk, c)
    node _gen_int
      = intrinsic(circt_plusargs_value<FORMAT = "foo">
                    : { found : UInt<1>, result : UInt<5> })
    connect io3, _gen_int.found
    connect io4, _gen_int.result
    intrinsic(circt_verif_assert, intrinsic(circt_isX : UInt<1>, c))
    node _gen_int_0 = intrinsic(circt_isX : UInt<1>, c)
    intrinsic(circt_verif_assert, intrinsic(circt_isX : UInt<1>, _gen_int_0))

@fabianschuiki fabianschuiki changed the title [FIRRTL] Generic intrnsic parsing/emitter support. [FIRRTL] Generic intrinsic parsing/emitter support Apr 4, 2024
@dtzSiFive dtzSiFive force-pushed the feature/generic-intrinsic-op-parser-emitter branch from 7aa2c4c to 7482d71 Compare April 4, 2024 18:17
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.

Nice refactoring of the parameter parsing! Looks good to me. Gonna let others comment on the syntax.

lib/Dialect/FIRRTL/Export/FIREmitter.cpp Show resolved Hide resolved
Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

I took a quick look through it, and the implementation looks good to me. I'm happy to approve as-is, not sure if anyone else wants to weigh in or have a deeper design review. To me, the fact that the parsing logic is relatively straightforward and not going through crazy gyrations means the syntax is effective.

Allows use of "intrinsic" as an identifier when not followed
by the left-paren, e.g. `connect intrinsic.i, i`.
@dtzSiFive
Copy link
Contributor Author

Added commit moving to the left-paren keyword specifically so that this is safe w.r.t. backwards-compatibility with designs that parse today as it only changes what happens when someone writes intrinsic( which is never legal presently.

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.

LGTM

lib/Dialect/FIRRTL/Import/FIRParser.cpp Outdated Show resolved Hide resolved
Co-authored-by: Robert Young <rwy0717@gmail.com>
@dtzSiFive
Copy link
Contributor Author

Landing, thanks for the reviews/feedback all!

Syntax is not official, but let's keep this train moving and modify as needed 👍

@dtzSiFive dtzSiFive merged commit d1a2f5e into llvm:main Apr 8, 2024
4 checks passed
@dtzSiFive dtzSiFive deleted the feature/generic-intrinsic-op-parser-emitter branch April 8, 2024 16:42
cepheus69 pushed a commit to cepheus69/circt that referenced this pull request Apr 22, 2024
Add parsing and emitter support for FIRRTL intrinsic.

Refactor parameter parsing on (ext/int)modules as these use same syntax.

See tests and PR for more details.

Thanks for the grammar fix, Rob!

Co-authored-by: Robert Young <rwy0717@gmail.com>
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

5 participants