20 #include "mlir/Transforms/Passes.h"
21 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/Path.h"
25 using namespace circt;
29 pm.nest<firrtl::CircuitOp>().addPass(
44 pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
47 pm.nest<firrtl::CircuitOp>().addPass(
49 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
57 StringRef inputFilename) {
68 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
69 mlir::createCSEPass());
71 pm.nest<firrtl::CircuitOp>().nestAny().addPass(mlir::createCSEPass());
74 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
77 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
80 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
85 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
91 pm.nest<firrtl::CircuitOp>().addPass(
104 pm.nest<firrtl::CircuitOp>().addPass(
121 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
131 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
148 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
156 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
161 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
167 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
174 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
192 pm.addNestedPass<firrtl::CircuitOp>(
197 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
206 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
208 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
213 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
219 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
224 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
235 pm.nest<firrtl::CircuitOp>().addPass(
238 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
243 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
247 if (outputFilename ==
"-")
250 pm.nest<firrtl::CircuitOp>().addPass(
255 ? llvm::sys::path::parent_path(inputFilename)
257 pm.nest<firrtl::CircuitOp>().addPass(
266 pm.nest<firrtl::CircuitOp>().addPass(
279 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
287 modulePM.addPass(mlir::createCSEPass());
298 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
305 pm.addPass(verif::createLowerFormalToHWPass());
317 FirtoolOptions::RandomKind::Reg),
325 FirtoolOptions::RandomKind::Mem),
330 ? seq::ReadEnableMode::Ignore
331 : seq::ReadEnableMode::Undefined,
339 modulePM.addPass(mlir::createCSEPass());
341 modulePM.addPass(mlir::createCSEPass());
361 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
372 if (
auto fileLoc = dyn_cast<FileLineColLoc>(loc))
373 return fileLoc.getFilename().getValue().ends_with(
".fir");
379 [](mlir::Location loc) {
return true; }));
397 std::unique_ptr<llvm::raw_ostream> os) {
407 llvm::raw_ostream &os) {
417 llvm::StringRef directory) {
435 llvm::raw_ostream &os) {
437 pm.addNestedPass<
hw::HWModuleOp>(circt::verif::createPrepareForFormalPass());
451 struct FirtoolCmdOptions {
454 llvm::cl::desc(
"Output filename, or directory for split output"),
455 llvm::cl::value_desc(
"filename"),
460 "disable-annotation-unknown",
461 llvm::cl::desc(
"Ignore unknown annotations when parsing"),
462 llvm::cl::init(
false)};
465 "disable-annotation-classless",
466 llvm::cl::desc(
"Ignore annotations without a class when parsing"),
467 llvm::cl::init(
false)};
470 "lower-annotations-no-ref-type-ports",
472 "Create real ports instead of ref type ports when resolving "
473 "wiring problems inside the LowerAnnotations pass"),
474 llvm::cl::init(
false), llvm::cl::Hidden};
477 "allow-adding-ports-on-public-modules",
478 llvm::cl::desc(
"Allow adding ports to public modules"),
479 llvm::cl::init(
false), llvm::cl::Hidden};
483 llvm::cl::desc(
"Convert probes to non-probe signals"),
484 llvm::cl::init(
false), llvm::cl::Hidden};
488 "preserve-aggregate",
489 llvm::cl::desc(
"Specify input file format:"),
492 "Preserve no aggregate"),
494 "Preserve only 1d vectors of ground type"),
496 "Preserve only vectors"),
498 "Preserve vectors and bundles")),
504 llvm::cl::desc(
"Specify the values which can be optimized away"),
507 "Strip all names. No name is preserved"),
508 clEnumValN(firrtl::PreserveValues::None,
"none",
509 "Names could be preserved by best-effort unlike `strip`"),
511 "Preserve values with meaningful names"),
513 "Preserve all values")),
514 llvm::cl::init(firrtl::PreserveValues::None)};
517 "g", llvm::cl::desc(
"Enable the generation of debug information"),
518 llvm::cl::init(
false)};
522 "O", llvm::cl::desc(
"Controls how much optimization should be performed"),
523 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
525 "Compile with only necessary optimizations"),
526 clEnumValN(firtool::FirtoolOptions::BuildModeRelease,
527 "release",
"Compile with optimizations")),
528 llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};
531 llvm::cl::desc(
"Disable layer sink"),
536 llvm::cl::desc(
"Disable optimizations"),
540 "export-chisel-interface",
541 llvm::cl::desc(
"Generate a Scala Chisel interface to the top level "
542 "module of the firrtl circuit"),
543 llvm::cl::init(
false)};
546 "chisel-interface-out-dir",
548 "The output directory for generated Chisel interface files"),
553 llvm::cl::desc(
"Transform vectors of bundles to bundles of vectors"),
554 llvm::cl::init(
false)};
558 llvm::cl::desc(
"Disable deduplication of structurally identical modules"),
559 llvm::cl::init(
false)};
562 "grand-central-companion-mode",
563 llvm::cl::desc(
"Specifies the handling of Grand Central companions"),
565 clEnumValN(firrtl::CompanionMode::Bind,
"bind",
566 "Lower companion instances to SystemVerilog binds"),
567 clEnumValN(firrtl::CompanionMode::Instantiate,
"instantiate",
568 "Instantiate companions in the design"),
569 clEnumValN(firrtl::CompanionMode::Drop,
"drop",
570 "Remove companions from the design")),
571 llvm::cl::init(firrtl::CompanionMode::Bind),
576 "disable-aggressive-merge-connections",
578 "Disable aggressive merge connections (i.e. merge all field-level "
579 "connections into bulk connections)"),
580 llvm::cl::init(
false)};
583 "advanced-layer-sink",
584 llvm::cl::desc(
"Sink logic into layer blocks (advanced)"),
585 llvm::cl::init(
false)};
589 llvm::cl::desc(
"Lower memories to have memories with masks as an "
590 "array with one memory per ground type"),
591 llvm::cl::init(
false)};
596 "Optional path to use as the root of black box annotations"),
597 llvm::cl::value_desc(
"path"),
603 llvm::cl::desc(
"Replace the seq mem for macro replacement and emit "
604 "relevant metadata"),
605 llvm::cl::init(
false)};
608 "repl-seq-mem-file", llvm::cl::desc(
"File name for seq mem metadata"),
612 "extract-test-code", llvm::cl::desc(
"Run the extract test code pass"),
613 llvm::cl::init(
false)};
616 "ignore-read-enable-mem",
617 llvm::cl::desc(
"Ignore the read enable signal, instead of "
618 "assigning X on read disable"),
619 llvm::cl::init(
false)};
623 "Disable random initialization code (may break semantics!)"),
625 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
626 "disable-mem-randomization",
627 "Disable emission of memory randomization code"),
628 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
629 "disable-reg-randomization",
630 "Disable emission of register randomization code"),
632 "disable-all-randomization",
633 "Disable emission of all randomization code")),
634 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
637 "output-annotation-file",
638 llvm::cl::desc(
"Optional output annotation file"),
639 llvm::cl::CommaSeparated, llvm::cl::value_desc(
"filename")};
642 "warn-on-unprocessed-annotations",
644 "Warn about annotations that were not removed by lower-to-hw"),
645 llvm::cl::init(
false)};
649 llvm::cl::desc(
"Annotate mux pragmas for memory array access"),
650 llvm::cl::init(
false)};
653 "verification-flavor",
654 llvm::cl::desc(
"Specify a verification flavor used in LowerFIRRTLToHW"),
656 clEnumValN(firrtl::VerificationFlavor::None,
"none",
657 "Use the flavor specified by the op"),
658 clEnumValN(firrtl::VerificationFlavor::IfElseFatal,
"if-else-fatal",
659 "Use Use `if(cond) else $fatal(..)` format"),
660 clEnumValN(firrtl::VerificationFlavor::Immediate,
"immediate",
661 "Use immediate verif statements"),
662 clEnumValN(firrtl::VerificationFlavor::SVA,
"sva",
"Use SVA")),
663 llvm::cl::init(firrtl::VerificationFlavor::None)};
666 "emit-separate-always-blocks",
668 "Prevent always blocks from being merged and emit constructs into "
669 "separate always blocks whenever possible"),
670 llvm::cl::init(
false)};
673 "etc-disable-instance-extraction",
674 llvm::cl::desc(
"Disable extracting instances only that feed test code"),
675 llvm::cl::init(
false)};
678 "etc-disable-register-extraction",
679 llvm::cl::desc(
"Disable extracting registers that only feed test code"),
680 llvm::cl::init(
false)};
683 "etc-disable-module-inlining",
684 llvm::cl::desc(
"Disable inlining modules that only feed test code"),
685 llvm::cl::init(
false)};
688 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
690 "Add a vivado specific SV attribute (* ram_style = "
691 "\"distributed\" *) to unpacked array registers as a workaronud "
692 "for a vivado synthesis bug that incorrectly modifies "
693 "address conflict behavivor of combinational memories"),
694 llvm::cl::init(
false)};
701 "ckg-name", llvm::cl::desc(
"Clock gate module name"),
702 llvm::cl::init(
"EICG_wrapper")};
705 "ckg-input", llvm::cl::desc(
"Clock gate input port name"),
706 llvm::cl::init(
"in")};
709 "ckg-output", llvm::cl::desc(
"Clock gate output port name"),
710 llvm::cl::init(
"out")};
713 "ckg-enable", llvm::cl::desc(
"Clock gate enable port name"),
714 llvm::cl::init(
"en")};
718 llvm::cl::desc(
"Clock gate test enable port name (optional)"),
719 llvm::cl::init(
"test_en")};
722 "export-module-hierarchy",
723 llvm::cl::desc(
"Export module and instance hierarchy as JSON"),
724 llvm::cl::init(
false)};
727 "strip-fir-debug-info",
729 "Disable source fir locator information in output Verilog"),
730 llvm::cl::init(
true)};
734 llvm::cl::desc(
"Disable source locator information in output Verilog"),
735 llvm::cl::init(
false)};
738 "fixup-eicg-wrapper",
739 llvm::cl::desc(
"Lower `EICG_wrapper` modules into clock gate intrinsics"),
740 llvm::cl::init(
false)};
743 "add-companion-assume",
744 llvm::cl::desc(
"Add companion assumes to assertions"),
745 llvm::cl::init(
false)};
748 "select-default-for-unspecified-instance-choice",
750 "Specialize instance choice to default, if no option selected"),
751 llvm::cl::init(
false)};
755 static llvm::ManagedStatic<FirtoolCmdOptions>
clOptions;
767 : outputFilename(
"-"), disableAnnotationsUnknown(false),
768 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
769 allowAddingPortsOnPublic(false), probesToSignals(false),
770 preserveAggregate(firrtl::PreserveAggregate::None),
771 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
772 buildMode(BuildModeRelease), disableLayerSink(false),
774 chiselInterfaceOutDirectory(
""), vbToBV(false), noDedup(false),
776 disableAggressiveMergeConnections(false), advancedLayerSink(false),
777 lowerMemories(false), blackBoxRootPath(
""), replSeqMem(false),
778 replSeqMemFile(
""), extractTestCode(false), ignoreReadEnableMem(false),
779 disableRandom(
RandomKind::None), outputAnnotationFilename(
""),
780 enableAnnotationWarning(false), addMuxPragmas(false),
782 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
783 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
784 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
785 ckgModuleName(
"EICG_wrapper"), ckgInputName(
"in"), ckgOutputName(
"out"),
786 ckgEnableName(
"en"), ckgTestEnableName(
"test_en"), ckgInstName(
"ckg"),
787 exportModuleHierarchy(false), stripFirDebugInfo(true),
788 stripDebugInfo(false), fixupEICGWrapper(false), addCompanionAssume(false),
789 disableCSEinClasses(false), selectDefaultInstanceChoice(false) {
810 clOptions->disableAggressiveMergeConnections;
828 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
static LogicalResult exportChiselInterface(CircuitOp circuit, llvm::raw_ostream &os)
Exports a Chisel interface to the output stream.
std::unique_ptr< mlir::Pass > createDedupPass()
@ All
Preserve all aggregate values.
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
@ None
Don't preserve aggregate at all.
@ Strip
Strip all names. No name on declaration is preserved.
std::unique_ptr< mlir::Pass > createInferReadWritePass()
std::unique_ptr< mlir::Pass > createCheckCombLoopsPass()
std::unique_ptr< mlir::Pass > createCheckLayers()
std::unique_ptr< mlir::Pass > createCheckRecursiveInstantiation()
std::unique_ptr< mlir::Pass > createFinalizeIRPass()
std::unique_ptr< mlir::Pass > createLowerFIRRTLTypesPass(PreserveAggregate::PreserveMode mode=PreserveAggregate::None, PreserveAggregate::PreserveMode memoryMode=PreserveAggregate::None)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createResolveTracesPass(mlir::StringRef outputAnnotationFilename="")
std::unique_ptr< mlir::Pass > createResolvePathsPass()
std::unique_ptr< mlir::Pass > createLowerFIRRTLAnnotationsPass(bool ignoreUnhandledAnnotations=false, bool ignoreClasslessAnnotations=false, bool noRefTypePorts=false, bool allowAddingPortsOnPublic=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createLowerSignaturesPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createVBToBVPass()
std::unique_ptr< mlir::Pass > createGrandCentralPass(CompanionMode companionMode=CompanionMode::Bind)
std::unique_ptr< mlir::Pass > createLowerDPIPass()
std::unique_ptr< mlir::Pass > createLowerIntmodulesPass(bool fixupEICGWrapper=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createIMConstPropPass()
std::unique_ptr< mlir::Pass > createBlackBoxReaderPass(std::optional< mlir::StringRef > inputPrefix={})
std::unique_ptr< mlir::Pass > createCreateCompanionAssume()
std::unique_ptr< mlir::Pass > createCreateSiFiveMetadataPass(bool replSeqMem=false, mlir::StringRef replSeqMemFile="")
std::unique_ptr< mlir::Pass > createAdvancedLayerSinkPass()
std::unique_ptr< mlir::Pass > createLayerMergePass()
std::unique_ptr< mlir::Pass > createInlinerPass()
std::unique_ptr< mlir::Pass > createVectorizationPass()
std::unique_ptr< mlir::Pass > createLowerMemoryPass()
std::unique_ptr< mlir::Pass > createDropNamesPass(PreserveValues::PreserveMode mode=PreserveValues::None)
std::unique_ptr< mlir::Pass > createLowerLayersPass()
std::unique_ptr< mlir::Pass > createIMDeadCodeElimPass()
std::unique_ptr< mlir::Pass > createLintingPass()
std::unique_ptr< mlir::Pass > createPassiveWiresPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createExtractInstancesPass()
std::unique_ptr< mlir::Pass > createSpecializeOptionPass(bool selectDefaultInstanceChoice=false)
std::unique_ptr< mlir::Pass > createLayerSinkPass()
std::unique_ptr< mlir::Pass > createSpecializeLayersPass()
std::unique_ptr< mlir::Pass > createLowerCHIRRTLPass()
std::unique_ptr< mlir::Pass > createInnerSymbolDCEPass()
std::unique_ptr< mlir::Pass > createExpandWhensPass()
std::unique_ptr< mlir::Pass > createLowerXMRPass()
std::unique_ptr< mlir::Pass > createLowerIntrinsicsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createInferWidthsPass()
std::unique_ptr< mlir::Pass > createMemToRegOfVecPass(bool replSeqMem=false, bool ignoreReadEnable=false)
std::unique_ptr< mlir::Pass > createLowerOpenAggsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createAssignOutputDirsPass(mlir::StringRef outputDir="")
std::unique_ptr< mlir::Pass > createDropConstPass()
std::unique_ptr< mlir::Pass > createSFCCompatPass()
std::unique_ptr< mlir::Pass > createInjectDUTHierarchyPass()
std::unique_ptr< mlir::Pass > createRandomizeRegisterInitPass()
std::unique_ptr< mlir::Pass > createLowerClassesPass()
std::unique_ptr< mlir::Pass > createAddSeqMemPortsPass()
std::unique_ptr< mlir::Pass > createRegisterOptimizerPass()
std::unique_ptr< mlir::Pass > createLowerMatchesPass()
std::unique_ptr< mlir::Pass > createProbesToSignalsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createMergeConnectionsPass(bool enableAggressiveMerging=false)
std::unique_ptr< mlir::Pass > createInferResetsPass()
std::unique_ptr< mlir::Pass > createFlattenMemoryPass()
std::unique_ptr< mlir::Pass > createMaterializeDebugInfoPass()
std::unique_ptr< mlir::Pass > createFlattenModulesPass()
std::unique_ptr< mlir::Pass > createVerifyInnerRefNamespacePass()
std::unique_ptr< mlir::Pass > createVerifyObjectFieldsPass()
std::unique_ptr< mlir::Pass > createFreezePathsPass(std::function< StringAttr(Operation *)> getOpNameFallback={})
std::unique_ptr< mlir::Pass > createHWMemSimImplPass(const HWMemSimImplOptions &options={})
std::unique_ptr< mlir::Pass > createExternalizeClockGatePass(const ExternalizeClockGateOptions &options={})
std::unique_ptr< mlir::Pass > createHWExportModuleHierarchyPass()
std::unique_ptr< mlir::Pass > createSVExtractTestCodePass(bool disableInstanceExtraction=false, bool disableRegisterExtraction=false, bool disableModuleInlining=false)
std::unique_ptr< mlir::Pass > createHWLegalizeModulesPass()
std::unique_ptr< mlir::Pass > createPrettifyVerilogPass()
std::unique_ptr< mlir::Pass > createHWCleanupPass(bool mergeAlwaysBlocks=true)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::Pass > createExportSplitChiselInterfacePass(mlir::StringRef outputDirectory="./")
std::unique_ptr< mlir::Pass > createExportVerilogPass(std::unique_ptr< llvm::raw_ostream > os)
std::unique_ptr< mlir::Pass > createExportChiselInterfacePass(llvm::raw_ostream &os)
std::unique_ptr< mlir::Pass > createExportSplitVerilogPass(llvm::StringRef directory="./")
std::unique_ptr< mlir::Pass > createConvertHWToBTOR2Pass(llvm::raw_ostream &os)
std::unique_ptr< OperationPass< hw::HWModuleOp > > createLowerVerifToSVPass()
Create the Verif to SV conversion pass.
std::unique_ptr< mlir::Pass > createLowerSeqToSVPass(const LowerSeqToSVOptions &options={})
std::unique_ptr< mlir::Pass > createLowerLTLToCorePass()
std::unique_ptr< mlir::Pass > createLowerFIRRTLToHWPass(bool enableAnnotationWarning=false, firrtl::VerificationFlavor assertionFlavor=firrtl::VerificationFlavor::None)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createLowerSimToSVPass()
std::unique_ptr< Pass > createSimpleCanonicalizerPass()
Create a simple canonicalizer pass.
std::unique_ptr< mlir::Pass > createStripDebugInfoWithPredPass(const std::function< bool(mlir::Location)> &pred)
Creates a pass to strip debug information from a function.
LogicalResult populatePrepareForExportVerilog(mlir::PassManager &pm, const firtool::FirtoolOptions &opt)