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