CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Firtool.cpp
Go to the documentation of this file.
1//===- Firtool.cpp - Definitions for the firtool pipeline setup -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
20#include "mlir/Transforms/Passes.h"
21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/Path.h"
23
24using namespace llvm;
25using namespace circt;
26
27LogicalResult firtool::populatePreprocessTransforms(mlir::PassManager &pm,
28 const FirtoolOptions &opt) {
29 pm.nest<firrtl::CircuitOp>().addPass(
31 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createCheckLayers());
32 // Legalize away "open" aggregates to hw-only versions.
33 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerOpenAggsPass());
34
35 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createResolvePathsPass());
36
37 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotationsPass(
42
43 if (opt.shouldEnableDebugInfo())
44 pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
46
47 pm.nest<firrtl::CircuitOp>().addPass(
49 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
51
52 return success();
53}
54
55LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
56 const FirtoolOptions &opt,
57 StringRef inputFilename) {
58 // TODO: Ensure instance graph and other passes can handle instance choice
59 // then run this pass after all diagnostic passes have run.
60 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeOptionPass(
62 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerSignaturesPass());
63
64 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInjectDUTHierarchyPass());
65
66 if (!opt.shouldDisableOptimization()) {
68 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
69 mlir::createCSEPass());
70 else
71 pm.nest<firrtl::CircuitOp>().nestAny().addPass(mlir::createCSEPass());
72 }
73
74 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
76
77 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
79
80 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
82
83 // Run LowerMatches before InferWidths, as the latter does not support the
84 // match statement, but it does support what they lower to.
85 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
87
88 // Width inference creates canonicalization opportunities.
89 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidthsPass());
90
91 pm.nest<firrtl::CircuitOp>().addPass(
94
95 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResetsPass());
96
98 StringRef outdir = opt.getChiselInterfaceOutputDirectory();
99 if (opt.isDefaultOutputFilename() && outdir.empty()) {
100 pm.nest<firrtl::CircuitOp>().addPass(createExportChiselInterfacePass());
101 } else {
102 if (outdir.empty())
103 outdir = opt.getOutputFilename();
104 pm.nest<firrtl::CircuitOp>().addPass(
106 }
107 }
108
109 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDropConstPass());
110
111 if (opt.shouldDedup())
112 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDedupPass());
113
114 if (opt.shouldConvertVecOfBundle()) {
115 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
117 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createVBToBVPass());
118 }
119
120 if (!opt.shouldLowerMemories())
121 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
123
124 // The input mlir file could be firrtl dialect so we might need to clean
125 // things up.
126 // pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerSignaturesPass());
127 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
129
130 {
131 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
132 modulePM.addPass(firrtl::createExpandWhensPass());
133 modulePM.addPass(firrtl::createSFCCompatPass());
134 }
135
136 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createCheckCombLoopsPass());
137
138 // Must run this pass after all diagnostic passes have run, otherwise it can
139 // hide errors.
140 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeLayersPass());
141
142 // Run after inference, layer specialization.
144 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createProbesToSignalsPass());
145
146 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInlinerPass());
147
148 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
150
151 // Preset the random initialization parameters for each module. The current
152 // implementation assumes it can run at a time where every register is
153 // currently in the final module it will be emitted in, all registers have
154 // been created, and no registers have yet been removed.
155 if (opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg))
156 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
158
159 // If we parsed a FIRRTL file and have optimizations enabled, clean it up.
160 if (!opt.shouldDisableOptimization())
161 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
163
164 // Run the infer-rw pass, which merges read and write ports of a memory with
165 // mutually exclusive enables.
166 if (!opt.shouldDisableOptimization())
167 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
169
171 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerMemoryPass());
172
173 if (opt.shouldAddCompanionAssume())
174 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
176
177 if (!opt.shouldDisableOptimization())
178 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
179
180 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createAddSeqMemPortsPass());
181
185
186 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstancesPass());
187
188 // Run SymbolDCE as late as possible, but before InnerSymbolDCE. This is for
189 // hierpathop's and just for general cleanup.
190 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
191
192 // Run InnerSymbolDCE as late as possible, but before IMDCE.
194
195 // The above passes, IMConstProp in particular, introduce additional
196 // canonicalization opportunities that we should pick up here before we
197 // proceed to output-specific pipelines.
198 if (!opt.shouldDisableOptimization()) {
199 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
201 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
203 // Re-run IMConstProp to propagate constants produced by register
204 // optimizations.
205 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
206 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
209 }
210
211 // Always run this, required for legalization.
212 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
215
216 if (!opt.shouldDisableOptimization())
217 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
219
220 // Layer lowering passes. Move operations into layers when possible and
221 // remove layers by converting them to other constructs. This lowering
222 // process can create a few optimization opportunities.
223 //
224 // TODO: Improve LowerLayers to avoid the need for canonicalization. See:
225 // https://github.com/llvm/circt/issues/7896
226 if (!opt.shouldDisableLayerSink()) {
227 if (opt.shouldAdvancedLayerSink())
228 pm.nest<firrtl::CircuitOp>().addPass(
230 else
231 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
233 }
234 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
235 if (!opt.shouldDisableOptimization())
236 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
238
239 auto outputFilename = opt.getOutputFilename();
240 if (outputFilename == "-")
241 outputFilename = "";
242
243 pm.nest<firrtl::CircuitOp>().addPass(
244 firrtl::createAssignOutputDirsPass(outputFilename));
245
246 // Run passes to resolve Grand Central features. This should run before
247 // BlackBoxReader because Grand Central needs to inform BlackBoxReader where
248 // certain black boxes should be placed. Note: all Grand Central Taps related
249 // collateral is resolved entirely by LowerAnnotations.
250 // Run this after output directories are (otherwise) assigned,
251 // so generated interfaces can be appropriately marked.
252 pm.addNestedPass<firrtl::CircuitOp>(
254
255 // Read black box source files into the IR.
256 StringRef blackBoxRoot = opt.getBlackBoxRootPath().empty()
257 ? llvm::sys::path::parent_path(inputFilename)
258 : opt.getBlackBoxRootPath();
259 pm.nest<firrtl::CircuitOp>().addPass(
261 return success();
262}
263
264LogicalResult firtool::populateLowFIRRTLToHW(mlir::PassManager &pm,
265 const FirtoolOptions &opt) {
266 // Remove TraceAnnotations and write their updated paths to an output
267 // annotation file.
268 pm.nest<firrtl::CircuitOp>().addPass(
270
271 // Lower the ref.resolve and ref.send ops and remove the RefType ports.
272 // LowerToHW cannot handle RefType so, this pass must be run to remove all
273 // RefType ports and ops.
274 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMRPass());
275
276 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerDPIPass());
277 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerClassesPass());
278 pm.nest<firrtl::CircuitOp>().addPass(om::createVerifyObjectFieldsPass());
279
280 // Check for static asserts.
281 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
283
285 opt.getVerificationFlavor()));
286
287 if (!opt.shouldDisableOptimization()) {
288 auto &modulePM = pm.nest<hw::HWModuleOp>();
289 modulePM.addPass(mlir::createCSEPass());
290 modulePM.addPass(createSimpleCanonicalizerPass());
291 }
292
293 // Check inner symbols and inner refs.
294 pm.addPass(hw::createVerifyInnerRefNamespacePass());
295
296 // Check OM object fields.
297 pm.addPass(om::createVerifyObjectFieldsPass());
298
299 // Run the verif op verification pass
300 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
301
302 return success();
303}
304
305LogicalResult firtool::populateHWToSV(mlir::PassManager &pm,
306 const FirtoolOptions &opt) {
307 pm.nestAny().addPass(verif::createStripContractsPass());
308 pm.addPass(verif::createLowerFormalToHWPass());
309 pm.addPass(
310 verif::createLowerSymbolicValuesPass({opt.getSymbolicValueLowering()}));
311
312 if (opt.shouldExtractTestCode())
313 pm.addPass(sv::createSVExtractTestCodePass(
317
318 pm.addPass(seq::createExternalizeClockGatePass(opt.getClockGateOptions()));
319 pm.addPass(circt::createLowerSimToSVPass());
321 {/*disableRegRandomization=*/!opt.isRandomEnabled(
322 FirtoolOptions::RandomKind::Reg),
323 /*disableMemRandomization=*/
324 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
325 /*emitSeparateAlwaysBlocks=*/
327 pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
328 pm.addPass(seq::createHWMemSimImplPass(
329 {/*disableMemRandomization=*/!opt.isRandomEnabled(
330 FirtoolOptions::RandomKind::Mem),
331 /*disableRegRandomization=*/
332 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
333 /*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
334 /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
335 ? seq::ReadEnableMode::Ignore
336 : seq::ReadEnableMode::Undefined,
337 /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
338 /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
340
341 // If enabled, run the optimizer.
342 if (!opt.shouldDisableOptimization()) {
343 auto &modulePM = pm.nest<hw::HWModuleOp>();
344 modulePM.addPass(mlir::createCSEPass());
345 modulePM.addPass(createSimpleCanonicalizerPass());
346 modulePM.addPass(mlir::createCSEPass());
347 modulePM.addPass(sv::createHWCleanupPass(
348 /*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()));
349 }
350
351 // Check inner symbols and inner refs.
352 pm.addPass(hw::createVerifyInnerRefNamespacePass());
353
354 // Check OM object fields.
355 pm.addPass(om::createVerifyObjectFieldsPass());
356
357 return success();
358}
359
360namespace detail {
361LogicalResult
363 const firtool::FirtoolOptions &opt) {
364
365 // Run the verif op verification pass
366 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
367
368 // Legalize unsupported operations within the modules.
370
371 // Tidy up the IR to improve verilog emission quality.
372 if (!opt.shouldDisableOptimization())
373 pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilogPass());
374
375 if (opt.shouldStripFirDebugInfo())
376 pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
377 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc))
378 return fileLoc.getFilename().getValue().ends_with(".fir");
379 return false;
380 }));
381
382 if (opt.shouldStripDebugInfo())
384 [](mlir::Location loc) { return true; }));
385
386 // Emit module and testbench hierarchy JSON files.
389
390 // Check inner symbols and inner refs.
392
393 // Check OM object fields.
395
396 return success();
397}
398} // namespace detail
399
400LogicalResult
401firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
402 std::unique_ptr<llvm::raw_ostream> os) {
404 return failure();
405
406 pm.addPass(createExportVerilogPass(std::move(os)));
407 return success();
408}
409
410LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
411 const FirtoolOptions &opt,
412 llvm::raw_ostream &os) {
414 return failure();
415
416 pm.addPass(createExportVerilogPass(os));
417 return success();
418}
419
420LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
421 const FirtoolOptions &opt,
422 llvm::StringRef directory) {
424 return failure();
425
426 pm.addPass(createExportSplitVerilogPass(directory));
427 return success();
428}
429
430LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
431 const FirtoolOptions &opt) {
432 pm.addPass(firrtl::createFinalizeIRPass());
433 pm.addPass(om::createFreezePathsPass());
434
435 return success();
436}
437
438LogicalResult firtool::populateHWToBTOR2(mlir::PassManager &pm,
439 const FirtoolOptions &opt,
440 llvm::raw_ostream &os) {
442 pm.addNestedPass<hw::HWModuleOp>(circt::verif::createPrepareForFormalPass());
444 pm.addPass(circt::createConvertHWToBTOR2Pass(os));
445 return success();
446}
447
448//===----------------------------------------------------------------------===//
449// FIRTOOL CommandLine Options
450//===----------------------------------------------------------------------===//
451
452namespace {
453/// This struct contains command line options that can be used to initialize
454/// various bits of a Firtool pipeline. This uses a struct wrapper to avoid the
455/// need for global command line options.
456struct FirtoolCmdOptions {
457 llvm::cl::opt<std::string> outputFilename{
458 "o",
459 llvm::cl::desc("Output filename, or directory for split output"),
460 llvm::cl::value_desc("filename"),
461 llvm::cl::init("-"),
462 };
463
464 llvm::cl::opt<bool> disableAnnotationsUnknown{
465 "disable-annotation-unknown",
466 llvm::cl::desc("Ignore unknown annotations when parsing"),
467 llvm::cl::init(false)};
468
469 llvm::cl::opt<bool> disableAnnotationsClassless{
470 "disable-annotation-classless",
471 llvm::cl::desc("Ignore annotations without a class when parsing"),
472 llvm::cl::init(false)};
473
474 llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
475 "lower-annotations-no-ref-type-ports",
476 llvm::cl::desc(
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};
480
481 llvm::cl::opt<bool> allowAddingPortsOnPublic{
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};
485
486 llvm::cl::opt<bool> probesToSignals{
487 "probes-to-signals",
488 llvm::cl::desc("Convert probes to non-probe signals"),
489 llvm::cl::init(false), llvm::cl::Hidden};
490
492 preserveAggregate{
493 "preserve-aggregate",
494 llvm::cl::desc("Specify input file format:"),
495 llvm::cl::values(
497 "Preserve no aggregate"),
499 "Preserve only 1d vectors of ground type"),
501 "Preserve only vectors"),
503 "Preserve vectors and bundles")),
505 };
506
508 "preserve-values",
509 llvm::cl::desc("Specify the values which can be optimized away"),
510 llvm::cl::values(
511 clEnumValN(firrtl::PreserveValues::Strip, "strip",
512 "Strip all names. No name is preserved"),
513 clEnumValN(firrtl::PreserveValues::None, "none",
514 "Names could be preserved by best-effort unlike `strip`"),
515 clEnumValN(firrtl::PreserveValues::Named, "named",
516 "Preserve values with meaningful names"),
517 clEnumValN(firrtl::PreserveValues::All, "all",
518 "Preserve all values")),
519 llvm::cl::init(firrtl::PreserveValues::None)};
520
521 llvm::cl::opt<bool> enableDebugInfo{
522 "g", llvm::cl::desc("Enable the generation of debug information"),
523 llvm::cl::init(false)};
524
525 // Build mode options.
527 "O", llvm::cl::desc("Controls how much optimization should be performed"),
528 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
529 "debug",
530 "Compile with only necessary optimizations"),
532 "release", "Compile with optimizations")),
534
535 llvm::cl::opt<bool> disableLayerSink{"disable-layer-sink",
536 llvm::cl::desc("Disable layer sink"),
537 cl::init(false)};
538
539 llvm::cl::opt<bool> disableOptimization{
540 "disable-opt",
541 llvm::cl::desc("Disable optimizations"),
542 };
543
544 llvm::cl::opt<bool> exportChiselInterface{
545 "export-chisel-interface",
546 llvm::cl::desc("Generate a Scala Chisel interface to the top level "
547 "module of the firrtl circuit"),
548 llvm::cl::init(false)};
549
550 llvm::cl::opt<std::string> chiselInterfaceOutDirectory{
551 "chisel-interface-out-dir",
552 llvm::cl::desc(
553 "The output directory for generated Chisel interface files"),
554 llvm::cl::init("")};
555
556 llvm::cl::opt<bool> vbToBV{
557 "vb-to-bv",
558 llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
559 llvm::cl::init(false)};
560
561 llvm::cl::opt<bool> noDedup{
562 "no-dedup",
563 llvm::cl::desc("Disable deduplication of structurally identical modules"),
564 llvm::cl::init(false)};
565
567 "grand-central-companion-mode",
568 llvm::cl::desc("Specifies the handling of Grand Central companions"),
569 ::llvm::cl::values(
570 clEnumValN(firrtl::CompanionMode::Bind, "bind",
571 "Lower companion instances to SystemVerilog binds"),
572 clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
573 "Instantiate companions in the design"),
574 clEnumValN(firrtl::CompanionMode::Drop, "drop",
575 "Remove companions from the design")),
576 llvm::cl::init(firrtl::CompanionMode::Bind),
577 llvm::cl::Hidden,
578 };
579
580 llvm::cl::opt<bool> disableAggressiveMergeConnections{
581 "disable-aggressive-merge-connections",
582 llvm::cl::desc(
583 "Disable aggressive merge connections (i.e. merge all field-level "
584 "connections into bulk connections)"),
585 llvm::cl::init(false)};
586
587 llvm::cl::opt<bool> advancedLayerSink{
588 "advanced-layer-sink",
589 llvm::cl::desc("Sink logic into layer blocks (advanced)"),
590 llvm::cl::init(false)};
591
592 llvm::cl::opt<bool> lowerMemories{
593 "lower-memories",
594 llvm::cl::desc("Lower memories to have memories with masks as an "
595 "array with one memory per ground type"),
596 llvm::cl::init(false)};
597
598 llvm::cl::opt<std::string> blackBoxRootPath{
599 "blackbox-path",
600 llvm::cl::desc(
601 "Optional path to use as the root of black box annotations"),
602 llvm::cl::value_desc("path"),
603 llvm::cl::init(""),
604 };
605
606 llvm::cl::opt<bool> replSeqMem{
607 "repl-seq-mem",
608 llvm::cl::desc("Replace the seq mem for macro replacement and emit "
609 "relevant metadata"),
610 llvm::cl::init(false)};
611
612 llvm::cl::opt<std::string> replSeqMemFile{
613 "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
614 llvm::cl::init("")};
615
616 llvm::cl::opt<bool> extractTestCode{
617 "extract-test-code", llvm::cl::desc("Run the extract test code pass"),
618 llvm::cl::init(false)};
619
620 llvm::cl::opt<bool> ignoreReadEnableMem{
621 "ignore-read-enable-mem",
622 llvm::cl::desc("Ignore the read enable signal, instead of "
623 "assigning X on read disable"),
624 llvm::cl::init(false)};
625
627 llvm::cl::desc(
628 "Disable random initialization code (may break semantics!)"),
629 llvm::cl::values(
630 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
631 "disable-mem-randomization",
632 "Disable emission of memory randomization code"),
633 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
634 "disable-reg-randomization",
635 "Disable emission of register randomization code"),
636 clEnumValN(firtool::FirtoolOptions::RandomKind::All,
637 "disable-all-randomization",
638 "Disable emission of all randomization code")),
639 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
640
641 llvm::cl::opt<std::string> outputAnnotationFilename{
642 "output-annotation-file",
643 llvm::cl::desc("Optional output annotation file"),
644 llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
645
646 llvm::cl::opt<bool> enableAnnotationWarning{
647 "warn-on-unprocessed-annotations",
648 llvm::cl::desc(
649 "Warn about annotations that were not removed by lower-to-hw"),
650 llvm::cl::init(false)};
651
652 llvm::cl::opt<bool> addMuxPragmas{
653 "add-mux-pragmas",
654 llvm::cl::desc("Annotate mux pragmas for memory array access"),
655 llvm::cl::init(false)};
656
658 "verification-flavor",
659 llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
660 llvm::cl::values(
661 clEnumValN(firrtl::VerificationFlavor::None, "none",
662 "Use the flavor specified by the op"),
663 clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
664 "Use Use `if(cond) else $fatal(..)` format"),
665 clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
666 "Use immediate verif statements"),
667 clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
668 llvm::cl::init(firrtl::VerificationFlavor::None)};
669
670 llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
671 "emit-separate-always-blocks",
672 llvm::cl::desc(
673 "Prevent always blocks from being merged and emit constructs into "
674 "separate always blocks whenever possible"),
675 llvm::cl::init(false)};
676
677 llvm::cl::opt<bool> etcDisableInstanceExtraction{
678 "etc-disable-instance-extraction",
679 llvm::cl::desc("Disable extracting instances only that feed test code"),
680 llvm::cl::init(false)};
681
682 llvm::cl::opt<bool> etcDisableRegisterExtraction{
683 "etc-disable-register-extraction",
684 llvm::cl::desc("Disable extracting registers that only feed test code"),
685 llvm::cl::init(false)};
686
687 llvm::cl::opt<bool> etcDisableModuleInlining{
688 "etc-disable-module-inlining",
689 llvm::cl::desc("Disable inlining modules that only feed test code"),
690 llvm::cl::init(false)};
691
692 llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
693 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
694 llvm::cl::desc(
695 "Add a vivado specific SV attribute (* ram_style = "
696 "\"distributed\" *) to unpacked array registers as a workaronud "
697 "for a vivado synthesis bug that incorrectly modifies "
698 "address conflict behavivor of combinational memories"),
699 llvm::cl::init(false)};
700
701 //===----------------------------------------------------------------------===
702 // External Clock Gate Options
703 //===----------------------------------------------------------------------===
704
705 llvm::cl::opt<std::string> ckgModuleName{
706 "ckg-name", llvm::cl::desc("Clock gate module name"),
707 llvm::cl::init("EICG_wrapper")};
708
709 llvm::cl::opt<std::string> ckgInputName{
710 "ckg-input", llvm::cl::desc("Clock gate input port name"),
711 llvm::cl::init("in")};
712
713 llvm::cl::opt<std::string> ckgOutputName{
714 "ckg-output", llvm::cl::desc("Clock gate output port name"),
715 llvm::cl::init("out")};
716
717 llvm::cl::opt<std::string> ckgEnableName{
718 "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
719 llvm::cl::init("en")};
720
721 llvm::cl::opt<std::string> ckgTestEnableName{
722 "ckg-test-enable",
723 llvm::cl::desc("Clock gate test enable port name (optional)"),
724 llvm::cl::init("test_en")};
725
726 llvm::cl::opt<bool> exportModuleHierarchy{
727 "export-module-hierarchy",
728 llvm::cl::desc("Export module and instance hierarchy as JSON"),
729 llvm::cl::init(false)};
730
731 llvm::cl::opt<bool> stripFirDebugInfo{
732 "strip-fir-debug-info",
733 llvm::cl::desc(
734 "Disable source fir locator information in output Verilog"),
735 llvm::cl::init(true)};
736
737 llvm::cl::opt<bool> stripDebugInfo{
738 "strip-debug-info",
739 llvm::cl::desc("Disable source locator information in output Verilog"),
740 llvm::cl::init(false)};
741
742 llvm::cl::opt<bool> fixupEICGWrapper{
743 "fixup-eicg-wrapper",
744 llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
745 llvm::cl::init(false)};
746
747 llvm::cl::opt<bool> addCompanionAssume{
748 "add-companion-assume",
749 llvm::cl::desc("Add companion assumes to assertions"),
750 llvm::cl::init(false)};
751
752 llvm::cl::opt<bool> selectDefaultInstanceChoice{
753 "select-default-for-unspecified-instance-choice",
754 llvm::cl::desc(
755 "Specialize instance choice to default, if no option selected"),
756 llvm::cl::init(false)};
757
759 "symbolic-values",
760 llvm::cl::desc("Control how symbolic values are lowered"),
761 llvm::cl::init(verif::SymbolicValueLowering::ExtModule),
762 verif::symbolicValueLoweringCLValues()};
763};
764} // namespace
765
766static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
767
768/// Register a set of useful command-line options that can be used to configure
769/// various flags within the MLIRContext. These flags are used when constructing
770/// an MLIR context for initialization.
772 // Make sure that the options struct has been initialized.
773 *clOptions;
774}
775
776// Initialize the firtool options with defaults supplied by the cl::opts above.
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), exportChiselInterface(false),
785 chiselInterfaceOutDirectory(""), vbToBV(false), noDedup(false),
786 companionMode(firrtl::CompanionMode::Bind),
787 disableAggressiveMergeConnections(false), advancedLayerSink(false),
788 lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
789 replSeqMemFile(""), extractTestCode(false), ignoreReadEnableMem(false),
790 disableRandom(RandomKind::None), outputAnnotationFilename(""),
791 enableAnnotationWarning(false), addMuxPragmas(false),
792 verificationFlavor(firrtl::VerificationFlavor::None),
793 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
794 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
795 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
796 ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
797 ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
798 exportModuleHierarchy(false), stripFirDebugInfo(true),
799 stripDebugInfo(false), fixupEICGWrapper(false), addCompanionAssume(false),
800 disableCSEinClasses(false), selectDefaultInstanceChoice(false) {
801 if (!clOptions.isConstructed())
802 return;
803 outputFilename = clOptions->outputFilename;
804 disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
805 disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
806 lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
807 allowAddingPortsOnPublic = clOptions->allowAddingPortsOnPublic;
808 probesToSignals = clOptions->probesToSignals;
809 preserveAggregate = clOptions->preserveAggregate;
810 preserveMode = clOptions->preserveMode;
811 enableDebugInfo = clOptions->enableDebugInfo;
812 buildMode = clOptions->buildMode;
813 disableLayerSink = clOptions->disableLayerSink;
814 disableOptimization = clOptions->disableOptimization;
815 exportChiselInterface = clOptions->exportChiselInterface;
816 chiselInterfaceOutDirectory = clOptions->chiselInterfaceOutDirectory;
817 vbToBV = clOptions->vbToBV;
818 noDedup = clOptions->noDedup;
819 companionMode = clOptions->companionMode;
821 clOptions->disableAggressiveMergeConnections;
822 advancedLayerSink = clOptions->advancedLayerSink;
823 lowerMemories = clOptions->lowerMemories;
824 blackBoxRootPath = clOptions->blackBoxRootPath;
825 replSeqMem = clOptions->replSeqMem;
826 replSeqMemFile = clOptions->replSeqMemFile;
827 extractTestCode = clOptions->extractTestCode;
828 ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
829 disableRandom = clOptions->disableRandom;
830 outputAnnotationFilename = clOptions->outputAnnotationFilename;
831 enableAnnotationWarning = clOptions->enableAnnotationWarning;
832 addMuxPragmas = clOptions->addMuxPragmas;
833 verificationFlavor = clOptions->verificationFlavor;
834 emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
835 etcDisableInstanceExtraction = clOptions->etcDisableInstanceExtraction;
836 etcDisableRegisterExtraction = clOptions->etcDisableRegisterExtraction;
837 etcDisableModuleInlining = clOptions->etcDisableModuleInlining;
839 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
840 ckgModuleName = clOptions->ckgModuleName;
841 ckgInputName = clOptions->ckgInputName;
842 ckgOutputName = clOptions->ckgOutputName;
843 ckgEnableName = clOptions->ckgEnableName;
844 ckgTestEnableName = clOptions->ckgTestEnableName;
845 exportModuleHierarchy = clOptions->exportModuleHierarchy;
846 stripFirDebugInfo = clOptions->stripFirDebugInfo;
847 stripDebugInfo = clOptions->stripDebugInfo;
848 fixupEICGWrapper = clOptions->fixupEICGWrapper;
849 addCompanionAssume = clOptions->addCompanionAssume;
850 selectDefaultInstanceChoice = clOptions->selectDefaultInstanceChoice;
851 symbolicValueLowering = clOptions->symbolicValueLowering;
852}
static LogicalResult exportChiselInterface(CircuitOp circuit, llvm::raw_ostream &os)
Exports a Chisel interface to the output stream.
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition Firtool.cpp:766
Set of options used to control the behavior of the firtool pipeline.
Definition Firtool.h:31
bool shouldStripDebugInfo() const
Definition Firtool.h:118
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition Firtool.h:65
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition Firtool.h:130
bool shouldDisableLayerSink() const
Definition Firtool.h:100
firrtl::PreserveValues::PreserveMode preserveMode
Definition Firtool.h:397
bool shouldAddCompanionAssume() const
Definition Firtool.h:135
auto getVerificationFlavor() const
Definition Firtool.h:125
bool isDefaultOutputFilename() const
Definition Firtool.h:85
StringRef getOutputFilename() const
Definition Firtool.h:55
bool shouldDisableAggressiveMergeConnections() const
Definition Firtool.h:121
StringRef getReplaceSequentialMemoriesFile() const
Definition Firtool.h:60
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition Firtool.h:424
bool shouldExportChiselInterface() const
Definition Firtool.h:107
bool shouldAdvancedLayerSink() const
Definition Firtool.h:102
bool shouldExtractTestCode() const
Definition Firtool.h:133
std::string chiselInterfaceOutDirectory
Definition Firtool.h:403
bool shouldFixupEICGWrapper() const
Definition Firtool.h:134
bool shouldConvertProbesToSignals() const
Definition Firtool.h:98
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition Firtool.h:43
StringRef getBlackBoxRootPath() const
Definition Firtool.h:56
bool shouldDisableCSEinClasses() const
Definition Firtool.h:136
bool shouldDisableOptimization() const
Definition Firtool.h:101
firrtl::CompanionMode getCompanionMode() const
Definition Firtool.h:68
bool shouldDisableClasslessAnnotations() const
Definition Firtool.h:89
bool shouldReplaceSequentialMemories() const
Definition Firtool.h:99
bool shouldIgnoreReadEnableMemories() const
Definition Firtool.h:106
bool isRandomEnabled(RandomKind kind) const
Definition Firtool.h:39
bool shouldDisableUnknownAnnotations() const
Definition Firtool.h:86
bool shouldAddMuxPragmas() const
Definition Firtool.h:129
bool shouldEnableAnnotationWarning() const
Definition Firtool.h:124
bool shouldEtcDisableInstanceExtraction() const
Definition Firtool.h:109
bool shouldConvertVecOfBundle() const
Definition Firtool.h:108
StringRef getOutputAnnotationFilename() const
Definition Firtool.h:61
bool shouldStripFirDebugInfo() const
Definition Firtool.h:119
bool shouldEtcDisableRegisterExtraction() const
Definition Firtool.h:112
std::string outputAnnotationFilename
Definition Firtool.h:416
firrtl::VerificationFlavor verificationFlavor
Definition Firtool.h:419
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition Firtool.h:396
bool shouldLowerMemories() const
Definition Firtool.h:103
bool shouldEtcDisableModuleInlining() const
Definition Firtool.h:115
bool shouldAllowAddingPortsOnPublic() const
Definition Firtool.h:95
bool shouldLowerNoRefTypePortAnnotations() const
Definition Firtool.h:92
verif::SymbolicValueLowering getSymbolicValueLowering() const
Definition Firtool.h:141
bool shouldExportModuleHierarchy() const
Definition Firtool.h:120
firrtl::CompanionMode companionMode
Definition Firtool.h:406
bool shouldSelectDefaultInstanceChoice() const
Definition Firtool.h:137
verif::SymbolicValueLowering symbolicValueLowering
Definition Firtool.h:438
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition Firtool.h:70
bool shouldEnableDebugInfo() const
Definition Firtool.h:105
bool shouldEmitSeparateAlwaysBlocks() const
Definition Firtool.h:126
StringRef getChiselInterfaceOutputDirectory() const
Definition Firtool.h:57
@ All
Preserve all aggregate values.
Definition Passes.h:42
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
Definition Passes.h:36
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
Definition Passes.h:39
@ None
Don't preserve aggregate at all.
Definition Passes.h:33
@ None
Don't explicitly preserve any named values.
Definition Passes.h:54
@ Strip
Strip all names. No name on declaration is preserved.
Definition Passes.h:50
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 > 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()
Definition VBToBV.cpp:993
std::unique_ptr< mlir::Pass > createGrandCentralPass(CompanionMode companionMode=CompanionMode::Bind)
std::unique_ptr< mlir::Pass > createLowerDPIPass()
Definition LowerDPI.cpp:294
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 > createCreateCompanionAssume()
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)
Definition DropName.cpp:101
std::unique_ptr< mlir::Pass > createLowerLayersPass()
std::unique_ptr< mlir::Pass > createIMDeadCodeElimPass()
std::unique_ptr< mlir::Pass > createLintingPass()
Definition Lint.cpp:77
std::unique_ptr< mlir::Pass > createPassiveWiresPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createExtractInstancesPass()
std::unique_ptr< mlir::Pass > createDedupPass()
Definition Dedup.cpp:1894
std::unique_ptr< mlir::Pass > createSpecializeOptionPass(bool selectDefaultInstanceChoice=false)
std::unique_ptr< mlir::Pass > createLayerSinkPass()
Definition LayerSink.cpp:58
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()
Definition LowerXMR.cpp:878
std::unique_ptr< mlir::Pass > createLowerIntrinsicsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createInferWidthsPass()
std::unique_ptr< mlir::Pass > createResolveTracesPass(mlir::StringRef outputAnnotationFilename="")
std::unique_ptr< mlir::Pass > createMemToRegOfVecPass(bool replSeqMem=false, bool ignoreReadEnable=false)
std::unique_ptr< mlir::Pass > createCreateSiFiveMetadataPass(bool replSeqMem=false, mlir::StringRef replSeqMemFile="")
std::unique_ptr< mlir::Pass > createAssignOutputDirsPass(mlir::StringRef outputDir="")
std::unique_ptr< mlir::Pass > createBlackBoxReaderPass(std::optional< mlir::StringRef > inputPrefix={})
std::unique_ptr< mlir::Pass > createLowerOpenAggsPass()
This is the pass constructor.
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()
LogicalResult populateHWToBTOR2(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::raw_ostream &os)
Definition Firtool.cpp:438
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition Firtool.cpp:420
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:305
LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:264
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition Firtool.cpp:401
LogicalResult populatePreprocessTransforms(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:27
void registerFirtoolCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
Definition Firtool.cpp:771
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:430
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition Firtool.cpp:55
std::unique_ptr< mlir::Pass > createFlattenModulesPass()
std::unique_ptr< mlir::Pass > createVerifyInnerRefNamespacePass()
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< mlir::Pass > createExportSplitChiselInterfacePass(mlir::StringRef outputDirectory="./")
std::unique_ptr< OperationPass< hw::HWModuleOp > > createLowerVerifToSVPass()
Create the Verif to SV conversion pass.
std::unique_ptr< mlir::Pass > createLowerSeqToSVPass(const LowerSeqToSVOptions &options={})
Definition SeqToSV.cpp:852
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()
Definition SimToSV.cpp:375
std::unique_ptr< Pass > createSimpleCanonicalizerPass()
Create a simple canonicalizer pass.
Definition Passes.cpp:15
std::unique_ptr< mlir::Pass > createConvertHWToBTOR2Pass()
std::unique_ptr< mlir::Pass > createExportChiselInterfacePass()
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)
Definition Firtool.cpp:362