20#include "mlir/Transforms/Passes.h"
21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/Path.h"
29 pm.nest<firrtl::CircuitOp>().addPass(
30 firrtl::createCheckRecursiveInstantiation());
31 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createCheckLayers());
33 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerOpenAggs());
35 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createResolvePaths());
37 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotations(
44 pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
45 firrtl::createMaterializeDebugInfo());
47 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerIntmodules(
49 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
50 firrtl::createLowerIntrinsics());
59 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeOption(
62 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerSignatures());
68 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInjectDUTHierarchy());
72 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
73 mlir::createCSEPass());
75 pm.nest<firrtl::CircuitOp>().nestAny().addPass(mlir::createCSEPass());
78 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
79 firrtl::createPassiveWires());
81 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
84 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
85 firrtl::createLowerCHIRRTLPass());
89 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
90 firrtl::createLowerMatches());
93 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidths());
95 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createMemToRegOfVec(
99 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResets());
101 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDropConst());
104 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDedup());
107 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypes(
110 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createVBToBV());
114 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
115 firrtl::createFlattenMemory());
120 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypes(
125 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
126 modulePM.addPass(firrtl::createExpandWhens());
127 modulePM.addPass(firrtl::createSFCCompat());
130 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createCheckCombLoops());
134 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeLayers());
138 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createProbesToSignals());
140 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInliner());
142 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
143 firrtl::createLayerMerge());
150 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
151 firrtl::createRandomizeRegisterInit());
155 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
161 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
162 firrtl::createInferReadWrite());
165 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerMemory());
168 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstProp());
170 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createAddSeqMemPorts());
172 pm.addPass(firrtl::createCreateSiFiveMetadata(
179 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstances());
183 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
186 pm.addPass(firrtl::createInnerSymbolDCE());
193 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
194 circt::firrtl::createEliminateWires());
195 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
197 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
198 circt::firrtl::createRegisterOptimizer());
201 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstProp());
202 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
204 pm.addPass(firrtl::createIMDeadCodeElim());
208 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
209 firrtl::createMergeConnections(
214 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
215 firrtl::createVectorization());
222 StringRef inputFilename) {
227 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLayerSink());
232 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMR());
241 pm.nest<firrtl::CircuitOp>().addPass(
244 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
248 if (outputFilename ==
"-")
251 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAssignOutputDirs(
252 {outputFilename.str()}));
260 pm.addNestedPass<firrtl::CircuitOp>(
265 ? llvm::sys::path::parent_path(inputFilename)
267 pm.nest<firrtl::CircuitOp>().addPass(
268 firrtl::createBlackBoxReader({blackBoxRoot.str()}));
272 pm.nest<firrtl::CircuitOp>().addPass(
275 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerDPI());
276 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerClasses());
277 pm.nest<firrtl::CircuitOp>().addPass(om::createVerifyObjectFieldsPass());
280 pm.nest<firrtl::CircuitOp>().addPass(circt::firrtl::createLint(
289 modulePM.addPass(mlir::createCSEPass());
294 pm.addPass(hw::createVerifyInnerRefNamespace());
297 pm.addPass(om::createVerifyObjectFieldsPass());
300 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
307 pm.nestAny().addPass(verif::createStripContractsPass());
308 pm.addPass(verif::createLowerFormalToHWPass());
313 pm.addPass(sv::createSVExtractTestCodePass(
322 FirtoolOptions::RandomKind::Reg),
328 pm.addPass(seq::createHWMemSimImplPass(
330 FirtoolOptions::RandomKind::Mem),
335 ? seq::ReadEnableMode::Ignore
336 : seq::ReadEnableMode::Undefined,
344 modulePM.addPass(mlir::createCSEPass());
346 modulePM.addPass(mlir::createCSEPass());
347 modulePM.addPass(sv::createHWCleanupPass(
352 pm.addPass(hw::createVerifyInnerRefNamespace());
355 pm.addPass(om::createVerifyObjectFieldsPass());
366 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
377 if (
auto fileLoc = dyn_cast<FileLineColLoc>(loc))
378 return fileLoc.getFilename().getValue().ends_with(
".fir");
384 [](mlir::Location loc) {
return true; }));
391 pm.addPass(hw::createVerifyInnerRefNamespace());
402 std::unique_ptr<llvm::raw_ostream> os) {
412 llvm::raw_ostream &os) {
422 llvm::StringRef directory) {
432 pm.addPass(firrtl::createFinalizeIR());
433 pm.addPass(om::createFreezePathsPass());
440 llvm::raw_ostream &os) {
442 pm.addNestedPass<
hw::HWModuleOp>(circt::verif::createPrepareForFormalPass());
443 pm.addPass(circt::hw::createFlattenModules());
456struct FirtoolCmdOptions {
459 llvm::cl::desc(
"Output filename, or directory for split output"),
460 llvm::cl::value_desc(
"filename"),
465 "disable-annotation-unknown",
466 llvm::cl::desc(
"Ignore unknown annotations when parsing"),
467 llvm::cl::init(
false)};
470 "disable-annotation-classless",
471 llvm::cl::desc(
"Ignore annotations without a class when parsing"),
472 llvm::cl::init(
false)};
475 "lower-annotations-no-ref-type-ports",
477 "Create real ports instead of ref type ports when resolving "
478 "wiring problems inside the LowerAnnotations pass"),
479 llvm::cl::init(
false), llvm::cl::Hidden};
482 "allow-adding-ports-on-public-modules",
483 llvm::cl::desc(
"Allow adding ports to public modules"),
484 llvm::cl::init(
false), llvm::cl::Hidden};
488 llvm::cl::desc(
"Convert probes to non-probe signals"),
489 llvm::cl::init(
false), llvm::cl::Hidden};
493 "preserve-aggregate",
494 llvm::cl::desc(
"Specify input file format:"),
497 "Preserve no aggregate"),
499 "Preserve only 1d vectors of ground type"),
501 "Preserve only vectors"),
503 "Preserve vectors and bundles")),
509 llvm::cl::desc(
"Specify the values which can be optimized away"),
512 "Strip all names. No name is preserved"),
514 "Names could be preserved by best-effort unlike `strip`"),
516 "Preserve values with meaningful names"),
518 "Preserve all values")),
522 "g", llvm::cl::desc(
"Enable the generation of debug information"),
523 llvm::cl::init(
false)};
527 "O", llvm::cl::desc(
"Controls how much optimization should be performed"),
530 "Compile with only necessary optimizations"),
532 "release",
"Compile with optimizations")),
536 llvm::cl::desc(
"Disable layer sink"),
541 llvm::cl::desc(
"Disable optimizations"),
546 llvm::cl::desc(
"Transform vectors of bundles to bundles of vectors"),
547 llvm::cl::init(
false)};
551 llvm::cl::desc(
"Disable deduplication of structurally identical modules"),
552 llvm::cl::init(
false)};
555 "grand-central-companion-mode",
556 llvm::cl::desc(
"Specifies the handling of Grand Central companions"),
558 clEnumValN(firrtl::CompanionMode::Bind,
"bind",
559 "Lower companion instances to SystemVerilog binds"),
560 clEnumValN(firrtl::CompanionMode::Instantiate,
"instantiate",
561 "Instantiate companions in the design"),
562 clEnumValN(firrtl::CompanionMode::Drop,
"drop",
563 "Remove companions from the design")),
564 llvm::cl::init(firrtl::CompanionMode::Bind),
569 "disable-aggressive-merge-connections",
571 "Disable aggressive merge connections (i.e. merge all field-level "
572 "connections into bulk connections)"),
573 llvm::cl::init(
false)};
577 llvm::cl::desc(
"Lower memories to have memories with masks as an "
578 "array with one memory per ground type"),
579 llvm::cl::init(
false)};
584 "Optional path to use as the root of black box annotations"),
585 llvm::cl::value_desc(
"path"),
591 llvm::cl::desc(
"Replace the seq mem for macro replacement and emit "
592 "relevant metadata"),
593 llvm::cl::init(
false)};
596 "repl-seq-mem-file", llvm::cl::desc(
"File name for seq mem metadata"),
600 "extract-test-code", llvm::cl::desc(
"Run the extract test code pass"),
601 llvm::cl::init(
false)};
604 "ignore-read-enable-mem",
605 llvm::cl::desc(
"Ignore the read enable signal, instead of "
606 "assigning X on read disable"),
607 llvm::cl::init(
false)};
611 "Disable random initialization code (may break semantics!)"),
613 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
614 "disable-mem-randomization",
615 "Disable emission of memory randomization code"),
616 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
617 "disable-reg-randomization",
618 "Disable emission of register randomization code"),
619 clEnumValN(firtool::FirtoolOptions::RandomKind::All,
620 "disable-all-randomization",
621 "Disable emission of all randomization code")),
622 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
625 "output-annotation-file",
626 llvm::cl::desc(
"Optional output annotation file"),
627 llvm::cl::CommaSeparated, llvm::cl::value_desc(
"filename")};
630 "warn-on-unprocessed-annotations",
632 "Warn about annotations that were not removed by lower-to-hw"),
633 llvm::cl::init(
false)};
637 llvm::cl::desc(
"Annotate mux pragmas for memory array access"),
638 llvm::cl::init(
false)};
641 "verification-flavor",
642 llvm::cl::desc(
"Specify a verification flavor used in LowerFIRRTLToHW"),
644 clEnumValN(firrtl::VerificationFlavor::None,
"none",
645 "Use the flavor specified by the op"),
646 clEnumValN(firrtl::VerificationFlavor::IfElseFatal,
"if-else-fatal",
647 "Use Use `if(cond) else $fatal(..)` format"),
648 clEnumValN(firrtl::VerificationFlavor::Immediate,
"immediate",
649 "Use immediate verif statements"),
650 clEnumValN(firrtl::VerificationFlavor::SVA,
"sva",
"Use SVA")),
651 llvm::cl::init(firrtl::VerificationFlavor::None)};
654 "emit-separate-always-blocks",
656 "Prevent always blocks from being merged and emit constructs into "
657 "separate always blocks whenever possible"),
658 llvm::cl::init(
false)};
661 "etc-disable-instance-extraction",
662 llvm::cl::desc(
"Disable extracting instances only that feed test code"),
663 llvm::cl::init(
false)};
666 "etc-disable-register-extraction",
667 llvm::cl::desc(
"Disable extracting registers that only feed test code"),
668 llvm::cl::init(
false)};
671 "etc-disable-module-inlining",
672 llvm::cl::desc(
"Disable inlining modules that only feed test code"),
673 llvm::cl::init(
false)};
676 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
678 "Add a vivado specific SV attribute (* ram_style = "
679 "\"distributed\" *) to unpacked array registers as a workaronud "
680 "for a vivado synthesis bug that incorrectly modifies "
681 "address conflict behavivor of combinational memories"),
682 llvm::cl::init(
false)};
689 "ckg-name", llvm::cl::desc(
"Clock gate module name"),
690 llvm::cl::init(
"EICG_wrapper")};
693 "ckg-input", llvm::cl::desc(
"Clock gate input port name"),
694 llvm::cl::init(
"in")};
697 "ckg-output", llvm::cl::desc(
"Clock gate output port name"),
698 llvm::cl::init(
"out")};
701 "ckg-enable", llvm::cl::desc(
"Clock gate enable port name"),
702 llvm::cl::init(
"en")};
706 llvm::cl::desc(
"Clock gate test enable port name (optional)"),
707 llvm::cl::init(
"test_en")};
710 "export-module-hierarchy",
711 llvm::cl::desc(
"Export module and instance hierarchy as JSON"),
712 llvm::cl::init(
false)};
715 "strip-fir-debug-info",
717 "Disable source fir locator information in output Verilog"),
718 llvm::cl::init(
true)};
722 llvm::cl::desc(
"Disable source locator information in output Verilog"),
723 llvm::cl::init(
false)};
726 "fixup-eicg-wrapper",
727 llvm::cl::desc(
"Lower `EICG_wrapper` modules into clock gate intrinsics"),
728 llvm::cl::init(
false)};
731 "select-default-for-unspecified-instance-choice",
733 "Specialize instance choice to default, if no option selected"),
734 llvm::cl::init(
false)};
738 llvm::cl::desc(
"Control how symbolic values are lowered"),
739 llvm::cl::init(verif::SymbolicValueLowering::ExtModule),
740 verif::symbolicValueLoweringCLValues()};
743 "disable-wire-elimination", llvm::cl::desc(
"Disable wire elimination"),
744 llvm::cl::init(
false)};
747 "emit-all-bind-files",
748 llvm::cl::desc(
"Emit bindfiles for private modules"),
749 llvm::cl::init(
false)};
756 "lint-static-asserts", llvm::cl::desc(
"Lint static assertions"),
757 llvm::cl::init(
true)};
761 "lint-xmrs-in-design", llvm::cl::desc(
"Lint XMRs in the design"),
762 llvm::cl::init(
false)};
778 : outputFilename(
"-"), disableAnnotationsUnknown(false),
779 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
780 allowAddingPortsOnPublic(false), probesToSignals(false),
781 preserveAggregate(firrtl::PreserveAggregate::None),
782 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
783 buildMode(BuildModeRelease), disableLayerSink(false),
784 disableOptimization(false), vbToBV(false), noDedup(false),
785 companionMode(firrtl::CompanionMode::Bind),
786 disableAggressiveMergeConnections(false), lowerMemories(false),
787 blackBoxRootPath(
""), replSeqMem(false), replSeqMemFile(
""),
788 extractTestCode(false), ignoreReadEnableMem(false),
789 disableRandom(
RandomKind::None), outputAnnotationFilename(
""),
790 enableAnnotationWarning(false), addMuxPragmas(false),
791 verificationFlavor(firrtl::VerificationFlavor::None),
792 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
793 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
794 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
795 ckgModuleName(
"EICG_wrapper"), ckgInputName(
"in"), ckgOutputName(
"out"),
796 ckgEnableName(
"en"), ckgTestEnableName(
"test_en"), ckgInstName(
"ckg"),
797 exportModuleHierarchy(false), stripFirDebugInfo(true),
798 stripDebugInfo(false), fixupEICGWrapper(false),
799 disableCSEinClasses(false), selectDefaultInstanceChoice(false),
800 symbolicValueLowering(
verif::SymbolicValueLowering::ExtModule),
801 disableWireElimination(false), lintStaticAsserts(true),
802 lintXmrsInDesign(true), emitAllBindFiles(false) {
821 clOptions->disableAggressiveMergeConnections;
838 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
@ 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.
@ None
Don't explicitly preserve any named values.
@ Strip
Strip all names. No name on declaration is preserved.
std::unique_ptr< mlir::Pass > createVerifyObjectFieldsPass()
std::unique_ptr< mlir::Pass > createHWExportModuleHierarchyPass()
std::unique_ptr< mlir::Pass > createHWLegalizeModulesPass()
std::unique_ptr< mlir::Pass > createPrettifyVerilogPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::Pass > createExportSplitVerilogPass(llvm::StringRef directory="./")
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 > createConvertHWToBTOR2Pass()
std::unique_ptr< mlir::Pass > createExportVerilogPass()
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)