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