Skip to content

Commit

Permalink
[nix] split mlirbc to two output
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin authored and SpriteOvO committed May 6, 2024
1 parent f3c0db6 commit 39776b4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 49 deletions.
23 changes: 13 additions & 10 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,27 @@ lib.makeScope newScope
then self.cases
else pkgsX86.t1."${configName}".cases;

ip = {
ip = rec {
recurseForDerivations = true;

mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ip"; /* use-binder = true; */ };
rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.mlirbc; };
elaborate = innerSelf.callPackage ./elaborate.nix { target = "ip"; /* use-binder = true; */ };
mlirbc = innerSelf.callPackage ./mlirbc.nix { inherit elaborate; };
rtl = innerSelf.callPackage ./rtl.nix { inherit mlirbc; };

emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ipemu"; /* use-binder = true; */ };
emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.emu-mlirbc; };
emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; /* use-binder = true; */ };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = emu-mlirbc; };

emu = innerSelf.callPackage ./ipemu.nix { rtl = innerSelf.ip.emu-rtl; stdenv = moldStdenv; };
emu-trace = innerSelf.callPackage ./ipemu.nix { rtl = innerSelf.ip.emu-rtl; stdenv = moldStdenv; do-trace = true; };
emu = innerSelf.callPackage ./ipemu.nix { rtl = ip.emu-rtl; stdenv = moldStdenv; };
emu-trace = innerSelf.callPackage ./ipemu.nix { rtl = emu-rtl; stdenv = moldStdenv; do-trace = true; };
};

subsystem = {
subsystem = rec {
recurseForDerivations = true;

mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "subsystem"; /* use-binder = true; */ };
rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.subsystem.mlirbc; };
elaborate = innerSelf.callPackage ./elaborate.nix { target = "subsystem"; /* use-binder = true; */ };
mlirbc = innerSelf.callPackage ./mlirbc.nix { inherit elaborate; };
rtl = innerSelf.callPackage ./rtl.nix { inherit mlirbc; };
};

release = innerSelf.callPackage ./release { };
Expand Down
52 changes: 52 additions & 0 deletions nix/t1/elaborate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ stdenvNoCC
, lib

, espresso
, circt

, elaborateConfigJson
, elaborator
, configName
, target
, use-binder ? false
}:

assert lib.assertMsg
(lib.elem target [ "ip" "ipemu" "subsystem" "subsystememu" ])
"Unknown elaborate target ${target}";

let
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"
(if use-binder then (placeholder "out") else "elaborate")
(lib.optionalString (use-binder) "--binder-mlirbc-out")
(lib.optionalString (use-binder) "${target}-${configName}")
];
in
stdenvNoCC.mkDerivation {
name = "t1-${target}-${configName}-elaborate";

nativeBuildInputs = [ espresso circt ];

passthru = {
elaborateTarget = target;
elaborateConfig = configName;
};

buildCommand = ''
mkdir -p elaborate $out
${elaborator}/bin/elaborator ${target} ${lib.escapeShellArgs elaborateArgs}
'' + lib.optionalString (!use-binder) ''
firtool elaborate/*.fir \
--annotation-file elaborate/*.anno.json \
--emit-bytecode \
--parse-only \
-o $out/${target}-${configName}.mlirbc
'';

meta.description = "Parsed only MLIR Bytecode file for ${target} with config ${configName}.";
}
48 changes: 10 additions & 38 deletions nix/t1/mlirbc.nix
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
{ stdenvNoCC
, lib

, espresso
, circt

, elaborateConfigJson
, elaborator
, configName
, target
, use-binder ? false
, elaborate
}:

assert lib.assertMsg
(lib.elem target [ "ip" "ipemu" "subsystem" "subsystememu" ])
"Unknown elaborate target ${target}";

let
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"
(if use-binder then (placeholder "out") else "elaborate")
(lib.optionalString (use-binder) "--binder-mlirbc-out")
(lib.optionalString (use-binder) "${target}-${configName}")
];
uniqueName = "${elaborate.elaborateTarget}-${elaborate.elaborateConfig}";
in
stdenvNoCC.mkDerivation {
name = "t1-${target}-${configName}-mlirbc";
name = "t1-${uniqueName}-mlirbc";

nativeBuildInputs = [ espresso circt ];
nativeBuildInputs = [ circt ];

passthru = {
elaborateTarget = target;
elaborateConfig = configName;
};
inherit (elaborate) passthru;

buildCommand = ''
mkdir -p elaborate $out
mkdir $out
${elaborator}/bin/elaborator ${target} ${lib.escapeShellArgs elaborateArgs}
'' + lib.optionalString (!use-binder) ''
firtool elaborate/*.fir \
--annotation-file elaborate/*.anno.json \
firtool ${elaborate}/${uniqueName}.mlirbc \
--emit-bytecode \
-O=debug \
--preserve-values=named \
--output-annotation-file=mfc.anno.json \
--lowering-options=verifLabels \
--emit-bytecode \
--parse-only \
-o $out/${target}-${configName}.mlirbc
--output-final-mlir=$out/${uniqueName}-lowered.mlirbc
'';

meta.description = "Elaborated MLIR Bytecode file for ${target} with config ${configName}.";
meta.description = "Lowered MLIR Bytecode file (${uniqueName}).";
}
3 changes: 2 additions & 1 deletion nix/t1/rtl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ stdenvNoCC.mkDerivation {
buildCommand = ''
mkdir -p $out
firtool ${mlirbc}/*.mlirbc -o $out ${mfcArgs}
firtool ${mlirbc}/${mlirbc.elaborateTarget}-${mlirbc.elaborateConfig}-lowered.mlirbc \
-o $out ${mfcArgs}
'' + lib.optionalString fixupFilelist ''
# For ipemu, there are also some manually generated system verilog file for test bench.
# Those files are now recorded in a individual file list.
Expand Down

0 comments on commit 39776b4

Please sign in to comment.