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