[firtool] Lower annotations with -parse-only

Change `firtool -parse-only` to stop after parsing, verification, and
annotation lowering as opposed to stopping after parsing.  It is
incredibly rare that a user (or, much more likely, a developer) actually
wants the behavior of stopping after parsing as opposed to stopping
after annotation lowering.  This avoids a frequent pattern where a
user/developer will use something like the following instead of
`-parse-only` for any circuit that includes annotations:

  firtool -parse-only Foo.fir | circt-opt -firrtl-lower-annotations

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
This commit is contained in:
Schuyler Eldridge 2022-09-21 17:29:15 -04:00
parent 2c233e621e
commit e61288bf32
No known key found for this signature in database
GPG Key ID: 50C5E9936AAD536D
2 changed files with 13 additions and 20 deletions

View File

@ -1,9 +1,8 @@
; RUN: firtool %s --format=fir --ir-fir | circt-opt | FileCheck %s --check-prefix=MLIR
; RUN: firtool %s --format=fir --ir-fir --annotation-file %s.anno.json,%s.anno.1.json | circt-opt | FileCheck %s --check-prefix=ANNOTATIONS
; RUN: firtool %s --format=fir --ir-fir --annotation-file %s.anno.json --annotation-file %s.anno.1.json | circt-opt | FileCheck %s --check-prefix=ANNOTATIONS
; RUN: firtool %s --format=fir --parse-only --annotation-file %s.anno.json,%s.anno.1.json | circt-opt | FileCheck %s --check-prefix=ANNOTATIONS
; RUN: firtool %s --format=fir --parse-only --annotation-file %s.anno.json --annotation-file %s.anno.1.json | circt-opt | FileCheck %s --check-prefix=ANNOTATIONS
; RUN: firtool %s --format=fir --ir-hw | circt-opt | FileCheck %s --check-prefix=MLIRLOWER
; RUN: firtool %s --format=fir -verilog | FileCheck %s --check-prefix=VERILOG
; RUN: firtool %s --annotation-file %s.anno.json,%s.anno.1.json --parse-only | FileCheck %s --check-prefix=RAWANNOTATIONS
; RUN: firtool %s --omir-file %s.omir.anno.json --parse-only | circt-opt -firrtl-lower-annotations | FileCheck %s --check-prefix=OMIR
; RUN: firtool %s --omir-file %s.omir.anno.json --output-omir meta.omir.json --verilog | FileCheck %s --check-prefix=OMIROUT
; RUN: firtool %s --format=fir --ir-verilog | circt-opt | FileCheck %s --check-prefix=VERILOG-IR
@ -19,14 +18,6 @@ circuit test_mod : %[[{"class": "circt.testNT", "data": "a"}]]
; ANNOTATIONS-SAME: {class = "circt.test", info = "a CircuitTarget Annotation"}
; ANNOTATIONS-SAME: {class = "circt.test", info = "a CircuitName Annotation"}
; RAWANNOTATIONS-LABEL: firrtl.circuit "test_mod"
; RAWANNOTATIONS-SAME: {class = "circt.testNT", data = "a"}
; RAWANNOTATIONS-SAME: {class = "circt.testNT", info = "a NoTargetAnnotation"}
; RAWANNOTATIONS-SAME: {class = "circt.test", info = "a CircuitTarget Annotation", target = "~test_mod"}
; RAWANNOTATIONS-SAME: {class = "circt.test", info = "a ModuleTarget Annotation", target = "~test_mod|test_mod"}
; RAWANNOTATIONS-SAME: {class = "circt.test", info = "a CircuitName Annotation", target = "test_mod"}
; RAWANNOTATIONS-SAME: {class = "circt.test", info = "a ModuleName Annotation", target = "test_mod.test_mod"}
; OMIR: #loc0 = loc(fused["Foo.scala":64:64, "Bar.scala":128:128])
; OMIR-NEXT: #loc1 = loc("Foo.scala":32:32)
; OMIR-LABEL: firrtl.circuit "test_mod"

View File

@ -322,7 +322,8 @@ static cl::opt<OutputFormatKind> outputFormat(
cl::desc("Specify output format:"),
cl::values(
clEnumValN(OutputParseOnly, "parse-only",
"Emit FIR dialect after parsing"),
"Emit FIR dialect after parsing, verification, and "
"annotation lowering"),
clEnumValN(OutputIRFir, "ir-fir", "Emit FIR dialect after pipeline"),
clEnumValN(OutputIRHW, "ir-hw", "Emit HW dialect"),
clEnumValN(OutputIRSV, "ir-sv", "Emit SV dialect"),
@ -537,14 +538,6 @@ processBuffer(MLIRContext &context, TimingScope &ts, llvm::SourceMgr &sourceMgr,
<< " sec\n";
}
// If the user asked for just a parse, stop here.
if (outputFormat == OutputParseOnly) {
mlir::ModuleOp theModule = module.release();
auto outputTimer = ts.nest("Print .mlir output");
printOp(theModule, outputFile.value()->os());
return success();
}
// Apply any pass manager command line options.
PassManager pm(&context);
pm.enableVerifier(verifyPasses);
@ -556,6 +549,15 @@ processBuffer(MLIRContext &context, TimingScope &ts, llvm::SourceMgr &sourceMgr,
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotationsPass(
disableAnnotationsUnknown, disableAnnotationsClassless));
// If the user asked for --parse-only, stop after running LowerAnnotations.
if (outputFormat == OutputParseOnly) {
if (failed(pm.run(module.get())))
return failure();
auto outputTimer = ts.nest("Print .mlir output");
printOp(*module, outputFile.value()->os());
return success();
}
// TODO: Move this to the O1 pipeline.
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
firrtl::createDropNamesPass(preserveMode));