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>();
139 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
151 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
156 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
162 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
171 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
191 pm.addNestedPass<firrtl::CircuitOp>(
196 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
205 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
207 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
216 pm.nest<firrtl::CircuitOp>().addPass(
220 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
225 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
229 if (outputFilename ==
"-")
232 pm.nest<firrtl::CircuitOp>().addPass(
237 ? llvm::sys::path::parent_path(inputFilename)
239 pm.nest<firrtl::CircuitOp>().addPass(
248 pm.nest<firrtl::CircuitOp>().addPass(
261 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
269 modulePM.addPass(mlir::createCSEPass());
298 FirtoolOptions::RandomKind::Reg),
306 FirtoolOptions::RandomKind::Mem),
311 ? seq::ReadEnableMode::Ignore
312 : seq::ReadEnableMode::Undefined,
320 modulePM.addPass(mlir::createCSEPass());
322 modulePM.addPass(mlir::createCSEPass());
353 if (
auto fileLoc = dyn_cast<FileLineColLoc>(loc))
354 return fileLoc.getFilename().getValue().ends_with(
".fir");
360 [](mlir::Location loc) {
return true; }));
378 std::unique_ptr<llvm::raw_ostream> os) {
388 llvm::raw_ostream &os) {
398 llvm::StringRef directory) {
416 llvm::raw_ostream &os) {
432 struct FirtoolCmdOptions {
435 llvm::cl::desc(
"Output filename, or directory for split output"),
436 llvm::cl::value_desc(
"filename"),
441 "disable-annotation-unknown",
442 llvm::cl::desc(
"Ignore unknown annotations when parsing"),
443 llvm::cl::init(
false)};
446 "disable-annotation-classless",
447 llvm::cl::desc(
"Ignore annotations without a class when parsing"),
448 llvm::cl::init(
false)};
451 "lower-annotations-no-ref-type-ports",
453 "Create real ports instead of ref type ports when resolving "
454 "wiring problems inside the LowerAnnotations pass"),
455 llvm::cl::init(
false), llvm::cl::Hidden};
458 "allow-adding-ports-on-public-modules",
459 llvm::cl::desc(
"Allow adding ports to public modules"),
460 llvm::cl::init(
false), llvm::cl::Hidden};
464 llvm::cl::desc(
"Convert probes to non-probe signals"),
465 llvm::cl::init(
false), llvm::cl::Hidden};
469 "preserve-aggregate",
470 llvm::cl::desc(
"Specify input file format:"),
473 "Preserve no aggregate"),
475 "Preserve only 1d vectors of ground type"),
477 "Preserve only vectors"),
479 "Preserve vectors and bundles")),
485 llvm::cl::desc(
"Specify the values which can be optimized away"),
488 "Strip all names. No name is preserved"),
489 clEnumValN(firrtl::PreserveValues::None,
"none",
490 "Names could be preserved by best-effort unlike `strip`"),
492 "Preserve values with meaningful names"),
494 "Preserve all values")),
495 llvm::cl::init(firrtl::PreserveValues::None)};
498 "g", llvm::cl::desc(
"Enable the generation of debug information"),
499 llvm::cl::init(
false)};
503 "O", llvm::cl::desc(
"Controls how much optimization should be performed"),
504 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
506 "Compile with only necessary optimizations"),
507 clEnumValN(firtool::FirtoolOptions::BuildModeRelease,
508 "release",
"Compile with optimizations")),
509 llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};
513 llvm::cl::desc(
"Disable optimizations"),
517 "export-chisel-interface",
518 llvm::cl::desc(
"Generate a Scala Chisel interface to the top level "
519 "module of the firrtl circuit"),
520 llvm::cl::init(
false)};
523 "chisel-interface-out-dir",
525 "The output directory for generated Chisel interface files"),
530 llvm::cl::desc(
"Transform vectors of bundles to bundles of vectors"),
531 llvm::cl::init(
false)};
535 llvm::cl::desc(
"Disable deduplication of structurally identical modules"),
536 llvm::cl::init(
false)};
539 "grand-central-companion-mode",
540 llvm::cl::desc(
"Specifies the handling of Grand Central companions"),
542 clEnumValN(firrtl::CompanionMode::Bind,
"bind",
543 "Lower companion instances to SystemVerilog binds"),
544 clEnumValN(firrtl::CompanionMode::Instantiate,
"instantiate",
545 "Instantiate companions in the design"),
546 clEnumValN(firrtl::CompanionMode::Drop,
"drop",
547 "Remove companions from the design")),
548 llvm::cl::init(firrtl::CompanionMode::Bind),
553 "disable-aggressive-merge-connections",
555 "Disable aggressive merge connections (i.e. merge all field-level "
556 "connections into bulk connections)"),
557 llvm::cl::init(
false)};
560 "emit-omir", llvm::cl::desc(
"Emit OMIR annotations to a JSON file"),
561 llvm::cl::init(
true)};
564 "output-omir", llvm::cl::desc(
"File name for the output omir"),
569 llvm::cl::desc(
"Lower memories to have memories with masks as an "
570 "array with one memory per ground type"),
571 llvm::cl::init(
false)};
576 "Optional path to use as the root of black box annotations"),
577 llvm::cl::value_desc(
"path"),
583 llvm::cl::desc(
"Replace the seq mem for macro replacement and emit "
584 "relevant metadata"),
585 llvm::cl::init(
false)};
588 "repl-seq-mem-file", llvm::cl::desc(
"File name for seq mem metadata"),
592 "extract-test-code", llvm::cl::desc(
"Run the extract test code pass"),
593 llvm::cl::init(
false)};
596 "ignore-read-enable-mem",
597 llvm::cl::desc(
"Ignore the read enable signal, instead of "
598 "assigning X on read disable"),
599 llvm::cl::init(
false)};
603 "Disable random initialization code (may break semantics!)"),
605 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
606 "disable-mem-randomization",
607 "Disable emission of memory randomization code"),
608 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
609 "disable-reg-randomization",
610 "Disable emission of register randomization code"),
612 "disable-all-randomization",
613 "Disable emission of all randomization code")),
614 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
617 "output-annotation-file",
618 llvm::cl::desc(
"Optional output annotation file"),
619 llvm::cl::CommaSeparated, llvm::cl::value_desc(
"filename")};
622 "warn-on-unprocessed-annotations",
624 "Warn about annotations that were not removed by lower-to-hw"),
625 llvm::cl::init(
false)};
629 llvm::cl::desc(
"Annotate mux pragmas for memory array access"),
630 llvm::cl::init(
false)};
633 "verification-flavor",
634 llvm::cl::desc(
"Specify a verification flavor used in LowerFIRRTLToHW"),
636 clEnumValN(firrtl::VerificationFlavor::None,
"none",
637 "Use the flavor specified by the op"),
638 clEnumValN(firrtl::VerificationFlavor::IfElseFatal,
"if-else-fatal",
639 "Use Use `if(cond) else $fatal(..)` format"),
640 clEnumValN(firrtl::VerificationFlavor::Immediate,
"immediate",
641 "Use immediate verif statements"),
642 clEnumValN(firrtl::VerificationFlavor::SVA,
"sva",
"Use SVA")),
643 llvm::cl::init(firrtl::VerificationFlavor::None)};
646 "emit-separate-always-blocks",
648 "Prevent always blocks from being merged and emit constructs into "
649 "separate always blocks whenever possible"),
650 llvm::cl::init(
false)};
653 "etc-disable-instance-extraction",
654 llvm::cl::desc(
"Disable extracting instances only that feed test code"),
655 llvm::cl::init(
false)};
658 "etc-disable-register-extraction",
659 llvm::cl::desc(
"Disable extracting registers that only feed test code"),
660 llvm::cl::init(
false)};
663 "etc-disable-module-inlining",
664 llvm::cl::desc(
"Disable inlining modules that only feed test code"),
665 llvm::cl::init(
false)};
668 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
670 "Add a vivado specific SV attribute (* ram_style = "
671 "\"distributed\" *) to unpacked array registers as a workaronud "
672 "for a vivado synthesis bug that incorrectly modifies "
673 "address conflict behavivor of combinational memories"),
674 llvm::cl::init(
false)};
681 "ckg-name", llvm::cl::desc(
"Clock gate module name"),
682 llvm::cl::init(
"EICG_wrapper")};
685 "ckg-input", llvm::cl::desc(
"Clock gate input port name"),
686 llvm::cl::init(
"in")};
689 "ckg-output", llvm::cl::desc(
"Clock gate output port name"),
690 llvm::cl::init(
"out")};
693 "ckg-enable", llvm::cl::desc(
"Clock gate enable port name"),
694 llvm::cl::init(
"en")};
698 llvm::cl::desc(
"Clock gate test enable port name (optional)"),
699 llvm::cl::init(
"test_en")};
702 "export-module-hierarchy",
703 llvm::cl::desc(
"Export module and instance hierarchy as JSON"),
704 llvm::cl::init(
false)};
707 "strip-fir-debug-info",
709 "Disable source fir locator information in output Verilog"),
710 llvm::cl::init(
true)};
714 llvm::cl::desc(
"Disable source locator information in output Verilog"),
715 llvm::cl::init(
false)};
718 "fixup-eicg-wrapper",
719 llvm::cl::desc(
"Lower `EICG_wrapper` modules into clock gate intrinsics"),
720 llvm::cl::init(
false)};
723 "add-companion-assume",
724 llvm::cl::desc(
"Add companion assumes to assertions"),
725 llvm::cl::init(
false)};
729 static llvm::ManagedStatic<FirtoolCmdOptions>
clOptions;
741 : outputFilename(
"-"), disableAnnotationsUnknown(false),
742 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
743 allowAddingPortsOnPublic(false), probesToSignals(false),
744 preserveAggregate(firrtl::PreserveAggregate::None),
745 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
746 buildMode(BuildModeRelease), disableOptimization(false),
748 vbToBV(false), noDedup(false), companionMode(firrtl::
CompanionMode::Bind),
749 disableAggressiveMergeConnections(false), emitOMIR(true), omirOutFile(
""),
750 lowerMemories(false), blackBoxRootPath(
""), replSeqMem(false),
751 replSeqMemFile(
""), extractTestCode(false), ignoreReadEnableMem(false),
752 disableRandom(
RandomKind::None), outputAnnotationFilename(
""),
753 enableAnnotationWarning(false), addMuxPragmas(false),
755 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
756 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
757 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
758 ckgModuleName(
"EICG_wrapper"), ckgInputName(
"in"), ckgOutputName(
"out"),
759 ckgEnableName(
"en"), ckgTestEnableName(
"test_en"), ckgInstName(
"ckg"),
760 exportModuleHierarchy(false), stripFirDebugInfo(true),
761 stripDebugInfo(false), fixupEICGWrapper(false),
762 addCompanionAssume(false) {
782 clOptions->disableAggressiveMergeConnections;
801 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 > 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)
std::unique_ptr< mlir::Pass > createVerifyClockedAssertLikePass()
std::unique_ptr< mlir::Pass > createPrepareForFormalPass()
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)