CIRCT 20.0.0git
Loading...
Searching...
No Matches
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.addPass(verif::createLowerFormalToHWPass());
308
309 if (opt.shouldExtractTestCode())
310 pm.addPass(sv::createSVExtractTestCodePass(
314
315 pm.addPass(seq::createExternalizeClockGatePass(opt.getClockGateOptions()));
316 pm.addPass(circt::createLowerSimToSVPass());
318 {/*disableRegRandomization=*/!opt.isRandomEnabled(
319 FirtoolOptions::RandomKind::Reg),
320 /*disableMemRandomization=*/
321 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
322 /*emitSeparateAlwaysBlocks=*/
324 pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
325 pm.addPass(seq::createHWMemSimImplPass(
326 {/*disableMemRandomization=*/!opt.isRandomEnabled(
327 FirtoolOptions::RandomKind::Mem),
328 /*disableRegRandomization=*/
329 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
330 /*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
331 /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
332 ? seq::ReadEnableMode::Ignore
333 : seq::ReadEnableMode::Undefined,
334 /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
335 /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
337
338 // If enabled, run the optimizer.
339 if (!opt.shouldDisableOptimization()) {
340 auto &modulePM = pm.nest<hw::HWModuleOp>();
341 modulePM.addPass(mlir::createCSEPass());
342 modulePM.addPass(createSimpleCanonicalizerPass());
343 modulePM.addPass(mlir::createCSEPass());
344 modulePM.addPass(sv::createHWCleanupPass(
345 /*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()));
346 }
347
348 // Check inner symbols and inner refs.
349 pm.addPass(hw::createVerifyInnerRefNamespacePass());
350
351 // Check OM object fields.
352 pm.addPass(om::createVerifyObjectFieldsPass());
353
354 return success();
355}
356
357namespace detail {
358LogicalResult
360 const firtool::FirtoolOptions &opt) {
361
362 // Run the verif op verification pass
363 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
364
365 // Legalize unsupported operations within the modules.
367
368 // Tidy up the IR to improve verilog emission quality.
369 if (!opt.shouldDisableOptimization())
370 pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilogPass());
371
372 if (opt.shouldStripFirDebugInfo())
373 pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
374 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc))
375 return fileLoc.getFilename().getValue().ends_with(".fir");
376 return false;
377 }));
378
379 if (opt.shouldStripDebugInfo())
381 [](mlir::Location loc) { return true; }));
382
383 // Emit module and testbench hierarchy JSON files.
386
387 // Check inner symbols and inner refs.
389
390 // Check OM object fields.
392
393 return success();
394}
395} // namespace detail
396
397LogicalResult
398firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
399 std::unique_ptr<llvm::raw_ostream> os) {
401 return failure();
402
403 pm.addPass(createExportVerilogPass(std::move(os)));
404 return success();
405}
406
407LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
408 const FirtoolOptions &opt,
409 llvm::raw_ostream &os) {
411 return failure();
412
413 pm.addPass(createExportVerilogPass(os));
414 return success();
415}
416
417LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
418 const FirtoolOptions &opt,
419 llvm::StringRef directory) {
421 return failure();
422
423 pm.addPass(createExportSplitVerilogPass(directory));
424 return success();
425}
426
427LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
428 const FirtoolOptions &opt) {
429 pm.addPass(firrtl::createFinalizeIRPass());
430 pm.addPass(om::createFreezePathsPass());
431
432 return success();
433}
434
435LogicalResult firtool::populateHWToBTOR2(mlir::PassManager &pm,
436 const FirtoolOptions &opt,
437 llvm::raw_ostream &os) {
439 pm.addNestedPass<hw::HWModuleOp>(circt::verif::createPrepareForFormalPass());
441 pm.addPass(circt::createConvertHWToBTOR2Pass(os));
442 return success();
443}
444
445//===----------------------------------------------------------------------===//
446// FIRTOOL CommandLine Options
447//===----------------------------------------------------------------------===//
448
449namespace {
450/// This struct contains command line options that can be used to initialize
451/// various bits of a Firtool pipeline. This uses a struct wrapper to avoid the
452/// need for global command line options.
453struct FirtoolCmdOptions {
454 llvm::cl::opt<std::string> outputFilename{
455 "o",
456 llvm::cl::desc("Output filename, or directory for split output"),
457 llvm::cl::value_desc("filename"),
458 llvm::cl::init("-"),
459 };
460
461 llvm::cl::opt<bool> disableAnnotationsUnknown{
462 "disable-annotation-unknown",
463 llvm::cl::desc("Ignore unknown annotations when parsing"),
464 llvm::cl::init(false)};
465
466 llvm::cl::opt<bool> disableAnnotationsClassless{
467 "disable-annotation-classless",
468 llvm::cl::desc("Ignore annotations without a class when parsing"),
469 llvm::cl::init(false)};
470
471 llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
472 "lower-annotations-no-ref-type-ports",
473 llvm::cl::desc(
474 "Create real ports instead of ref type ports when resolving "
475 "wiring problems inside the LowerAnnotations pass"),
476 llvm::cl::init(false), llvm::cl::Hidden};
477
478 llvm::cl::opt<bool> allowAddingPortsOnPublic{
479 "allow-adding-ports-on-public-modules",
480 llvm::cl::desc("Allow adding ports to public modules"),
481 llvm::cl::init(false), llvm::cl::Hidden};
482
483 llvm::cl::opt<bool> probesToSignals{
484 "probes-to-signals",
485 llvm::cl::desc("Convert probes to non-probe signals"),
486 llvm::cl::init(false), llvm::cl::Hidden};
487
489 preserveAggregate{
490 "preserve-aggregate",
491 llvm::cl::desc("Specify input file format:"),
492 llvm::cl::values(
494 "Preserve no aggregate"),
496 "Preserve only 1d vectors of ground type"),
498 "Preserve only vectors"),
500 "Preserve vectors and bundles")),
502 };
503
505 "preserve-values",
506 llvm::cl::desc("Specify the values which can be optimized away"),
507 llvm::cl::values(
508 clEnumValN(firrtl::PreserveValues::Strip, "strip",
509 "Strip all names. No name is preserved"),
510 clEnumValN(firrtl::PreserveValues::None, "none",
511 "Names could be preserved by best-effort unlike `strip`"),
512 clEnumValN(firrtl::PreserveValues::Named, "named",
513 "Preserve values with meaningful names"),
514 clEnumValN(firrtl::PreserveValues::All, "all",
515 "Preserve all values")),
516 llvm::cl::init(firrtl::PreserveValues::None)};
517
518 llvm::cl::opt<bool> enableDebugInfo{
519 "g", llvm::cl::desc("Enable the generation of debug information"),
520 llvm::cl::init(false)};
521
522 // Build mode options.
524 "O", llvm::cl::desc("Controls how much optimization should be performed"),
525 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
526 "debug",
527 "Compile with only necessary optimizations"),
529 "release", "Compile with optimizations")),
531
532 llvm::cl::opt<bool> disableLayerSink{"disable-layer-sink",
533 llvm::cl::desc("Disable layer sink"),
534 cl::init(false)};
535
536 llvm::cl::opt<bool> disableOptimization{
537 "disable-opt",
538 llvm::cl::desc("Disable optimizations"),
539 };
540
541 llvm::cl::opt<bool> exportChiselInterface{
542 "export-chisel-interface",
543 llvm::cl::desc("Generate a Scala Chisel interface to the top level "
544 "module of the firrtl circuit"),
545 llvm::cl::init(false)};
546
547 llvm::cl::opt<std::string> chiselInterfaceOutDirectory{
548 "chisel-interface-out-dir",
549 llvm::cl::desc(
550 "The output directory for generated Chisel interface files"),
551 llvm::cl::init("")};
552
553 llvm::cl::opt<bool> vbToBV{
554 "vb-to-bv",
555 llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
556 llvm::cl::init(false)};
557
558 llvm::cl::opt<bool> noDedup{
559 "no-dedup",
560 llvm::cl::desc("Disable deduplication of structurally identical modules"),
561 llvm::cl::init(false)};
562
564 "grand-central-companion-mode",
565 llvm::cl::desc("Specifies the handling of Grand Central companions"),
566 ::llvm::cl::values(
567 clEnumValN(firrtl::CompanionMode::Bind, "bind",
568 "Lower companion instances to SystemVerilog binds"),
569 clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
570 "Instantiate companions in the design"),
571 clEnumValN(firrtl::CompanionMode::Drop, "drop",
572 "Remove companions from the design")),
573 llvm::cl::init(firrtl::CompanionMode::Bind),
574 llvm::cl::Hidden,
575 };
576
577 llvm::cl::opt<bool> disableAggressiveMergeConnections{
578 "disable-aggressive-merge-connections",
579 llvm::cl::desc(
580 "Disable aggressive merge connections (i.e. merge all field-level "
581 "connections into bulk connections)"),
582 llvm::cl::init(false)};
583
584 llvm::cl::opt<bool> advancedLayerSink{
585 "advanced-layer-sink",
586 llvm::cl::desc("Sink logic into layer blocks (advanced)"),
587 llvm::cl::init(false)};
588
589 llvm::cl::opt<bool> lowerMemories{
590 "lower-memories",
591 llvm::cl::desc("Lower memories to have memories with masks as an "
592 "array with one memory per ground type"),
593 llvm::cl::init(false)};
594
595 llvm::cl::opt<std::string> blackBoxRootPath{
596 "blackbox-path",
597 llvm::cl::desc(
598 "Optional path to use as the root of black box annotations"),
599 llvm::cl::value_desc("path"),
600 llvm::cl::init(""),
601 };
602
603 llvm::cl::opt<bool> replSeqMem{
604 "repl-seq-mem",
605 llvm::cl::desc("Replace the seq mem for macro replacement and emit "
606 "relevant metadata"),
607 llvm::cl::init(false)};
608
609 llvm::cl::opt<std::string> replSeqMemFile{
610 "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
611 llvm::cl::init("")};
612
613 llvm::cl::opt<bool> extractTestCode{
614 "extract-test-code", llvm::cl::desc("Run the extract test code pass"),
615 llvm::cl::init(false)};
616
617 llvm::cl::opt<bool> ignoreReadEnableMem{
618 "ignore-read-enable-mem",
619 llvm::cl::desc("Ignore the read enable signal, instead of "
620 "assigning X on read disable"),
621 llvm::cl::init(false)};
622
624 llvm::cl::desc(
625 "Disable random initialization code (may break semantics!)"),
626 llvm::cl::values(
627 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
628 "disable-mem-randomization",
629 "Disable emission of memory randomization code"),
630 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
631 "disable-reg-randomization",
632 "Disable emission of register randomization code"),
633 clEnumValN(firtool::FirtoolOptions::RandomKind::All,
634 "disable-all-randomization",
635 "Disable emission of all randomization code")),
636 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
637
638 llvm::cl::opt<std::string> outputAnnotationFilename{
639 "output-annotation-file",
640 llvm::cl::desc("Optional output annotation file"),
641 llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
642
643 llvm::cl::opt<bool> enableAnnotationWarning{
644 "warn-on-unprocessed-annotations",
645 llvm::cl::desc(
646 "Warn about annotations that were not removed by lower-to-hw"),
647 llvm::cl::init(false)};
648
649 llvm::cl::opt<bool> addMuxPragmas{
650 "add-mux-pragmas",
651 llvm::cl::desc("Annotate mux pragmas for memory array access"),
652 llvm::cl::init(false)};
653
655 "verification-flavor",
656 llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
657 llvm::cl::values(
658 clEnumValN(firrtl::VerificationFlavor::None, "none",
659 "Use the flavor specified by the op"),
660 clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
661 "Use Use `if(cond) else $fatal(..)` format"),
662 clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
663 "Use immediate verif statements"),
664 clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
665 llvm::cl::init(firrtl::VerificationFlavor::None)};
666
667 llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
668 "emit-separate-always-blocks",
669 llvm::cl::desc(
670 "Prevent always blocks from being merged and emit constructs into "
671 "separate always blocks whenever possible"),
672 llvm::cl::init(false)};
673
674 llvm::cl::opt<bool> etcDisableInstanceExtraction{
675 "etc-disable-instance-extraction",
676 llvm::cl::desc("Disable extracting instances only that feed test code"),
677 llvm::cl::init(false)};
678
679 llvm::cl::opt<bool> etcDisableRegisterExtraction{
680 "etc-disable-register-extraction",
681 llvm::cl::desc("Disable extracting registers that only feed test code"),
682 llvm::cl::init(false)};
683
684 llvm::cl::opt<bool> etcDisableModuleInlining{
685 "etc-disable-module-inlining",
686 llvm::cl::desc("Disable inlining modules that only feed test code"),
687 llvm::cl::init(false)};
688
689 llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
690 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
691 llvm::cl::desc(
692 "Add a vivado specific SV attribute (* ram_style = "
693 "\"distributed\" *) to unpacked array registers as a workaronud "
694 "for a vivado synthesis bug that incorrectly modifies "
695 "address conflict behavivor of combinational memories"),
696 llvm::cl::init(false)};
697
698 //===----------------------------------------------------------------------===
699 // External Clock Gate Options
700 //===----------------------------------------------------------------------===
701
702 llvm::cl::opt<std::string> ckgModuleName{
703 "ckg-name", llvm::cl::desc("Clock gate module name"),
704 llvm::cl::init("EICG_wrapper")};
705
706 llvm::cl::opt<std::string> ckgInputName{
707 "ckg-input", llvm::cl::desc("Clock gate input port name"),
708 llvm::cl::init("in")};
709
710 llvm::cl::opt<std::string> ckgOutputName{
711 "ckg-output", llvm::cl::desc("Clock gate output port name"),
712 llvm::cl::init("out")};
713
714 llvm::cl::opt<std::string> ckgEnableName{
715 "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
716 llvm::cl::init("en")};
717
718 llvm::cl::opt<std::string> ckgTestEnableName{
719 "ckg-test-enable",
720 llvm::cl::desc("Clock gate test enable port name (optional)"),
721 llvm::cl::init("test_en")};
722
723 llvm::cl::opt<bool> exportModuleHierarchy{
724 "export-module-hierarchy",
725 llvm::cl::desc("Export module and instance hierarchy as JSON"),
726 llvm::cl::init(false)};
727
728 llvm::cl::opt<bool> stripFirDebugInfo{
729 "strip-fir-debug-info",
730 llvm::cl::desc(
731 "Disable source fir locator information in output Verilog"),
732 llvm::cl::init(true)};
733
734 llvm::cl::opt<bool> stripDebugInfo{
735 "strip-debug-info",
736 llvm::cl::desc("Disable source locator information in output Verilog"),
737 llvm::cl::init(false)};
738
739 llvm::cl::opt<bool> fixupEICGWrapper{
740 "fixup-eicg-wrapper",
741 llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
742 llvm::cl::init(false)};
743
744 llvm::cl::opt<bool> addCompanionAssume{
745 "add-companion-assume",
746 llvm::cl::desc("Add companion assumes to assertions"),
747 llvm::cl::init(false)};
748
749 llvm::cl::opt<bool> selectDefaultInstanceChoice{
750 "select-default-for-unspecified-instance-choice",
751 llvm::cl::desc(
752 "Specialize instance choice to default, if no option selected"),
753 llvm::cl::init(false)};
754};
755} // namespace
756
757static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
758
759/// Register a set of useful command-line options that can be used to configure
760/// various flags within the MLIRContext. These flags are used when constructing
761/// an MLIR context for initialization.
763 // Make sure that the options struct has been initialized.
764 *clOptions;
765}
766
767// Initialize the firtool options with defaults supplied by the cl::opts above.
769 : outputFilename("-"), disableAnnotationsUnknown(false),
770 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
771 allowAddingPortsOnPublic(false), probesToSignals(false),
772 preserveAggregate(firrtl::PreserveAggregate::None),
773 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
774 buildMode(BuildModeRelease), disableLayerSink(false),
775 disableOptimization(false), exportChiselInterface(false),
776 chiselInterfaceOutDirectory(""), vbToBV(false), noDedup(false),
777 companionMode(firrtl::CompanionMode::Bind),
778 disableAggressiveMergeConnections(false), advancedLayerSink(false),
779 lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
780 replSeqMemFile(""), extractTestCode(false), ignoreReadEnableMem(false),
781 disableRandom(RandomKind::None), outputAnnotationFilename(""),
782 enableAnnotationWarning(false), addMuxPragmas(false),
783 verificationFlavor(firrtl::VerificationFlavor::None),
784 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
785 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
786 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
787 ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
788 ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
789 exportModuleHierarchy(false), stripFirDebugInfo(true),
790 stripDebugInfo(false), fixupEICGWrapper(false), addCompanionAssume(false),
791 disableCSEinClasses(false), selectDefaultInstanceChoice(false) {
792 if (!clOptions.isConstructed())
793 return;
794 outputFilename = clOptions->outputFilename;
795 disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
796 disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
797 lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
798 allowAddingPortsOnPublic = clOptions->allowAddingPortsOnPublic;
799 probesToSignals = clOptions->probesToSignals;
800 preserveAggregate = clOptions->preserveAggregate;
801 preserveMode = clOptions->preserveMode;
802 enableDebugInfo = clOptions->enableDebugInfo;
803 buildMode = clOptions->buildMode;
804 disableLayerSink = clOptions->disableLayerSink;
805 disableOptimization = clOptions->disableOptimization;
806 exportChiselInterface = clOptions->exportChiselInterface;
807 chiselInterfaceOutDirectory = clOptions->chiselInterfaceOutDirectory;
808 vbToBV = clOptions->vbToBV;
809 noDedup = clOptions->noDedup;
810 companionMode = clOptions->companionMode;
812 clOptions->disableAggressiveMergeConnections;
813 advancedLayerSink = clOptions->advancedLayerSink;
814 lowerMemories = clOptions->lowerMemories;
815 blackBoxRootPath = clOptions->blackBoxRootPath;
816 replSeqMem = clOptions->replSeqMem;
817 replSeqMemFile = clOptions->replSeqMemFile;
818 extractTestCode = clOptions->extractTestCode;
819 ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
820 disableRandom = clOptions->disableRandom;
821 outputAnnotationFilename = clOptions->outputAnnotationFilename;
822 enableAnnotationWarning = clOptions->enableAnnotationWarning;
823 addMuxPragmas = clOptions->addMuxPragmas;
824 verificationFlavor = clOptions->verificationFlavor;
825 emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
826 etcDisableInstanceExtraction = clOptions->etcDisableInstanceExtraction;
827 etcDisableRegisterExtraction = clOptions->etcDisableRegisterExtraction;
828 etcDisableModuleInlining = clOptions->etcDisableModuleInlining;
830 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
831 ckgModuleName = clOptions->ckgModuleName;
832 ckgInputName = clOptions->ckgInputName;
833 ckgOutputName = clOptions->ckgOutputName;
834 ckgEnableName = clOptions->ckgEnableName;
835 ckgTestEnableName = clOptions->ckgTestEnableName;
836 exportModuleHierarchy = clOptions->exportModuleHierarchy;
837 stripFirDebugInfo = clOptions->stripFirDebugInfo;
838 stripDebugInfo = clOptions->stripDebugInfo;
839 fixupEICGWrapper = clOptions->fixupEICGWrapper;
840 addCompanionAssume = clOptions->addCompanionAssume;
841 selectDefaultInstanceChoice = clOptions->selectDefaultInstanceChoice;
842}
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:757
Set of options used to control the behavior of the firtool pipeline.
Definition Firtool.h:30
bool shouldStripDebugInfo() const
Definition Firtool.h:117
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition Firtool.h:64
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition Firtool.h:129
bool shouldDisableLayerSink() const
Definition Firtool.h:99
firrtl::PreserveValues::PreserveMode preserveMode
Definition Firtool.h:387
bool shouldAddCompanionAssume() const
Definition Firtool.h:134
auto getVerificationFlavor() const
Definition Firtool.h:124
bool isDefaultOutputFilename() const
Definition Firtool.h:84
StringRef getOutputFilename() const
Definition Firtool.h:54
bool shouldDisableAggressiveMergeConnections() const
Definition Firtool.h:120
StringRef getReplaceSequentialMemoriesFile() const
Definition Firtool.h:59
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition Firtool.h:414
bool shouldExportChiselInterface() const
Definition Firtool.h:106
bool shouldAdvancedLayerSink() const
Definition Firtool.h:101
bool shouldExtractTestCode() const
Definition Firtool.h:132
std::string chiselInterfaceOutDirectory
Definition Firtool.h:393
bool shouldFixupEICGWrapper() const
Definition Firtool.h:133
bool shouldConvertProbesToSignals() const
Definition Firtool.h:97
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition Firtool.h:42
StringRef getBlackBoxRootPath() const
Definition Firtool.h:55
bool shouldDisableCSEinClasses() const
Definition Firtool.h:135
bool shouldDisableOptimization() const
Definition Firtool.h:100
firrtl::CompanionMode getCompanionMode() const
Definition Firtool.h:67
bool shouldDisableClasslessAnnotations() const
Definition Firtool.h:88
bool shouldReplaceSequentialMemories() const
Definition Firtool.h:98
bool shouldIgnoreReadEnableMemories() const
Definition Firtool.h:105
bool isRandomEnabled(RandomKind kind) const
Definition Firtool.h:38
bool shouldDisableUnknownAnnotations() const
Definition Firtool.h:85
bool shouldAddMuxPragmas() const
Definition Firtool.h:128
bool shouldEnableAnnotationWarning() const
Definition Firtool.h:123
bool shouldEtcDisableInstanceExtraction() const
Definition Firtool.h:108
bool shouldConvertVecOfBundle() const
Definition Firtool.h:107
StringRef getOutputAnnotationFilename() const
Definition Firtool.h:60
bool shouldStripFirDebugInfo() const
Definition Firtool.h:118
bool shouldEtcDisableRegisterExtraction() const
Definition Firtool.h:111
std::string outputAnnotationFilename
Definition Firtool.h:406
firrtl::VerificationFlavor verificationFlavor
Definition Firtool.h:409
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition Firtool.h:386
bool shouldLowerMemories() const
Definition Firtool.h:102
bool shouldEtcDisableModuleInlining() const
Definition Firtool.h:114
bool shouldAllowAddingPortsOnPublic() const
Definition Firtool.h:94
bool shouldLowerNoRefTypePortAnnotations() const
Definition Firtool.h:91
bool shouldExportModuleHierarchy() const
Definition Firtool.h:119
firrtl::CompanionMode companionMode
Definition Firtool.h:396
bool shouldSelectDefaultInstanceChoice() const
Definition Firtool.h:136
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition Firtool.h:69
bool shouldEnableDebugInfo() const
Definition Firtool.h:104
bool shouldEmitSeparateAlwaysBlocks() const
Definition Firtool.h:125
StringRef getChiselInterfaceOutputDirectory() const
Definition Firtool.h:56
@ 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:1865
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:917
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:435
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition Firtool.cpp:417
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:398
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:762
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:427
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:845
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:370
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:359