!FQBlZBRjRMgQBRocZx:matrix.org

FIRRTL

123 Members
Discussion about the FIRRTL hardware IR and compiler2 Servers

Load older messages


SenderMessageTime
26 Feb 2024
@rameloni:gitter.imRaffaele Meloni

I have also found the FIRRTL language specification doc (https://github.com/chipsalliance/firrtl-spec/releases/latest/download/spec.pdf). I think it is really useful for my purpose since it also explains how FIRRTL high-level types are lowered before the compilation to verilog.

I also thought that @[fileinfo] can be somehow exploited (of course not alone) to rebuild chisel constructs from FIRRTL (and verilog).

But, during chisel elaboration, the chisel IR is lowered to the FIRRTL. Is there any documentation for Chisel IR? For now, I retrieved the types supported in Chisel IR from the code only. The good thing about chisel IR is that it preserves the Data objects.

11:47:37
@seldridge:matrix.orgSchuyler Eldridge

It's semi-integrated in that if you pass the -g option to firtool it will compile with debug info and print source locator information. You would also need to output the final MLIR to see this. Small example:

FIRRTL version 4.0.0
circuit Foo:
  module Foo:
    input a: {b: UInt<1>}
    output b: {b: UInt<1>}

    connect b.b, not(a.b)
# firtool Foo.fir -g --output-final-mlir=Foo.out.mlir -mlir-print-debuginfo && cat Foo.out.mlir

module {
  hw.module @Foo(in %a_b : i1, out b_b : i1) {
    %true = hw.constant true loc(#loc1)
    %0 = comb.xor bin %a_b, %true {sv.namehint = "b_b"} : i1 loc(#loc1)
    %1 = comb.xor bin %a_b, %true {sv.namehint = "b_b"} : i1 loc(#loc1)
    %2 = dbg.struct {"b": %a_b} : i1 loc(#loc1)
    dbg.variable "a", %2 : !dbg.struct loc(#loc1)
    %3 = dbg.struct {"b": %0} : i1 loc(#loc1)
    dbg.variable "b", %3 : !dbg.struct loc(#loc1)
    hw.output %1 : i1 loc(#loc1)
  } loc(#loc1)
  om.class @Foo_Class(%basepath: !om.frozenbasepath) {
  } loc(#loc1)
} loc(#loc)
#loc = loc("Foo.fir":0:0)
#loc1 = loc(unknown)

Those dbg.* operations are representing the original structure of the design. These will be preserved across inlining, type lowering, etc. The file info is still there, too,

16:05:09
@rameloni:gitter.imRaffaele MeloniSchuyler Eldridge: thanks! But does it just propagate high level fir information, right? No information about the original chisel source code is provided19:36:33
29 Feb 2024
@seldridge:matrix.orgSchuyler EldridgeSo, it's intended to be enough information to link back to the Chisel source code. Chisel already is providing information about line/column number. Coupled with the debug info that can track the original structure (e.g., of Bundles or Modules), you can then build some powerful tooling on top of this. One such example is what Synopsys is building to enable debugging of Chisel (or languages like it) in Verdi. They gave a presentation of this today during the CIRCT dev meetings. Link to video: https://sifive.zoom.us/rec/share/HJDsUM5Rns71oehdjpLgxMZCAT6u9oBp7QfVA897se0YP07uLSZHkZ6OwBqLGK73.TanC9AeTavrHnybK01:57:37
@seldridge:matrix.orgSchuyler Eldridge

The rough idea is that the frontend language needs to put enough information into the debug dialect. Once that information is there, then the compiler will keep it around and the debug information can be used later to provide links from the Verilog back to the source language. You can play around with this with an example like the following:

//> using scala "2.13.12"
//> using repository sonatype-s01:snapshots
//> using lib "org.chipsalliance::chisel::6.0.0+74-0a437d8f-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0+74-0a437d8f-SNAPSHOT"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage

class Baz extends Bundle {
  val a = Flipped(Bool())
  val b = Bool()
}

class Bar extends RawModule {
  val io = IO(new Baz)

  io.b :<>= !io.a
}

class Foo extends RawModule with Public {
  val io = IO(new Baz)

  private val bar = Module(new Bar)
  io :<>= bar.io
}

object Main extends App {
  println(
    ChiselStage.emitSystemVerilog(
      new Foo,
      firtoolOpts = Array("-g", "-emit-hgldd", "-output-final-mlir=Foo.mlir")
    )
  )
}
02:05:58
@seldridge:matrix.orgSchuyler EldridgeThe original FIRRTL example doesn't really show this because it is not incorporating Chisel source locator information.02:06:32
4 Mar 2024
@rameloni:gitter.imRaffaele Meloni
In reply to @seldridge:matrix.org

It's semi-integrated in that if you pass the -g option to firtool it will compile with debug info and print source locator information. You would also need to output the final MLIR to see this. Small example:

FIRRTL version 4.0.0
circuit Foo:
  module Foo:
    input a: {b: UInt<1>}
    output b: {b: UInt<1>}

    connect b.b, not(a.b)
# firtool Foo.fir -g --output-final-mlir=Foo.out.mlir -mlir-print-debuginfo && cat Foo.out.mlir

module {
  hw.module @Foo(in %a_b : i1, out b_b : i1) {
    %true = hw.constant true loc(#loc1)
    %0 = comb.xor bin %a_b, %true {sv.namehint = "b_b"} : i1 loc(#loc1)
    %1 = comb.xor bin %a_b, %true {sv.namehint = "b_b"} : i1 loc(#loc1)
    %2 = dbg.struct {"b": %a_b} : i1 loc(#loc1)
    dbg.variable "a", %2 : !dbg.struct loc(#loc1)
    %3 = dbg.struct {"b": %0} : i1 loc(#loc1)
    dbg.variable "b", %3 : !dbg.struct loc(#loc1)
    hw.output %1 : i1 loc(#loc1)
  } loc(#loc1)
  om.class @Foo_Class(%basepath: !om.frozenbasepath) {
  } loc(#loc1)
} loc(#loc)
#loc = loc("Foo.fir":0:0)
#loc1 = loc(unknown)

Those dbg.* operations are representing the original structure of the design. These will be preserved across inlining, type lowering, etc. The file info is still there, too,

What version of firtool supports this option?
17:31:46
@rameloni:gitter.imRaffaele MeloniI got it running, I will play with it now thank you! I have only a question, I installed the latest firtool now, from what version is this debug option supported?18:10:43
@seldridge:matrix.orgSchuyler Eldridge I believe it is available since firtool-1.59.0. 20:12:28
7 Mar 2024
@rameloni:gitter.imRaffaele Meloni
In reply to @seldridge:matrix.org

The rough idea is that the frontend language needs to put enough information into the debug dialect. Once that information is there, then the compiler will keep it around and the debug information can be used later to provide links from the Verilog back to the source language. You can play around with this with an example like the following:

//> using scala "2.13.12"
//> using repository sonatype-s01:snapshots
//> using lib "org.chipsalliance::chisel::6.0.0+74-0a437d8f-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0+74-0a437d8f-SNAPSHOT"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage

class Baz extends Bundle {
  val a = Flipped(Bool())
  val b = Bool()
}

class Bar extends RawModule {
  val io = IO(new Baz)

  io.b :<>= !io.a
}

class Foo extends RawModule with Public {
  val io = IO(new Baz)

  private val bar = Module(new Bar)
  io :<>= bar.io
}

object Main extends App {
  println(
    ChiselStage.emitSystemVerilog(
      new Foo,
      firtoolOpts = Array("-g", "-emit-hgldd", "-output-final-mlir=Foo.mlir")
    )
  )
}

Can I get that information in a separate file?
I tried this but it didn't work:

  ChiselStage.emitSystemVerilog(
      new Foo,
      firtoolOpts = Array("-g", "-emit-hgldd", "--hgldd-output-dir=work", "-output-final-mlir=Foo.mlir"),
    )

I also tried to use emitSystemVerilogFile but it outputs both verilog and hgldd in the same file, I can't get a separate output

10:53:37
@rameloni:gitter.imRaffaele Meloni

I just found this way to achieve that:

 ChiselStage.emitSystemVerilog(
    new Foo,
    firtoolOpts = Array(
      "-g",
      "--split-verilog",
      "-o=workdir",
      "-emit-hgldd",
    ),
  )
11:01:08
11 Mar 2024
@rameloni:gitter.imRaffaele Meloni Schuyler Eldridge: is the hgldd format somehow standardized? Are its fields going to be fixed over time or can they change? 17:38:56
@seldridge:matrix.orgSchuyler Eldridge HGLDD is very Synopsys-specific right now and basically governed by what their needs are. So, it will likely change. I brought this up with Fabian and it seems reasonable to have a more generic format that is not driven by the needs of Synopsys. There are some hints of this with the -dump-di option to circt-translate that can be used to dump the debug info in a more human readable format (though this is intended for humans to read and not machines to consume). 21:18:26
@rameloni:gitter.imRaffaele Meloni
In reply to @seldridge:matrix.org
HGLDD is very Synopsys-specific right now and basically governed by what their needs are. So, it will likely change. I brought this up with Fabian and it seems reasonable to have a more generic format that is not driven by the needs of Synopsys. There are some hints of this with the -dump-di option to circt-translate that can be used to dump the debug info in a more human readable format (though this is intended for humans to read and not machines to consume).
Schuyler Eldridge: ah alright, I'm also working on a waveform viewer for chisel open source, and I was thinking to use hgldd to map verilog to Firrtl IR. The alternative I thought was to parse directly the debug dialect from mlir but I do think it's gonna be more complex
21:24:53
@seldridge:matrix.orgSchuyler EldridgeDon't parse MLIR directly. It's not a stable format and it may change at any time. You can have an alternative emission of the debug info, though. That's more getting at this alternative interchange format which has the same data, but isn't being tuned to work with Verdi.21:26:02
@rameloni:gitter.imRaffaele Meloni
In reply to @seldridge:matrix.org
Don't parse MLIR directly. It's not a stable format and it may change at any time. You can have an alternative emission of the debug info, though. That's more getting at this alternative interchange format which has the same data, but isn't being tuned to work with Verdi.
How can I get it
21:26:53
@rameloni:gitter.imRaffaele Meloni* How can I get it?21:27:01
@rameloni:gitter.imRaffaele Meloni
In reply to @rameloni:gitter.im
Schuyler Eldridge: ah alright, I'm also working on a waveform viewer for chisel open source, and I was thinking to use hgldd to map verilog to Firrtl IR. The alternative I thought was to parse directly the debug dialect from mlir but I do think it's gonna be more complex
About this, I'm working on a little demo right now, and I'm going to publish it to ask for feedback and opinions about the project
21:29:08
@rameloni:gitter.imRaffaele Meloni* About this, I'm working on a little demo right now, and I'm going to publish it in 1/2 weeks to ask for feedback and opinions about the project21:29:25
@seldridge:matrix.orgSchuyler EldridgeIt's probably fine to continue what you're doing and then take the feedback later. What I'm proposing is a "translation" (what MLIR calls something goes from X -> MLIR or MLIR -> X, with the HGLDD exporter being one of the latter) that is able to read the debug info and generate an alternative format.21:50:58
@rameloni:gitter.imRaffaele Meloni
In reply to @seldridge:matrix.org
It's probably fine to continue what you're doing and then take the feedback later. What I'm proposing is a "translation" (what MLIR calls something goes from X -> MLIR or MLIR -> X, with the HGLDD exporter being one of the latter) that is able to read the debug info and generate an alternative format.
What I've done so far is to set the project such that it is able to parse what is inside the HGLDD format and make it available to my program
21:54:37
@rameloni:gitter.imRaffaele MeloniIs it what you meant?22:04:28
@seldridge:matrix.orgSchuyler EldridgeYeah, that's what I mean!22:05:01
@rameloni:gitter.imRaffaele MeloniPerfect! Thank you!22:06:31
12 Mar 2024
@rameloni:gitter.imRaffaele Meloni Hi Schuyler Eldridge sorry to bother you again, is there any brief documentation that explains what values are dumped in the HGLDD JSON? 17:58:18
@rameloni:gitter.imRaffaele MeloniSo far I've based the parsing on what I understood from the values I got from some examples 18:00:09
@seldridge:matrix.orgSchuyler Eldridge
In reply to @rameloni:gitter.im
So far I've based the parsing on what I understood from the values I got from some examples
Annoyingly no other than whatever comments may be in the pass generating them. You may try pinging Fabian Schuiki on the LLVM discourse #circt channel, though.
22:24:10
20 Mar 2024
@chandanassmee19b093:gitter.imchandanassmee19b093 joined the room.04:29:15
@chandanassmee19b093:gitter.imchandanassmee19b093Hello everyone, I want to study how a verilog blackbox is handled in firrtl flow, and I want to know if firrtl transforms can be written to get the $fwrite and $stop functions in the verilog code to convert to printf and stop functions in firrtl so that I can move them along the golden gate( midas II) flow to get the assertions and printf statements synthesized in firesim simulation04:51:04
13 Apr 2024
@javathunderman:matrix.orgArjun joined the room.18:25:05

There are no newer messages yet.


Back to Room ListRoom Version: 5