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