diff --git a/build.sc b/build.sc index afba001c8..6e1793e15 100644 --- a/build.sc +++ b/build.sc @@ -243,6 +243,17 @@ trait Subsystem def chiselIvy = None } +object panamaconverter extends PanamaConverter + +trait PanamaConverter + extends millbuild.dependencies.chisel.build.PanamaConverter { + def crossValue = v.scala + + override def millSourcePath = os.pwd / "dependencies" / "chisel" / "panamaconverter" + + def scalaVersion = T(v.scala) +} + // Module to generate RTL from json config object elaborator extends Elaborator @@ -250,6 +261,10 @@ trait Elaborator extends millbuild.common.ElaboratorModule { def scalaVersion = T(v.scala) + def panamaconverterModule = panamaconverter + + def circtInstallPath = T.input(PathRef(os.Path(T.ctx().env("CIRCT_INSTALL_PATH")))) + def generators = Seq( t1, ipemu, diff --git a/common.sc b/common.sc index 42364c782..82499c185 100644 --- a/common.sc +++ b/common.sc @@ -119,7 +119,13 @@ trait ElaboratorModule extends ScalaModule with HasChisel { def generators: Seq[ScalaModule] - override def moduleDeps = super.moduleDeps ++ generators + def panamaconverterModule: ScalaModule + def circtInstallPath: T[PathRef] + override def moduleDeps = super.moduleDeps ++ Seq(panamaconverterModule) ++ generators def mainargsIvy: Dep override def ivyDeps = T(super.ivyDeps() ++ Seq(mainargsIvy)) + override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21")) + override def forkArgs: T[Seq[String]] = T( + super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview", s"-Djava.library.path=${ circtInstallPath().path / "lib"}") + ) } diff --git a/elaborator/src/Main.scala b/elaborator/src/Main.scala index 59f94bdb6..ad0eb22dc 100644 --- a/elaborator/src/Main.scala +++ b/elaborator/src/Main.scala @@ -5,6 +5,7 @@ package org.chipsalliance.t1.elaborator import mainargs._ import org.chipsalliance.t1.rtl.T1Parameter +import chisel3.panamalib.option._ object Main { implicit object PathRead extends TokensReader.Simple[os.Path] { @@ -14,22 +15,33 @@ object Main { @main case class ElaborateConfig( - @arg(name = "target-dir", short = 't') targetDir: os.Path) { + @arg(name = "target-dir", short = 't') targetDir: os.Path, + @arg(name = "binder-mlirbc-out") binderMlirbcOut: Option[String] = None) { def elaborate(gen: () => chisel3.RawModule): Unit = { - var topName: String = null + var fir: firrtl.ir.Circuit = null + var panamaCIRCTConverter: chisel3.panamaconverter.PanamaCIRCTConverter = null + val annos = Seq( new chisel3.stage.phases.Elaborate, - new chisel3.stage.phases.Convert + if (binderMlirbcOut.isEmpty) new chisel3.stage.phases.Convert else chisel3.panamaconverter.stage.Convert ).foldLeft( Seq( - chisel3.stage.ChiselGeneratorAnnotation(gen) + chisel3.stage.ChiselGeneratorAnnotation(gen), + chisel3.panamaconverter.stage.FirtoolOptionsAnnotation(FirtoolOptions(Set( + BuildMode(BuildModeDebug), + PreserveValues(PreserveValuesModeNamed), + DisableUnknownAnnotations(true) + ))), ): firrtl.AnnotationSeq ) { case (annos, stage) => stage.transform(annos) } .flatMap { case firrtl.stage.FirrtlCircuitAnnotation(circuit) => - topName = circuit.main - os.write(targetDir / s"$topName.fir", circuit.serialize) + if (binderMlirbcOut.isEmpty) fir = circuit + None + case chisel3.panamaconverter.stage.PanamaCIRCTConverterAnnotation(converter) => + if (binderMlirbcOut.nonEmpty) panamaCIRCTConverter = converter None + case _: chisel3.panamaconverter.stage.FirtoolOptionsAnnotation => None case _: chisel3.stage.DesignAnnotation[_] => None case _: chisel3.stage.ChiselCircuitAnnotation => None case _: freechips.rocketchip.util.ParamsAnnotation => None @@ -39,7 +51,14 @@ object Main { case _: freechips.rocketchip.util.SRAMAnnotation => None case a => Some(a) } - os.write(targetDir / s"$topName.anno.json", firrtl.annotations.JsonProtocol.serialize(annos)) + + binderMlirbcOut match { + case Some(outFile) => + os.write(targetDir / s"$outFile.mlirbc", panamaCIRCTConverter.mlirBytecodeStream) + case None => + os.write(targetDir / s"${fir.main}.fir", fir.serialize) + os.write(targetDir / s"${fir.main}.anno.json", firrtl.annotations.JsonProtocol.serialize(annos)) + } } } diff --git a/flake.lock b/flake.lock index 1779ecd60..4ca0f3282 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708807242, - "narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=", + "lastModified": 1710272261, + "narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a", + "rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2", "type": "github" }, "original": { diff --git a/nix/overlay.nix b/nix/overlay.nix index 4f8a70932..210848f67 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -20,6 +20,7 @@ in libspike = final.callPackage ./pkgs/libspike.nix { }; buddy-mlir = final.callPackage ./pkgs/buddy-mlir.nix { }; fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { }; + circt-full = final.callPackage ./pkgs/circt-full.nix { }; mill = let jre = final.jdk21; in (prev.mill.override { inherit jre; }).overrideAttrs (_: { diff --git a/nix/pkgs/circt-full.nix b/nix/pkgs/circt-full.nix new file mode 100644 index 000000000..137db8bca --- /dev/null +++ b/nix/pkgs/circt-full.nix @@ -0,0 +1,15 @@ +{ symlinkJoin, circt }: +symlinkJoin { + name = "circt-full"; + paths = [ + circt + circt.lib + circt.dev + + circt.llvm + circt.llvm.lib + circt.llvm.dev + ]; + + inherit (circt) meta; +} diff --git a/nix/t1/_sources/generated.json b/nix/t1/_sources/generated.json index 40025bad1..95fa4c438 100644 --- a/nix/t1/_sources/generated.json +++ b/nix/t1/_sources/generated.json @@ -61,7 +61,7 @@ }, "chisel": { "cargoLocks": null, - "date": "2024-02-26", + "date": "2024-03-27", "extract": null, "name": "chisel", "passthru": null, @@ -73,11 +73,11 @@ "name": null, "owner": "chipsalliance", "repo": "chisel", - "rev": "344bdd636a36e6c3933cac527c61b5671d271534", - "sha256": "sha256-SZNs0AeAQtenGatRbUftxAZOLI2G7KgEbAeW0ciAl0c=", + "rev": "9177535ff1be47ffd99034bf0154c0f1ec637419", + "sha256": "sha256-smqNuOnmz+MeVGyS7mdIzegniQ/6EJH4CFqK4JntvrI=", "type": "github" }, - "version": "344bdd636a36e6c3933cac527c61b5671d271534" + "version": "9177535ff1be47ffd99034bf0154c0f1ec637419" }, "diplomacy": { "cargoLocks": null, diff --git a/nix/t1/_sources/generated.nix b/nix/t1/_sources/generated.nix index b9f1b0f08..c8f7bebc9 100644 --- a/nix/t1/_sources/generated.nix +++ b/nix/t1/_sources/generated.nix @@ -39,15 +39,15 @@ }; chisel = { pname = "chisel"; - version = "344bdd636a36e6c3933cac527c61b5671d271534"; + version = "9177535ff1be47ffd99034bf0154c0f1ec637419"; src = fetchFromGitHub { owner = "chipsalliance"; repo = "chisel"; - rev = "344bdd636a36e6c3933cac527c61b5671d271534"; + rev = "9177535ff1be47ffd99034bf0154c0f1ec637419"; fetchSubmodules = false; - sha256 = "sha256-SZNs0AeAQtenGatRbUftxAZOLI2G7KgEbAeW0ciAl0c="; + sha256 = "sha256-smqNuOnmz+MeVGyS7mdIzegniQ/6EJH4CFqK4JntvrI="; }; - date = "2024-02-26"; + date = "2024-03-27"; }; diplomacy = { pname = "diplomacy"; diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 620ea563f..75c8cbafc 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -65,10 +65,10 @@ lib.makeScope newScope ip = { recurseForDerivations = true; - mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ip"; }; + mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ip"; /* use-binder = true; */ }; rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.mlirbc; }; - emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ipemu"; }; + emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ipemu"; /* use-binder = true; */ }; emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.emu-mlirbc; }; emu = innerSelf.callPackage ./ipemu.nix { rtl = innerSelf.ip.emu-rtl; stdenv = moldStdenv; }; @@ -78,7 +78,7 @@ lib.makeScope newScope subsystem = { recurseForDerivations = true; - mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "subsystem"; }; + mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "subsystem"; use-binder = true; }; rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.subsystem.mlirbc; }; }; }) diff --git a/nix/t1/mlirbc.nix b/nix/t1/mlirbc.nix index 2cf7c3421..b617df228 100644 --- a/nix/t1/mlirbc.nix +++ b/nix/t1/mlirbc.nix @@ -8,6 +8,7 @@ , elaborator , configName , target +, use-binder ? false }: assert lib.assertMsg @@ -15,12 +16,14 @@ assert lib.assertMsg "Unknown elaborate target ${target}"; let - elaborateArgs = [ + elaborateArgs = lib.filter (s: s != "") [ "--ip-config" # Can't use `toString` here, or due to some shell escape issue, Java nio cannot find the path "${elaborateConfigJson}" "--target-dir" - "elaborate" + (if use-binder then (placeholder "out") else "elaborate") + (lib.optionalString (use-binder) "--binder-mlirbc-out") + (lib.optionalString (use-binder) "${target}-${configName}") ]; in stdenvNoCC.mkDerivation { @@ -37,7 +40,7 @@ stdenvNoCC.mkDerivation { mkdir -p elaborate $out ${elaborator}/bin/elaborator ${target} ${lib.escapeShellArgs elaborateArgs} - + '' + lib.optionalString (!use-binder) '' firtool elaborate/*.fir \ --annotation-file elaborate/*.anno.json \ -O=debug \ diff --git a/nix/t1/t1.nix b/nix/t1/t1.nix index e8190c093..78bd2699c 100644 --- a/nix/t1/t1.nix +++ b/nix/t1/t1.nix @@ -2,11 +2,13 @@ , stdenv , fetchMillDeps , makeWrapper -, jre +, jdk21 # chisel deps , mill , espresso +, circt-full +, jextract , strip-nondeterminism , submodules @@ -57,6 +59,8 @@ let nativeBuildInputs = [ mill + circt-full + jextract strip-nondeterminism makeWrapper @@ -65,6 +69,8 @@ let submodules.setupHook ]; + env.CIRCT_INSTALL_PATH = circt-full; + outputs = [ "out" "configgen" "elaborator" ]; buildPhase = '' @@ -81,8 +87,8 @@ let mv out/elaborator/assembly.dest/out.jar $out/share/java/elaborator.jar mkdir -p $configgen/bin $elaborator/bin - makeWrapper ${jre}/bin/java $configgen/bin/configgen --add-flags "-jar $out/share/java/configgen.jar" - makeWrapper ${jre}/bin/java $elaborator/bin/elaborator --add-flags "-jar $out/share/java/elaborator.jar" + makeWrapper ${jdk21}/bin/java $configgen/bin/configgen --add-flags "-jar $out/share/java/configgen.jar" + makeWrapper ${jdk21}/bin/java $elaborator/bin/elaborator --add-flags "--enable-preview -Djava.library.path=${circt-full}/lib -jar $out/share/java/elaborator.jar" ''; }; in