Skip to content

Commit

Permalink
[firtool] Change scalarize-top-module option
Browse files Browse the repository at this point in the history
Remove the -scalarize-top-module option to firtool (and the parser).
Replace this with -scalarize-public-modules.  This is done in preparation
for FIRRTL 4.0.0.  This is also largely unnecessary once FIRRTL 4.0.0
figures out how to attach the ABI to each public module.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
  • Loading branch information
seldridge committed Nov 27, 2023
1 parent 9045ce5 commit 7b5be71
Show file tree
Hide file tree
Showing 29 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion include/circt/Dialect/FIRRTL/FIRParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct FIRParserOptions {
/// This, along with numOMIRFiles provides structure to the buffers in the
/// source manager.
unsigned numAnnotationFiles;
bool scalarizeTopModule = false;
bool scalarizePublicModules = false;
bool scalarizeExtModules = false;
};

Expand Down
11 changes: 6 additions & 5 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4638,19 +4638,20 @@ ParseResult FIRCircuitParser::parseModule(CircuitOp circuit, bool isPublic,
info.parseOptionalInfo() || parsePortList(portList, portLocs, indent))
return failure();

auto circuitName = circuit.getName();
auto isMainModule = (name == circuitName);
// The main module is implicitly public.
isPublic |= name == circuit.getName();

ArrayAttr annotations = getConstants().emptyArrayAttr;
auto convention = Convention::Internal;
if (isMainModule && getConstants().options.scalarizeTopModule)
if (isPublic && getConstants().options.scalarizePublicModules)
convention = Convention::Scalarized;
auto conventionAttr = ConventionAttr::get(getContext(), convention);
auto builder = circuit.getBodyBuilder();
auto moduleOp = builder.create<FModuleOp>(info.getLoc(), name, conventionAttr,
portList, annotations);

auto visibility = isMainModule || isPublic ? SymbolTable::Visibility::Public
: SymbolTable::Visibility::Private;
auto visibility = isPublic ? SymbolTable::Visibility::Public
: SymbolTable::Visibility::Private;
SymbolTable::setSymbolVisibility(moduleOp, visibility);

// Parse the body of this module after all prototypes have been parsed. This
Expand Down
10 changes: 5 additions & 5 deletions test/firtool/convention.fir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: firtool %s --format=fir --parse-only --scalarize-top-module=false --scalarize-ext-modules=false --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_NONE %s
; RUN: firtool %s --format=fir --parse-only --scalarize-top-module=true --scalarize-ext-modules=false --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_TOP %s
; RUN: firtool %s --format=fir --parse-only --scalarize-top-module=false --scalarize-ext-modules=true --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_EXT %s
; RUN: firtool %s --format=fir --parse-only --scalarize-top-module=true --scalarize-ext-modules=true --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_BOTH %s
; RUN: firtool %s --format=fir --parse-only --scalarize-public-modules=false --scalarize-ext-modules=false --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_NONE %s
; RUN: firtool %s --format=fir --parse-only --scalarize-public-modules=true --scalarize-ext-modules=false --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_TOP %s
; RUN: firtool %s --format=fir --parse-only --scalarize-public-modules=false --scalarize-ext-modules=true --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_EXT %s
; RUN: firtool %s --format=fir --parse-only --scalarize-public-modules=true --scalarize-ext-modules=true --preserve-aggregate=all | FileCheck --check-prefix=SCALARIZE_BOTH %s

; Ensure that top module and ext modules are marked scalarized.

Expand All @@ -14,7 +14,7 @@ circuit Top :
output port: UInt<8>[2]
port[0] <= UInt<8>(0)
port[1] <= UInt<8>(0)

; SCALARIZE_NONE-NOT: attributes {convention = #firrtl<convention scalarized>}
; SCALARIZE_TOP-NOT: attributes {convention = #firrtl<convention scalarized>}
; SCALARIZE_EXT: attributes {convention = #firrtl<convention scalarized>}
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/refs-in-aggs.fir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Check this design makes it through firtool.
; RUN: firtool %s --no-dedup
; RUN: firtool %s --no-dedup --preserve-aggregate=all --scalarize-top-module=false
; RUN: firtool %s --no-dedup --preserve-aggregate=all --scalarize-public-modules=false

; Check parsing into open aggregates.
; RUN: circt-translate -import-firrtl -verify-diagnostics -split-input-file %s | circt-opt | FileCheck %s
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/define-flip-to-passive.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit Foo :
; SPEC EXAMPLE BEGIN
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/define-subelement.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit Foo:
; SPEC EXAMPLE BEGIN
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/define.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit Refs:
; SPEC EXAMPLE BEGIN
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/endpoints.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit Top : %[[
{ "class": "firrtl.transforms.DontTouchAnnotation", "target": "~Top|Top>producer_debug"},
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/ext.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
circuit MyExternalModuleWithRefs :
; SPEC EXAMPLE BEGIN
extmodule MyExternalModuleWithRefs :
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/force_and_release.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit ForceAndRelease:
; SPEC EXAMPLE BEGIN
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/force_initial.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0

circuit ForceAndRelease:
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/force_nonpassive.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false -verify-diagnostics
FIRRTL version 3.0.0

circuit Top :
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/forwarding_refs_upwards.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
circuit Forward:
; SPEC EXAMPLE BEGIN
extmodule Foo : ; XXX: module -> extmodule
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/forwarding_refs_upwards_narrow.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
circuit Forward :
; SPEC EXAMPLE BEGIN
extmodule Foo :
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/in_ref_context.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false -verify-diagnostics
FIRRTL version 3.0.0
; expected-error @+27 {{input probes cannot be used}}
; expected-note @+19 {{input probe here}}
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/inference_reset_bad.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false -verify-diagnostics
; XFAIL: *
; https://github.com/llvm/circt/issues/4813
FIRRTL version 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/inference_reset_good.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit ResetInferGood :
; SPEC EXAMPLE BEGIN
Expand Down
3 changes: 1 addition & 2 deletions test/firtool/spec/refs/inference_works.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
; NOT SPEC EXAMPLE
FIRRTL version 3.0.0

Expand All @@ -16,4 +16,3 @@ circuit MinimumWidth :
inst u of Uninferred
connect u.x, x
connect y, read(u.r)

2 changes: 1 addition & 1 deletion test/firtool/spec/refs/invalid_in.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s --verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false --verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false --verify-diagnostics
FIRRTL version 3.0.0
circuit FooUser:
; Invalid, per spec
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/nested_refproducer.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0
circuit RefProducer :
; SPEC EXAMPLE BEGIN
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/nosubaccess.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
circuit NoSubAccessesWithProbes :
extmodule Ext :
output x : {a : Probe<UInt<2>[2]>, b : UInt<2>}[3]
Expand Down
3 changes: 1 addition & 2 deletions test/firtool/spec/refs/probe_export_simple.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
circuit MyModule :
; SPEC EXAMPLE BEGIN
module MyModule :
Expand All @@ -8,4 +8,3 @@ circuit MyModule :

define r = probe(in)
; SPEC EXAMPLE END

2 changes: 1 addition & 1 deletion test/firtool/spec/refs/read.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0

circuit Foo :
Expand Down
3 changes: 1 addition & 2 deletions test/firtool/spec/refs/read_subelement.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0

circuit Foo :
Expand All @@ -17,4 +17,3 @@ circuit Foo :
inst f of Foo
connect x, read(f.p.b) ; indirectly access the probed data
; SPEC EXAMPLE END

2 changes: 1 addition & 1 deletion test/firtool/spec/refs/read_subelement_add.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0

circuit Foo :
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/unused_in.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false -verify-diagnostics
FIRRTL version 3.0.0
circuit ForwardDownwardsTH :
module ForwardDownwardsTH :
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/uturn.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false -verify-diagnostics
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false -verify-diagnostics
FIRRTL version 3.0.0
circuit UTurnTH:
module UTurnTH:
Expand Down
2 changes: 1 addition & 1 deletion test/firtool/spec/refs/when_c_force_initial.fir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: firtool %s
; RUN: firtool %s -preserve-aggregate=all -scalarize-top-module=false
; RUN: firtool %s -preserve-aggregate=all -scalarize-public-modules=false
FIRRTL version 3.0.0

circuit WhenCForce :
Expand Down
8 changes: 4 additions & 4 deletions tools/firtool/firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ static cl::opt<InfoLocHandling> infoLocHandling(
cl::init(InfoLocHandling::PreferInfo), cl::cat(mainCategory));

static cl::opt<bool>
scalarizeTopModule("scalarize-top-module",
cl::desc("Scalarize the ports of the top module"),
cl::init(true), cl::cat(mainCategory));
scalarizePublicModules("scalarize-public-modules",
cl::desc("Scalarize all public modules"),
cl::init(true), cl::cat(mainCategory));

static cl::opt<bool>
scalarizeExtModules("scalarize-ext-modules",
Expand Down Expand Up @@ -339,7 +339,7 @@ static LogicalResult processBuffer(
firrtl::FIRParserOptions options;
options.infoLocatorHandling = infoLocHandling;
options.numAnnotationFiles = numAnnotationFiles;
options.scalarizeTopModule = scalarizeTopModule;
options.scalarizePublicModules = scalarizePublicModules;
options.scalarizeExtModules = scalarizeExtModules;
module = importFIRFile(sourceMgr, &context, parserTimer, options);
} else {
Expand Down

0 comments on commit 7b5be71

Please sign in to comment.