circt icon indicating copy to clipboard operation
circt copied to clipboard

[LowerToHW] Make mux result pragmas optional

Open fabianschuiki opened this issue 3 years ago • 3 comments

PR #3404 introduced the emission of pragmas alongside multiplexer results:

circuit MultibitMux: 
  module MultibitMux :
    input a : UInt<1>[3]
    input sel : UInt<2>
    output b : UInt<1>
    b <= a[sel]
module MultibitMux(
  ...
  wire _GEN;

  wire [2:0] _GEN_0 = {{a_2}, {a_1}, {a_0}};
  assign _GEN = _GEN_0[sel] /* cadence map_to_mux */;   /* synopsys infer_mux_override */
  assign b = &sel ? a_0 : _GEN;
endmodule

This happens unconditionally. The problem is that for passes/tools that would like to analyze the HW lowering from FIRRTL, information is lost: the assignment is emitted as an sv.verbatim operation, which essentially removes the assignment from the IR and makes it hard to analyze. https://github.com/llvm/circt/blob/b77d81787ab37151bc579f2545e2369a328d7523/lib/Conversion/FIRRTLToHW/LowerToHW.cpp#L3411-L3430

It would be great to expose this mapping through a lowering option, such that users intending to further process the HW output (without the intent to go straight to SV) can disable the pragmas and retain the assignment information.

fabianschuiki avatar Sep 06 '22 16:09 fabianschuiki

#3832 does make the assignment visible via the SV dialect, which is good enough for now, but it does still pollute the HW dialect with SV ops, resulting in something like:

%0 = sv.wire  : !hw.inout<i5>
%1 = hw.array_get %x[%y] {sv.attributes = #sv.attributes<[#sv.attribute<"cadence map_to_mux">], emitAsComments>} : !hw.array<8xi5>
sv.assign %0, %1 {sv.attributes = #sv.attributes<[#sv.attribute<"synopsys infer_mux_override">], emitAsComments>} : i5
%2 = sv.read_inout %0 : !hw.inout<i5>

Ideally there could be a solution here that doesn't involve using SV ops at the HW level.

zyedidia avatar Sep 07 '22 20:09 zyedidia

Yeah it would be cool if we had a mux op in comb that actually encoded this specific use case of providing hints for the downstream tools, such that we could work around the SV dialect. Or a lowering option for LowerToHW that would skip these attributes entirely.

fabianschuiki avatar Sep 08 '22 01:09 fabianschuiki

Or a lowering option for LowerToHW that would skip these attributes entirely.

Yeah, I think it makes sense to create an option to attach pragmas if there is actual demand.

uenoku avatar Sep 08 '22 05:09 uenoku