llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.69k stars 302 forks source link

[FIRRTL] firrtl-lower-signatures fails for enum types #7106

Open programmerjake opened 6 months ago

programmerjake commented 6 months ago

using firtool-1.75.0 from github releases

I expect firtool to be able to lower enum types as specified in the ABI, however it just plain fails.

using the following FIRRTL:

FIRRTL version 3.2.0
circuit check_enum_literals:
    type Ty0 = {|None, Some: UInt<8>|}
    module check_enum_literals:
        input i: UInt<8>
        output o: Ty0
        connect o, {|None, Some: UInt<8>|}(Some, i)

I tried running:

firtool check_enum_literals.fir -o - --mlir-print-ir-after-all

which output:

<snip>
// -----// IR Dump After LowerIntrinsics (firrtl-lower-intrinsics) //----- //
firrtl.module @check_enum_literals(in %i: !firrtl.uint<8>, out %o: !firrtl.alias<Ty0, enum<None: uint<0>, Some: uint<8>>>) attributes {convention = #firrtl<convention scalarized>} {
  %0 = firrtl.enumcreate Some(%i) : (!firrtl.uint<8>) -> !firrtl.enum<None: uint<0>, Some: uint<8>>
  firrtl.connect %o, %0 : !firrtl.alias<Ty0, enum<None: uint<0>, Some: uint<8>>>, !firrtl.enum<None: uint<0>, Some: uint<8>>
}

// -----// IR Dump After LowerSignatures Failed (firrtl-lower-signatures) //----- //
firrtl.circuit "check_enum_literals" {
  firrtl.module @check_enum_literals(in %i: !firrtl.uint<8>, out %o: !firrtl.alias<Ty0, enum<None: uint<0>, Some: uint<8>>>) attributes {convention = #firrtl<convention scalarized>} {
    %0 = firrtl.enumcreate Some(%i) : (!firrtl.uint<8>) -> !firrtl.enum<None: uint<0>, Some: uint<8>>
    firrtl.connect %o, %0 : !firrtl.alias<Ty0, enum<None: uint<0>, Some: uint<8>>>, !firrtl.enum<None: uint<0>, Some: uint<8>>
  }
}
uenoku commented 6 months ago

Thank you for the report! LowerSignature seems not to handle enum right now ;) https://github.com/llvm/circt/blob/76b65f8606de447a85ef63c9c98ae9b1e2bd4b7f/lib/Dialect/FIRRTL/Transforms/LowerSignatures.cpp#L234