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