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][LowerXMR] Child U-Turn #4692

Closed
dtzSiFive opened this issue Feb 21, 2023 · 2 comments
Closed

[FIRRTL][LowerXMR] Child U-Turn #4692

dtzSiFive opened this issue Feb 21, 2023 · 2 comments
Labels
FIRRTL Involving the `firrtl` dialect

Comments

@dtzSiFive
Copy link
Contributor

Not priority presently, but if we want something like input references (arguably not, marking wontfix for now) the following should work:

ref-child-uturn.mlir:

firrtl.circuit "RefUTurnChild" {
  firrtl.module private @UTurnChild(in %in: !firrtl.ref<uint<2>>, out %out: !firrtl.ref<uint<2>>) {
    firrtl.strictconnect %out, %in : !firrtl.ref<uint<2>>
  }

  firrtl.module @RefUTurnChild(in %x : !firrtl.uint<2>, out %y : !firrtl.uint<2>) {
    %sub_in, %sub_out = firrtl.instance sub @UTurnChild(in in: !firrtl.ref<uint<2>>, out out: !firrtl.ref<uint<2>>)

    %x_ref = firrtl.ref.send %x : !firrtl.uint<2>
    firrtl.strictconnect %sub_in, %x_ref : !firrtl.ref<uint<2>>

    %val = firrtl.ref.resolve %sub_out : !firrtl.ref<uint<2>>
    firrtl.strictconnect %y, %val : !firrtl.uint<2>
  }
}

Which currently produces an error:

ref-child-uturn.mlir:2:3: error: reference dataflow cannot be traced back to the remote read op for module port 'out'
  firrtl.module private @UTurnChild(in %in: !firrtl.ref<uint<2>>, out %out: !firrtl.ref<uint<2>>) {
  ^
ref-child-uturn.mlir:2:3: note: see current operation: 
"firrtl.module"() ({
^bb0(%arg0: !firrtl.ref<uint<2>>, %arg1: !firrtl.ref<uint<2>>):
  "firrtl.strictconnect"(%arg1, %arg0) : (!firrtl.ref<uint<2>>, !firrtl.ref<uint<2>>) -> ()
}) {annotations = [], parameters = [], portAnnotations = [[], []], portDirections = -2 : i2, portLocations = [loc("ref-child-uturn.mlir":2:40), loc("ref-child-uturn.mlir":2:71)], portNames = ["in", "out"], portSyms = [], portTypes = [!firrtl.ref<uint<2>>, !firrtl.ref<uint<2>>], sym_name = "UTurnChild", sym_visibility = "private"} : () -> ()

Note that the same circuit is valid if the child module is marked for inlining:

firrtl.circuit "RefUTurnChild" {
  firrtl.module private @UTurnChild(in %in: !firrtl.ref<uint<2>>, out %out: !firrtl.ref<uint<2>>)
    attributes {annotations = [{class = "firrtl.passes.InlineAnnotation"}]}
  { firrtl.strictconnect %out, %in : !firrtl.ref<uint<2>> }

  firrtl.module @RefUTurnChild(in %x : !firrtl.uint<2>, out %y : !firrtl.uint<2>) {
    %sub_in, %sub_out = firrtl.instance sub @UTurnChild(in in: !firrtl.ref<uint<2>>, out out: !firrtl.ref<uint<2>>)

    %x_ref = firrtl.ref.send %x : !firrtl.uint<2>
    firrtl.strictconnect %sub_in, %x_ref : !firrtl.ref<uint<2>>

    %val = firrtl.ref.resolve %sub_out : !firrtl.ref<uint<2>>
    firrtl.strictconnect %y, %val : !firrtl.uint<2>
  }
}

Which produces:

// Generated by CIRCT 1.31.0g20230217_f4a1235
module RefUTurnChild(	// ref-child-uturn.mlir:6:3
  input  [1:0] x,	// ref-child-uturn.mlir:6:35
  output [1:0] y	// ref-child-uturn.mlir:6:61
);

  assign y = RefUTurnChild.x;	// ref-child-uturn.mlir:6:3, :12:12
endmodule
@dtzSiFive dtzSiFive added wontfix This will not be worked on FIRRTL Involving the `firrtl` dialect labels Feb 21, 2023
@dtzSiFive
Copy link
Contributor Author

This needs to work for the proposed FIRRTL reference types.

@dtzSiFive
Copy link
Contributor Author

HoistPassthrough + ProbeDCE makes this work, here's a touched up example (use ref.define for probes) that works now:

firrtl.circuit "RefUTurnChild" {
  firrtl.module private @UTurnChild(in %in: !firrtl.ref<uint<2>>, out %out: !firrtl.ref<uint<2>>) {
    firrtl.ref.define %out, %in : !firrtl.ref<uint<2>>
  }

  firrtl.module @RefUTurnChild(in %x : !firrtl.uint<2>, out %y : !firrtl.uint<2>) {
    %sub_in, %sub_out = firrtl.instance sub @UTurnChild(in in: !firrtl.ref<uint<2>>, out out: !firrtl.ref<uint<2>>)

    %x_ref = firrtl.ref.send %x : !firrtl.uint<2>
    firrtl.ref.define %sub_in, %x_ref : !firrtl.ref<uint<2>>

    %val = firrtl.ref.resolve %sub_out : !firrtl.ref<uint<2>>
    firrtl.strictconnect %y, %val : !firrtl.uint<2>
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

No branches or pull requests

1 participant