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) {
62 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
65 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
69 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
70 mlir::createCSEPass());
72 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
77 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
83 pm.nest<firrtl::CircuitOp>().addPass(
96 pm.nest<firrtl::CircuitOp>().addPass(
113 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
123 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
138 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
144 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
154 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
159 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
165 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
174 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
194 pm.addNestedPass<firrtl::CircuitOp>(
199 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
208 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
210 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
219 pm.nest<firrtl::CircuitOp>().addPass(
223 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
228 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
232 if (outputFilename ==
"-")
235 pm.nest<firrtl::CircuitOp>().addPass(
240 ? llvm::sys::path::parent_path(inputFilename)
242 pm.nest<firrtl::CircuitOp>().addPass(
251 pm.nest<firrtl::CircuitOp>().addPass(
264 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
272 modulePM.addPass(mlir::createCSEPass());
283 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
301 FirtoolOptions::RandomKind::Reg),
309 FirtoolOptions::RandomKind::Mem),
314 ? seq::ReadEnableMode::Ignore
315 : seq::ReadEnableMode::Undefined,
323 modulePM.addPass(mlir::createCSEPass());
325 modulePM.addPass(mlir::createCSEPass());
345 pm.addNestedPass<
hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
356 if (
auto fileLoc = dyn_cast<FileLineColLoc>(loc))
357 return fileLoc.getFilename().getValue().ends_with(
".fir");
363 [](mlir::Location loc) {
return true; }));
381 std::unique_ptr<llvm::raw_ostream> os) {
391 llvm::raw_ostream &os) {
401 llvm::StringRef directory) {
419 llvm::raw_ostream &os) {
421 pm.addNestedPass<
hw::HWModuleOp>(circt::verif::createPrepareForFormalPass());
435 struct FirtoolCmdOptions {
438 llvm::cl::desc(
"Output filename, or directory for split output"),
439 llvm::cl::value_desc(
"filename"),
444 "disable-annotation-unknown",
445 llvm::cl::desc(
"Ignore unknown annotations when parsing"),
446 llvm::cl::init(
false)};
449 "disable-annotation-classless",
450 llvm::cl::desc(
"Ignore annotations without a class when parsing"),
451 llvm::cl::init(
false)};
454 "lower-annotations-no-ref-type-ports",
456 "Create real ports instead of ref type ports when resolving "
457 "wiring problems inside the LowerAnnotations pass"),
458 llvm::cl::init(
false), llvm::cl::Hidden};
461 "allow-adding-ports-on-public-modules",
462 llvm::cl::desc(
"Allow adding ports to public modules"),
463 llvm::cl::init(
false), llvm::cl::Hidden};
467 llvm::cl::desc(
"Convert probes to non-probe signals"),
468 llvm::cl::init(
false), llvm::cl::Hidden};
472 "preserve-aggregate",
473 llvm::cl::desc(
"Specify input file format:"),
476 "Preserve no aggregate"),
478 "Preserve only 1d vectors of ground type"),
480 "Preserve only vectors"),
482 "Preserve vectors and bundles")),
488 llvm::cl::desc(
"Specify the values which can be optimized away"),
491 "Strip all names. No name is preserved"),
492 clEnumValN(firrtl::PreserveValues::None,
"none",
493 "Names could be preserved by best-effort unlike `strip`"),
495 "Preserve values with meaningful names"),
497 "Preserve all values")),
498 llvm::cl::init(firrtl::PreserveValues::None)};
501 "g", llvm::cl::desc(
"Enable the generation of debug information"),
502 llvm::cl::init(
false)};
506 "O", llvm::cl::desc(
"Controls how much optimization should be performed"),
507 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
509 "Compile with only necessary optimizations"),
510 clEnumValN(firtool::FirtoolOptions::BuildModeRelease,
511 "release",
"Compile with optimizations")),
512 llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};
516 llvm::cl::desc(
"Disable optimizations"),
520 "export-chisel-interface",
521 llvm::cl::desc(
"Generate a Scala Chisel interface to the top level "
522 "module of the firrtl circuit"),
523 llvm::cl::init(
false)};
526 "chisel-interface-out-dir",
528 "The output directory for generated Chisel interface files"),
533 llvm::cl::desc(
"Transform vectors of bundles to bundles of vectors"),
534 llvm::cl::init(
false)};
538 llvm::cl::desc(
"Disable deduplication of structurally identical modules"),
539 llvm::cl::init(
false)};
542 "grand-central-companion-mode",
543 llvm::cl::desc(
"Specifies the handling of Grand Central companions"),
545 clEnumValN(firrtl::CompanionMode::Bind,
"bind",
546 "Lower companion instances to SystemVerilog binds"),
547 clEnumValN(firrtl::CompanionMode::Instantiate,
"instantiate",
548 "Instantiate companions in the design"),
549 clEnumValN(firrtl::CompanionMode::Drop,
"drop",
550 "Remove companions from the design")),
551 llvm::cl::init(firrtl::CompanionMode::Bind),
556 "disable-aggressive-merge-connections",
558 "Disable aggressive merge connections (i.e. merge all field-level "
559 "connections into bulk connections)"),
560 llvm::cl::init(
false)};
563 "emit-omir", llvm::cl::desc(
"Emit OMIR annotations to a JSON file"),
564 llvm::cl::init(
true)};
567 "output-omir", llvm::cl::desc(
"File name for the output omir"),
571 "advanced-layer-sink",
572 llvm::cl::desc(
"Sink logic into layer blocks (advanced)"),
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"),
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 "add-companion-assume",
732 llvm::cl::desc(
"Add companion assumes to assertions"),
733 llvm::cl::init(
false)};
737 static llvm::ManagedStatic<FirtoolCmdOptions>
clOptions;
749 : outputFilename(
"-"), disableAnnotationsUnknown(false),
750 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
751 allowAddingPortsOnPublic(false), probesToSignals(false),
752 preserveAggregate(firrtl::PreserveAggregate::None),
753 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
754 buildMode(BuildModeRelease), disableOptimization(false),
756 vbToBV(false), noDedup(false), companionMode(firrtl::
CompanionMode::Bind),
757 disableAggressiveMergeConnections(false), emitOMIR(true), omirOutFile(
""),
758 advancedLayerSink(false), lowerMemories(false), blackBoxRootPath(
""),
759 replSeqMem(false), replSeqMemFile(
""), extractTestCode(false),
760 ignoreReadEnableMem(false), disableRandom(
RandomKind::None),
761 outputAnnotationFilename(
""), enableAnnotationWarning(false),
762 addMuxPragmas(false),
764 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
765 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
766 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
767 ckgModuleName(
"EICG_wrapper"), ckgInputName(
"in"), ckgOutputName(
"out"),
768 ckgEnableName(
"en"), ckgTestEnableName(
"test_en"), ckgInstName(
"ckg"),
769 exportModuleHierarchy(false), stripFirDebugInfo(true),
770 stripDebugInfo(false), fixupEICGWrapper(false),
771 addCompanionAssume(false) {
791 clOptions->disableAggressiveMergeConnections;
811 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 > createEmitOMIRPass(mlir::StringRef outputFilename="")
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 > 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 > createPrefixModulesPass()
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)