CIRCT 23.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(
30 firrtl::createCheckRecursiveInstantiation());
31 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createCheckLayers());
32 // Legalize away "open" aggregates to hw-only versions.
33 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerOpenAggs());
34
35 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createResolvePaths());
36
37 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotations(
38 {/*ignoreAnnotationClassless=*/opt.shouldDisableClasslessAnnotations(),
39 /*ignoreAnnotationUnknown=*/opt.shouldDisableUnknownAnnotations(),
40 /*noRefTypePorts=*/opt.shouldLowerNoRefTypePortAnnotations()}));
41
42 if (opt.shouldEnableDebugInfo())
43 pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
44 firrtl::createMaterializeDebugInfo());
45
46 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerIntmodules(
47 {/*fixupEICGWrapper=*/opt.shouldFixupEICGWrapper()}));
48 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
49 firrtl::createLowerIntrinsics());
50
51 return success();
52}
53
54LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
55 const FirtoolOptions &opt) {
56 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerSignatures());
57
58 // This pass is _not_ idempotent. It preserves its controlling annotation for
59 // use by ExtractInstances. This pass should be run before ExtractInstances.
60 //
61 // TODO: This pass should be deleted.
62 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInjectDUTHierarchy());
63
64 if (!opt.shouldDisableOptimization()) {
66 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
67 mlir::createCSEPass());
68 else
69 pm.nest<firrtl::CircuitOp>().nestAny().addPass(mlir::createCSEPass());
70 }
71
72 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
73 firrtl::createPassiveWires());
74
75 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
76 firrtl::createDropName({/*preserveMode=*/opt.getPreserveMode()}));
77
78 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
79 firrtl::createLowerCHIRRTLPass());
80
81 // Run LowerMatches before InferWidths, as the latter does not support the
82 // match statement, but it does support what they lower to.
83 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
84 firrtl::createLowerMatches());
85
86 // Width inference creates canonicalization opportunities.
87 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidths());
88
89 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createMemToRegOfVec(
90 {/*replSeqMemFile=*/opt.shouldIgnoreReadEnableMemories()}));
91
92 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResets());
93
94 // TODO: Move this to the same location as SpecializeLayers.
95 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeOption(
96 {/*selectDefaultInstanceChoice*/ opt
98
99 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDropConst());
100
101 if (opt.shouldDedup()) {
102 firrtl::DedupOptions opts;
103 opts.dedupClasses = opt.shouldDedupClasses();
104 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDedup(opts));
105 }
106
107 if (opt.shouldConvertVecOfBundle()) {
108 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypes(
109 {/*preserveAggregate=*/firrtl::PreserveAggregate::All,
110 /*preserveMemories*/ firrtl::PreserveAggregate::All}));
111 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createVBToBV());
112 }
113
114 if (!opt.shouldLowerMemories())
115 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
116 firrtl::createFlattenMemory());
117
118 // The input mlir file could be firrtl dialect so we might need to clean
119 // things up.
120 // pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerSignaturesPass());
121 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypes(
122 {/*preserveAggregate=*/opt.getPreserveAggregate(),
123 /*preserveMemory=*/firrtl::PreserveAggregate::None}));
124
125 {
126 auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
127 modulePM.addPass(firrtl::createExpandWhens());
128 modulePM.addPass(firrtl::createSFCCompat());
129 }
130
131 // InferDomains runs after ExpandWhens because FIRRTL allows for last-connect
132 // semantics and users have historically relied on this behavior to set
133 // default connections that are then overridden later. If this pass is run
134 // before ExpandWhens, then users can get errors if they rely on last-connect
135 // semantics.
136 if (auto mode = FirtoolOptions::toInferDomainsPassMode(opt.getDomainMode()))
137 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferDomains({*mode}));
138
139 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createCheckCombLoops());
140
141 // Must run this pass after all diagnostic passes have run, otherwise it can
142 // hide errors.
143 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeLayers());
144
145 // Run after inference, layer specialization.
147 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createProbesToSignals());
148
149 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInliner());
150
151 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
152 firrtl::createLayerMerge());
153
154 // Preset the random initialization parameters for each module. The current
155 // implementation assumes it can run at a time where every register is
156 // currently in the final module it will be emitted in, all registers have
157 // been created, and no registers have yet been removed.
158 if (opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg))
159 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
160 firrtl::createRandomizeRegisterInit());
161
162 // If we parsed a FIRRTL file and have optimizations enabled, clean it up.
163 if (!opt.shouldDisableOptimization())
164 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
166
167 // Run the infer-rw pass, which merges read and write ports of a memory with
168 // mutually exclusive enables.
169 if (!opt.shouldDisableOptimization())
170 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
171 firrtl::createInferReadWrite());
172
174 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerMemory());
175
176 if (!opt.shouldDisableOptimization())
177 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstProp());
178
179 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createAddSeqMemPorts());
180
181 pm.addPass(firrtl::createCreateSiFiveMetadata(
182 {/*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
183 /*replSeqMemFile=*/opt.getReplaceSequentialMemoriesFile().str()}));
184
185 // This pass must be run after InjectDUTHierarchy.
186 //
187 // TODO: This pass should be deleted along with InjectDUTHierarchy.
188 pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstances());
189
190 // Run SymbolDCE as late as possible, but before InnerSymbolDCE. This is for
191 // hierpathop's and just for general cleanup.
192 pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
193
194 // Run InnerSymbolDCE as late as possible, but before IMDCE.
195 pm.addPass(firrtl::createInnerSymbolDCE());
196
197 // The above passes, IMConstProp in particular, introduce additional
198 // canonicalization opportunities that we should pick up here before we
199 // proceed to output-specific pipelines.
200 if (!opt.shouldDisableOptimization()) {
202 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
203 circt::firrtl::createEliminateWires());
204 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
206 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
207 circt::firrtl::createRegisterOptimizer());
208 // Re-run IMConstProp to propagate constants produced by register
209 // optimizations.
210 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstProp());
211 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
213 pm.addPass(firrtl::createIMDeadCodeElim());
215 pm.nest<firrtl::CircuitOp>().addPass(
216 firrtl::createAnnotateInputOnlyModules());
217 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInliner());
218 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
220 }
221 }
222
223 // Always run this, required for legalization.
224 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
225 firrtl::createMergeConnections(
226 {/*enableAggressiveMergin=*/!opt
228
229 if (!opt.shouldDisableOptimization())
230 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
231 firrtl::createVectorization());
232
233 return success();
234}
235
236LogicalResult firtool::populateLowFIRRTLToHW(mlir::PassManager &pm,
237 const FirtoolOptions &opt,
238 StringRef inputFilename) {
239 // Populate instance macros for instance choice operations before lowering to
240 // HW.
241 pm.nest<firrtl::CircuitOp>().addPass(
242 firrtl::createPopulateInstanceChoiceSymbols());
243
244 // Run layersink immediately before LowerXMR. LowerXMR will "freeze" the
245 // location of probed objects by placing symbols on them. Run layersink first
246 // so that probed objects can be sunk if possible.
248 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLayerSink());
249
250 // Lower the ref.resolve and ref.send ops and remove the RefType ports.
251 // LowerToHW cannot handle RefType so, this pass must be run to remove all
252 // RefType ports and ops.
253 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMR());
254
255 // Layer lowering passes. Move operations into layers when possible and
256 // remove layers by converting them to other constructs. This lowering
257 // process can create a few optimization opportunities.
258 //
259 // TODO: Improve LowerLayers to avoid the need for canonicalization. See:
260 // https://github.com/llvm/circt/issues/7896
261
262 pm.nest<firrtl::CircuitOp>().addPass(
263 firrtl::createLowerLayers({opt.getEmitAllBindFiles()}));
264 if (!opt.shouldDisableOptimization())
265 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
267
268 auto outputFilename = opt.getOutputFilename();
269 if (outputFilename == "-")
270 outputFilename = "";
271
272 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAssignOutputDirs(
273 {/*outputDirOption=*/outputFilename.str()}));
274
275 // Run passes to resolve Grand Central features. This should run before
276 // BlackBoxReader because Grand Central needs to inform BlackBoxReader where
277 // certain black boxes should be placed. Note: all Grand Central Taps related
278 // collateral is resolved entirely by LowerAnnotations.
279 // Run this after output directories are (otherwise) assigned,
280 // so generated interfaces can be appropriately marked.
281 pm.addNestedPass<firrtl::CircuitOp>(
282 firrtl::createGrandCentral({/*companionMode=*/opt.getCompanionMode(),
283 /*noViews*/ opt.getNoViews()}));
284
285 // Read black box source files into the IR.
286 StringRef blackBoxRoot = opt.getBlackBoxRootPath().empty()
287 ? llvm::sys::path::parent_path(inputFilename)
288 : opt.getBlackBoxRootPath();
289 pm.nest<firrtl::CircuitOp>().addPass(
290 firrtl::createBlackBoxReader({/*inputPrefix=*/blackBoxRoot.str()}));
291
292 // Remove TraceAnnotations and write their updated paths to an output
293 // annotation file.
294 pm.nest<firrtl::CircuitOp>().addPass(
295 firrtl::createResolveTraces({opt.getOutputAnnotationFilename().str()}));
296
297 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerDPI());
298 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerDomains());
299 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerClasses());
300
301 // Check for static asserts.
302 pm.nest<firrtl::CircuitOp>().addPass(circt::firrtl::createLint(
303 {/*lintStaticAsserts=*/opt.getLintStaticAsserts(),
304 /*lintXmrsInDesign=*/opt.getLintXmrsInDesign()}));
305
308 opt.shouldLowerToCore()));
309
310 if (!opt.shouldDisableOptimization()) {
311 auto &modulePM = pm.nest<hw::HWModuleOp>();
312 modulePM.addPass(mlir::createCSEPass());
313 modulePM.addPass(createSimpleCanonicalizerPass());
314 }
315
316 // Check inner symbols and inner refs.
317 pm.addPass(hw::createVerifyInnerRefNamespace());
318
319 // Run the verif op verification pass
320 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
321
322 return success();
323}
324
325LogicalResult firtool::populateHWToSV(mlir::PassManager &pm,
326 const FirtoolOptions &opt) {
327 pm.nestAny().addPass(verif::createStripContractsPass());
328 pm.addPass(verif::createLowerTestsPass());
329 pm.addPass(
330 verif::createLowerSymbolicValuesPass({opt.getSymbolicValueLowering()}));
331
332 pm.addPass(seq::createExternalizeClockGate(opt.getClockGateOptions()));
333 pm.addPass(circt::createLowerSimToSVPass());
335 {/*disableRegRandomization=*/!opt.isRandomEnabled(
336 FirtoolOptions::RandomKind::Reg),
337 /*disableMemRandomization=*/
338 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
339 /*emitSeparateAlwaysBlocks=*/
341 pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
342 pm.addPass(seq::createHWMemSimImpl(
343 {/*disableMemRandomization=*/!opt.isRandomEnabled(
344 FirtoolOptions::RandomKind::Mem),
345 /*disableRegRandomization=*/
346 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
347 /*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
348 /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
349 ? seq::ReadEnableMode::Ignore
350 : seq::ReadEnableMode::Undefined,
351 /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
352 /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
354
355 // If enabled, run the optimizer.
356 if (!opt.shouldDisableOptimization()) {
357 auto &modulePM = pm.nest<hw::HWModuleOp>();
358 modulePM.addPass(mlir::createCSEPass());
359 modulePM.addPass(createSimpleCanonicalizerPass());
360 modulePM.addPass(mlir::createCSEPass());
361 modulePM.addPass(sv::createHWCleanup(
362 {/*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()}));
363 }
364
365 // Check inner symbols and inner refs.
366 pm.addPass(hw::createVerifyInnerRefNamespace());
367
368 return success();
369}
370
371namespace detail {
372LogicalResult
374 const firtool::FirtoolOptions &opt) {
375
376 // Run the verif op verification pass
377 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
378
379 // Legalize unsupported operations within the modules.
380 pm.nest<hw::HWModuleOp>().addPass(sv::createHWLegalizeModules());
381
382 // Tidy up the IR to improve verilog emission quality.
383 if (!opt.shouldDisableOptimization())
384 pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilog());
385
386 if (opt.shouldStripFirDebugInfo())
387 pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
388 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc))
389 return fileLoc.getFilename().getValue().ends_with(".fir");
390 return false;
391 }));
392
393 if (opt.shouldStripDebugInfo())
395 [](mlir::Location loc) { return true; }));
396
397 // Emit module and testbench hierarchy JSON files.
399 pm.addPass(sv::createHWExportModuleHierarchy());
400
401 // Check inner symbols and inner refs.
402 pm.addPass(hw::createVerifyInnerRefNamespace());
403
404 return success();
405}
406} // namespace detail
407
408LogicalResult
409firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
410 std::unique_ptr<llvm::raw_ostream> os) {
412 return failure();
413
414 pm.addPass(createExportVerilogPass(std::move(os)));
415 return success();
416}
417
418LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
419 const FirtoolOptions &opt,
420 llvm::raw_ostream &os) {
422 return failure();
423
424 pm.addPass(createExportVerilogPass(os));
425 return success();
426}
427
428LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
429 const FirtoolOptions &opt,
430 llvm::StringRef directory) {
432 return failure();
433
434 pm.addPass(createExportSplitVerilogPass(directory));
435 return success();
436}
437
438LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
439 const FirtoolOptions &opt) {
440 pm.addPass(firrtl::createFinalizeIR());
441 pm.addPass(om::createFreezePathsPass());
442 om::ElaborateObjectOptions options;
443 options.allPublicClasses = true;
444 options.allowUnevaluated = true;
445 pm.addPass(om::createElaborateObject(options));
446 // TODO: Add SymbolDCE to elimiate unused private classes once after we
447 // stopped using private classes.
448
449 return success();
450}
451
452/// BTOR2 emission pipeline, triggered with `--btor2` flag.
453LogicalResult firtool::populateHWToBTOR2(mlir::PassManager &pm,
454 const FirtoolOptions &opt,
455 llvm::raw_ostream &os) {
456 auto &mpm = pm.nest<hw::HWModuleOp>();
457 // Lower all supported `ltl` ops
458 mpm.addPass(circt::createLowerLTLToCorePass());
459 // LTLToCore can generate shiftreg which should be lowered before emission
460 mpm.addPass(circt::seq::createLowerSeqShiftReg());
461 // ShiftReg Lowering generates compreg.ce, which we don't support, so lower
462 mpm.addPass(circt::seq::createLowerSeqCompRegCE());
463 // Do final formal specific lowerings, e.g. inline wires eagerly
464 mpm.addPass(circt::verif::createPrepareForFormalPass());
465 pm.addPass(circt::hw::createFlattenModules());
466 pm.addPass(circt::createConvertHWToBTOR2Pass(os));
467 return success();
468}
469
470//===----------------------------------------------------------------------===//
471// FIRTOOL CommandLine Options
472//===----------------------------------------------------------------------===//
473
474namespace {
475/// This class contains command line options that can be used to initialize
476/// various bits of a Firtool pipeline. This uses a class wrapper to avoid the
477/// need for global command line options.
478class FirtoolCmdOptions {
479public:
480 llvm::cl::opt<std::string> outputFilename{
481 "o",
482 llvm::cl::desc("Output filename, or directory for split output"),
483 llvm::cl::value_desc("filename"),
484 llvm::cl::init("-"),
485 };
486
487 llvm::cl::opt<bool> disableAnnotationsUnknown{
488 "disable-annotation-unknown",
489 llvm::cl::desc("Ignore unknown annotations when parsing"),
490 llvm::cl::init(false)};
491
492 llvm::cl::opt<bool> disableAnnotationsClassless{
493 "disable-annotation-classless",
494 llvm::cl::desc("Ignore annotations without a class when parsing"),
495 llvm::cl::init(false)};
496
497 llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
498 "lower-annotations-no-ref-type-ports",
499 llvm::cl::desc(
500 "Create real ports instead of ref type ports when resolving "
501 "wiring problems inside the LowerAnnotations pass"),
502 llvm::cl::init(false), llvm::cl::Hidden};
503
504 llvm::cl::opt<bool> probesToSignals{
505 "probes-to-signals",
506 llvm::cl::desc("Convert probes to non-probe signals"),
507 llvm::cl::init(false), llvm::cl::Hidden};
508
510 preserveAggregate{
511 "preserve-aggregate",
512 llvm::cl::desc("Specify input file format:"),
513 llvm::cl::values(
515 "Preserve no aggregate"),
517 "Preserve only 1d vectors of ground type"),
519 "Preserve only vectors"),
521 "Preserve vectors and bundles")),
523 };
524
526 "preserve-values",
527 llvm::cl::desc("Specify the values which can be optimized away"),
528 llvm::cl::values(
529 clEnumValN(firrtl::PreserveValues::Strip, "strip",
530 "Strip all names. No name is preserved"),
531 clEnumValN(firrtl::PreserveValues::None, "none",
532 "Names could be preserved by best-effort unlike `strip`"),
533 clEnumValN(firrtl::PreserveValues::Named, "named",
534 "Preserve values with meaningful names"),
535 clEnumValN(firrtl::PreserveValues::All, "all",
536 "Preserve all values")),
537 llvm::cl::init(firrtl::PreserveValues::None)};
538
539 llvm::cl::opt<bool> enableDebugInfo{
540 "g", llvm::cl::desc("Enable the generation of debug information"),
541 llvm::cl::init(false)};
542
543 // Build mode options.
545 "O", llvm::cl::desc("Controls how much optimization should be performed"),
546 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
547 "debug",
548 "Compile with only necessary optimizations"),
550 "release", "Compile with optimizations")),
552
553 llvm::cl::opt<bool> disableLayerSink{"disable-layer-sink",
554 llvm::cl::desc("Disable layer sink"),
555 cl::init(false)};
556
557 llvm::cl::opt<bool> disableOptimization{
558 "disable-opt",
559 llvm::cl::desc("Disable optimizations"),
560 };
561
562 llvm::cl::opt<bool> vbToBV{
563 "vb-to-bv",
564 llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
565 llvm::cl::init(false)};
566
567 llvm::cl::opt<bool> noDedup{
568 "no-dedup",
569 llvm::cl::desc("Disable deduplication of structurally identical modules"),
570 llvm::cl::init(false)};
571
572 llvm::cl::opt<bool> dedupClasses{
573 "dedup-classes",
574 llvm::cl::desc(
575 "Deduplicate FIRRTL classes, violating their nominal typing"),
576 llvm::cl::init(true)};
577
579 "grand-central-companion-mode",
580 llvm::cl::desc("Specifies the handling of Grand Central companions"),
581 ::llvm::cl::values(
582 clEnumValN(firrtl::CompanionMode::Bind, "bind",
583 "Lower companion instances to SystemVerilog binds"),
584 clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
585 "Instantiate companions in the design"),
586 clEnumValN(firrtl::CompanionMode::Drop, "drop",
587 "Remove companions from the design")),
588 llvm::cl::init(firrtl::CompanionMode::Bind),
589 llvm::cl::Hidden,
590 };
591
592 llvm::cl::opt<bool> noViews{
593 "no-views",
594 llvm::cl::desc(
595 "Disable lowering of FIRRTL view intrinsics (delete them instead)"),
596 llvm::cl::init(false),
597 };
598
599 llvm::cl::opt<bool> disableAggressiveMergeConnections{
600 "disable-aggressive-merge-connections",
601 llvm::cl::desc(
602 "Disable aggressive merge connections (i.e. merge all field-level "
603 "connections into bulk connections)"),
604 llvm::cl::init(false)};
605
606 llvm::cl::opt<bool> lowerMemories{
607 "lower-memories",
608 llvm::cl::desc("Lower memories to have memories with masks as an "
609 "array with one memory per ground type"),
610 llvm::cl::init(false)};
611
612 llvm::cl::opt<std::string> blackBoxRootPath{
613 "blackbox-path",
614 llvm::cl::desc(
615 "Optional path to use as the root of black box annotations"),
616 llvm::cl::value_desc("path"),
617 llvm::cl::init(""),
618 };
619
620 llvm::cl::opt<bool> replSeqMem{
621 "repl-seq-mem",
622 llvm::cl::desc("Replace the seq mem for macro replacement and emit "
623 "relevant metadata"),
624 llvm::cl::init(false)};
625
626 llvm::cl::opt<std::string> replSeqMemFile{
627 "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
628 llvm::cl::init("")};
629
630 llvm::cl::opt<bool> ignoreReadEnableMem{
631 "ignore-read-enable-mem",
632 llvm::cl::desc("Ignore the read enable signal, instead of "
633 "assigning X on read disable"),
634 llvm::cl::init(false)};
635
636 firtool::FirtoolOptions::RandomKind disableRandomValue =
637 firtool::FirtoolOptions::RandomKind::None;
638
639 // Make these options (and their grouping category) inaccessible as their
640 // values are not intended to be used directly. These change a lattice of
641 // randomization disable settings and directly accessing the command line
642 // option the user provided is not useful.
643private:
644 llvm::cl::OptionCategory randomizationCategory{
645 "Disable random initialization code (may break semantics!)"};
646
647 llvm::cl::opt<bool> disableMemRandom{
648 "disable-mem-randomization",
649 llvm::cl::desc("Disable emission of memory randomization code"),
650 llvm::cl::cat(randomizationCategory), llvm::cl::ValueDisallowed,
651 llvm::cl::callback([&](const bool &) {
652 disableRandomValue = firtool::FirtoolOptions::mergeRandomKind(
653 disableRandomValue, firtool::FirtoolOptions::RandomKind::Mem);
654 })};
655
656 llvm::cl::opt<bool> disableRegRandom{
657 "disable-reg-randomization",
658 llvm::cl::desc("Disable emission of register randomization code"),
659 llvm::cl::cat(randomizationCategory), llvm::cl::ValueDisallowed,
660 llvm::cl::callback([&](const bool &) {
661 disableRandomValue = firtool::FirtoolOptions::mergeRandomKind(
662 disableRandomValue, firtool::FirtoolOptions::RandomKind::Reg);
663 })};
664
665 llvm::cl::opt<bool> disableAllRandom{
666 "disable-all-randomization",
667 llvm::cl::desc("Disable emission of all randomization code"),
668 llvm::cl::cat(randomizationCategory), llvm::cl::ValueDisallowed,
669 llvm::cl::callback([&](const bool &) {
670 disableRandomValue = firtool::FirtoolOptions::RandomKind::All;
671 })};
672
673public:
674 llvm::cl::opt<std::string> outputAnnotationFilename{
675 "output-annotation-file",
676 llvm::cl::desc("Optional output annotation file"),
677 llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
678
679 llvm::cl::opt<bool> enableAnnotationWarning{
680 "warn-on-unprocessed-annotations",
681 llvm::cl::desc(
682 "Warn about annotations that were not removed by lower-to-hw"),
683 llvm::cl::init(false)};
684
685 llvm::cl::opt<bool> lowerToCore{
686 "lower-to-core",
687 llvm::cl::desc("Prefer core dialects over direct SV lowering for FIRRTL "
688 "verification and printf operations"),
689 llvm::cl::init(false)};
690
691 llvm::cl::opt<bool> addMuxPragmas{
692 "add-mux-pragmas",
693 llvm::cl::desc("Annotate mux pragmas for memory array access"),
694 llvm::cl::init(false)};
695
697 "verification-flavor",
698 llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
699 llvm::cl::values(
700 clEnumValN(firrtl::VerificationFlavor::None, "none",
701 "Use the flavor specified by the op"),
702 clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
703 "Use Use `if(cond) else $fatal(..)` format"),
704 clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
705 "Use immediate verif statements"),
706 clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
707 llvm::cl::init(firrtl::VerificationFlavor::None)};
708
709 llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
710 "emit-separate-always-blocks",
711 llvm::cl::desc(
712 "Prevent always blocks from being merged and emit constructs into "
713 "separate always blocks whenever possible"),
714 llvm::cl::init(false)};
715
716 llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
717 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
718 llvm::cl::desc(
719 "Add a vivado specific SV attribute (* ram_style = "
720 "\"distributed\" *) to unpacked array registers as a workaronud "
721 "for a vivado synthesis bug that incorrectly modifies "
722 "address conflict behavivor of combinational memories"),
723 llvm::cl::init(false)};
724
725 //===----------------------------------------------------------------------===
726 // External Clock Gate Options
727 //===----------------------------------------------------------------------===
728
729 llvm::cl::opt<std::string> ckgModuleName{
730 "ckg-name", llvm::cl::desc("Clock gate module name"),
731 llvm::cl::init("EICG_wrapper")};
732
733 llvm::cl::opt<std::string> ckgInputName{
734 "ckg-input", llvm::cl::desc("Clock gate input port name"),
735 llvm::cl::init("in")};
736
737 llvm::cl::opt<std::string> ckgOutputName{
738 "ckg-output", llvm::cl::desc("Clock gate output port name"),
739 llvm::cl::init("out")};
740
741 llvm::cl::opt<std::string> ckgEnableName{
742 "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
743 llvm::cl::init("en")};
744
745 llvm::cl::opt<std::string> ckgTestEnableName{
746 "ckg-test-enable",
747 llvm::cl::desc("Clock gate test enable port name (optional)"),
748 llvm::cl::init("test_en")};
749
750 llvm::cl::opt<bool> exportModuleHierarchy{
751 "export-module-hierarchy",
752 llvm::cl::desc("Export module and instance hierarchy as JSON"),
753 llvm::cl::init(false)};
754
755 llvm::cl::opt<bool> stripFirDebugInfo{
756 "strip-fir-debug-info",
757 llvm::cl::desc(
758 "Disable source fir locator information in output Verilog"),
759 llvm::cl::init(true)};
760
761 llvm::cl::opt<bool> stripDebugInfo{
762 "strip-debug-info",
763 llvm::cl::desc("Disable source locator information in output Verilog"),
764 llvm::cl::init(false)};
765
766 llvm::cl::opt<bool> fixupEICGWrapper{
767 "fixup-eicg-wrapper",
768 llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
769 llvm::cl::init(false)};
770
771 llvm::cl::opt<bool> selectDefaultInstanceChoice{
772 "select-default-for-unspecified-instance-choice",
773 llvm::cl::desc(
774 "Specialize instance choice to default, if no option selected"),
775 llvm::cl::init(false)};
776
778 "symbolic-values",
779 llvm::cl::desc("Control how symbolic values are lowered"),
780 llvm::cl::init(verif::SymbolicValueLowering::ExtModule),
781 verif::symbolicValueLoweringCLValues()};
782
783 llvm::cl::opt<bool> disableWireElimination{
784 "disable-wire-elimination", llvm::cl::desc("Disable wire elimination"),
785 llvm::cl::init(false)};
786
787 llvm::cl::opt<bool> emitAllBindFiles{
788 "emit-all-bind-files",
789 llvm::cl::desc("Emit bindfiles for private modules"),
790 llvm::cl::init(false)};
791
792 llvm::cl::opt<bool> inlineInputOnlyModules{
793 "inline-input-only-modules", llvm::cl::desc("Inline input-only modules"),
794 llvm::cl::init(false)};
795
797 "domain-mode", llvm::cl::desc("Enable domain inference and checking"),
798 llvm::cl::init(firtool::FirtoolOptions::DomainMode::Strip),
799 llvm::cl::values(
800 clEnumValN(firtool::FirtoolOptions::DomainMode::Check, "check",
801 "Check domains without inference"),
802 clEnumValN(firtool::FirtoolOptions::DomainMode::Disable, "disable",
803 "Disable domain checking"),
804 clEnumValN(firtool::FirtoolOptions::DomainMode::Infer, "infer",
805 "Check domains with inference for private modules"),
806 clEnumValN(firtool::FirtoolOptions::DomainMode::InferAll, "infer-all",
807 "Check domains with inference for both public and private "
808 "modules"),
809 clEnumValN(firtool::FirtoolOptions::DomainMode::Strip, "strip",
810 "Erase all domain information"))};
811
812 //===----------------------------------------------------------------------===
813 // Lint options
814 //===----------------------------------------------------------------------===
815
816 llvm::cl::opt<bool> lintStaticAsserts{
817 "lint-static-asserts", llvm::cl::desc("Lint static assertions"),
818 llvm::cl::init(true)};
819 // TODO: Change this default to 'true' once this has been better tested and
820 // `-sv-extract-test-code` has been removed.
821 llvm::cl::opt<bool> lintXmrsInDesign{
822 "lint-xmrs-in-design", llvm::cl::desc("Lint XMRs in the design"),
823 llvm::cl::init(false)};
824};
825} // namespace
826
827static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
828
829/// Register a set of useful command-line options that can be used to configure
830/// various flags within the MLIRContext. These flags are used when constructing
831/// an MLIR context for initialization.
833 // Make sure that the options struct has been initialized.
834 *clOptions;
835}
836
837// Initialize the firtool options with defaults supplied by the cl::opts above.
839 : outputFilename("-"), disableAnnotationsUnknown(false),
840 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
841 probesToSignals(false),
842 preserveAggregate(firrtl::PreserveAggregate::None),
843 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
844 buildMode(BuildModeRelease), disableLayerSink(false),
845 disableOptimization(false), vbToBV(false), noDedup(false),
846 dedupClasses(true), companionMode(firrtl::CompanionMode::Bind),
847 noViews(false), disableAggressiveMergeConnections(false),
848 lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
849 replSeqMemFile(""), ignoreReadEnableMem(false),
850 disableRandom(RandomKind::None), outputAnnotationFilename(""),
851 enableAnnotationWarning(false), lowerToCore(false), addMuxPragmas(false),
852 verificationFlavor(firrtl::VerificationFlavor::None),
853 emitSeparateAlwaysBlocks(false),
854 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
855 ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
856 ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
857 exportModuleHierarchy(false), stripFirDebugInfo(true),
858 stripDebugInfo(false), fixupEICGWrapper(false),
859 disableCSEinClasses(false), selectDefaultInstanceChoice(false),
860 symbolicValueLowering(verif::SymbolicValueLowering::ExtModule),
861 disableWireElimination(false), lintStaticAsserts(true),
862 lintXmrsInDesign(true), emitAllBindFiles(false),
863 inlineInputOnlyModules(false), domainMode(DomainMode::Disable) {
864 if (!clOptions.isConstructed())
865 return;
866 outputFilename = clOptions->outputFilename;
867 disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
868 disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
869 lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
870 probesToSignals = clOptions->probesToSignals;
871 preserveAggregate = clOptions->preserveAggregate;
872 preserveMode = clOptions->preserveMode;
873 enableDebugInfo = clOptions->enableDebugInfo;
874 buildMode = clOptions->buildMode;
875 disableLayerSink = clOptions->disableLayerSink;
876 disableOptimization = clOptions->disableOptimization;
877 vbToBV = clOptions->vbToBV;
878 noDedup = clOptions->noDedup;
879 dedupClasses = clOptions->dedupClasses;
880 companionMode = clOptions->companionMode;
881 noViews = clOptions->noViews;
883 clOptions->disableAggressiveMergeConnections;
884 lowerMemories = clOptions->lowerMemories;
885 blackBoxRootPath = clOptions->blackBoxRootPath;
886 replSeqMem = clOptions->replSeqMem;
887 replSeqMemFile = clOptions->replSeqMemFile;
888 ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
889 disableRandom = clOptions->disableRandomValue;
890 outputAnnotationFilename = clOptions->outputAnnotationFilename;
891 enableAnnotationWarning = clOptions->enableAnnotationWarning;
892 lowerToCore = clOptions->lowerToCore;
893 addMuxPragmas = clOptions->addMuxPragmas;
894 verificationFlavor = clOptions->verificationFlavor;
895 emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
897 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
898 ckgModuleName = clOptions->ckgModuleName;
899 ckgInputName = clOptions->ckgInputName;
900 ckgOutputName = clOptions->ckgOutputName;
901 ckgEnableName = clOptions->ckgEnableName;
902 ckgTestEnableName = clOptions->ckgTestEnableName;
903 exportModuleHierarchy = clOptions->exportModuleHierarchy;
904 stripFirDebugInfo = clOptions->stripFirDebugInfo;
905 stripDebugInfo = clOptions->stripDebugInfo;
906 fixupEICGWrapper = clOptions->fixupEICGWrapper;
907 selectDefaultInstanceChoice = clOptions->selectDefaultInstanceChoice;
908 symbolicValueLowering = clOptions->symbolicValueLowering;
909 disableWireElimination = clOptions->disableWireElimination;
910 lintStaticAsserts = clOptions->lintStaticAsserts;
911 lintXmrsInDesign = clOptions->lintXmrsInDesign;
912 emitAllBindFiles = clOptions->emitAllBindFiles;
913 inlineInputOnlyModules = clOptions->inlineInputOnlyModules;
914 domainMode = clOptions->domainMode;
915}
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition Firtool.cpp:827
Set of options used to control the behavior of the firtool pipeline.
Definition Firtool.h:32
bool shouldStripDebugInfo() const
Definition Firtool.h:151
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition Firtool.h:109
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition Firtool.h:164
bool shouldDisableLayerSink() const
Definition Firtool.h:143
firrtl::PreserveValues::PreserveMode preserveMode
Definition Firtool.h:437
auto getVerificationFlavor() const
Definition Firtool.h:159
StringRef getOutputFilename() const
Definition Firtool.h:102
bool shouldDisableAggressiveMergeConnections() const
Definition Firtool.h:154
StringRef getReplaceSequentialMemoriesFile() const
Definition Firtool.h:104
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition Firtool.h:460
bool shouldFixupEICGWrapper() const
Definition Firtool.h:167
bool shouldConvertProbesToSignals() const
Definition Firtool.h:141
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition Firtool.h:90
bool shouldDedupClasses() const
Definition Firtool.h:147
StringRef getBlackBoxRootPath() const
Definition Firtool.h:103
bool shouldDisableCSEinClasses() const
Definition Firtool.h:168
bool shouldDisableOptimization() const
Definition Firtool.h:144
firrtl::CompanionMode getCompanionMode() const
Definition Firtool.h:112
bool shouldDisableClasslessAnnotations() const
Definition Firtool.h:135
bool getEmitAllBindFiles() const
Definition Firtool.h:182
bool shouldReplaceSequentialMemories() const
Definition Firtool.h:142
bool shouldIgnoreReadEnableMemories() const
Definition Firtool.h:149
bool isRandomEnabled(RandomKind kind) const
Definition Firtool.h:71
bool shouldDisableUnknownAnnotations() const
Definition Firtool.h:132
static RandomKind mergeRandomKind(RandomKind current, RandomKind incoming)
Advance the disabled-randomization lattice.
Definition Firtool.h:77
bool shouldAddMuxPragmas() const
Definition Firtool.h:163
bool shouldEnableAnnotationWarning() const
Definition Firtool.h:157
bool shouldConvertVecOfBundle() const
Definition Firtool.h:150
StringRef getOutputAnnotationFilename() const
Definition Firtool.h:105
bool shouldStripFirDebugInfo() const
Definition Firtool.h:152
std::string outputAnnotationFilename
Definition Firtool.h:454
firrtl::VerificationFlavor verificationFlavor
Definition Firtool.h:458
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition Firtool.h:436
bool shouldLowerMemories() const
Definition Firtool.h:145
DomainMode getDomainMode() const
Definition Firtool.h:186
bool getLintStaticAsserts() const
Definition Firtool.h:178
bool shouldLowerNoRefTypePortAnnotations() const
Definition Firtool.h:138
verif::SymbolicValueLowering getSymbolicValueLowering() const
Definition Firtool.h:173
bool shouldExportModuleHierarchy() const
Definition Firtool.h:153
firrtl::CompanionMode companionMode
Definition Firtool.h:445
bool shouldDisableWireElimination() const
Definition Firtool.h:176
bool shouldSelectDefaultInstanceChoice() const
Definition Firtool.h:169
bool shouldInlineInputOnlyModules() const
Definition Firtool.h:184
verif::SymbolicValueLowering symbolicValueLowering
Definition Firtool.h:473
bool getLintXmrsInDesign() const
Definition Firtool.h:180
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition Firtool.h:116
bool shouldEnableDebugInfo() const
Definition Firtool.h:148
bool shouldEmitSeparateAlwaysBlocks() const
Definition Firtool.h:160
@ All
Preserve all aggregate values.
Definition Passes.h:40
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
Definition Passes.h:34
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
Definition Passes.h:37
@ None
Don't preserve aggregate at all.
Definition Passes.h:31
@ None
Don't explicitly preserve any named values.
Definition Passes.h:52
@ Strip
Strip all names. No name on declaration is preserved.
Definition Passes.h:48
LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition Firtool.cpp:236
LogicalResult populateHWToBTOR2(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::raw_ostream &os)
BTOR2 emission pipeline, triggered with --btor2 flag.
Definition Firtool.cpp:453
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition Firtool.cpp:428
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:325
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition Firtool.cpp:409
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:832
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:438
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:54
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::Pass > createExportSplitVerilogPass(llvm::StringRef directory="./")
std::unique_ptr< mlir::Pass > createLowerFIRRTLToHWPass(bool enableAnnotationWarning=false, firrtl::VerificationFlavor assertionFlavor=firrtl::VerificationFlavor::None, bool lowerToCore=false)
This is the pass constructor.
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:858
std::unique_ptr< mlir::Pass > createLowerLTLToCorePass()
std::unique_ptr< mlir::Pass > createLowerSimToSVPass()
Definition SimToSV.cpp:943
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 > 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:373
Definition verif.py:1