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());
207 }
208
209 // Always run this, required for legalization.
210 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
211 firrtl::createMergeConnections(
212 {/*enableAggressiveMergin=*/!opt
214
215 if (!opt.shouldDisableOptimization())
216 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
217 firrtl::createVectorization());
218
219 return success();
220}
221
222LogicalResult firtool::populateLowFIRRTLToHW(mlir::PassManager &pm,
223 const FirtoolOptions &opt,
224 StringRef inputFilename) {
225 // Run layersink immediately before LowerXMR. LowerXMR will "freeze" the
226 // location of probed objects by placing symbols on them. Run layersink first
227 // so that probed objects can be sunk if possible.
229 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLayerSink());
230
231 // Lower the ref.resolve and ref.send ops and remove the RefType ports.
232 // LowerToHW cannot handle RefType so, this pass must be run to remove all
233 // RefType ports and ops.
234 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMR());
235
236 // Layer lowering passes. Move operations into layers when possible and
237 // remove layers by converting them to other constructs. This lowering
238 // process can create a few optimization opportunities.
239 //
240 // TODO: Improve LowerLayers to avoid the need for canonicalization. See:
241 // https://github.com/llvm/circt/issues/7896
242
243 pm.nest<firrtl::CircuitOp>().addPass(
244 firrtl::createLowerLayers({opt.getEmitAllBindFiles()}));
245 if (!opt.shouldDisableOptimization())
246 pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
248
249 auto outputFilename = opt.getOutputFilename();
250 if (outputFilename == "-")
251 outputFilename = "";
252
253 pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAssignOutputDirs(
254 {/*outputDirOption=*/outputFilename.str()}));
255
256 // Run passes to resolve Grand Central features. This should run before
257 // BlackBoxReader because Grand Central needs to inform BlackBoxReader where
258 // certain black boxes should be placed. Note: all Grand Central Taps related
259 // collateral is resolved entirely by LowerAnnotations.
260 // Run this after output directories are (otherwise) assigned,
261 // so generated interfaces can be appropriately marked.
262 pm.addNestedPass<firrtl::CircuitOp>(
263 firrtl::createGrandCentral({/*companionMode=*/opt.getCompanionMode(),
264 /*noViews*/ opt.getNoViews()}));
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::createLowerTestsPass());
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> probesToSignals{
486 "probes-to-signals",
487 llvm::cl::desc("Convert probes to non-probe signals"),
488 llvm::cl::init(false), llvm::cl::Hidden};
489
491 preserveAggregate{
492 "preserve-aggregate",
493 llvm::cl::desc("Specify input file format:"),
494 llvm::cl::values(
496 "Preserve no aggregate"),
498 "Preserve only 1d vectors of ground type"),
500 "Preserve only vectors"),
502 "Preserve vectors and bundles")),
504 };
505
507 "preserve-values",
508 llvm::cl::desc("Specify the values which can be optimized away"),
509 llvm::cl::values(
510 clEnumValN(firrtl::PreserveValues::Strip, "strip",
511 "Strip all names. No name is preserved"),
512 clEnumValN(firrtl::PreserveValues::None, "none",
513 "Names could be preserved by best-effort unlike `strip`"),
514 clEnumValN(firrtl::PreserveValues::Named, "named",
515 "Preserve values with meaningful names"),
516 clEnumValN(firrtl::PreserveValues::All, "all",
517 "Preserve all values")),
518 llvm::cl::init(firrtl::PreserveValues::None)};
519
520 llvm::cl::opt<bool> enableDebugInfo{
521 "g", llvm::cl::desc("Enable the generation of debug information"),
522 llvm::cl::init(false)};
523
524 // Build mode options.
526 "O", llvm::cl::desc("Controls how much optimization should be performed"),
527 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
528 "debug",
529 "Compile with only necessary optimizations"),
531 "release", "Compile with optimizations")),
533
534 llvm::cl::opt<bool> disableLayerSink{"disable-layer-sink",
535 llvm::cl::desc("Disable layer sink"),
536 cl::init(false)};
537
538 llvm::cl::opt<bool> disableOptimization{
539 "disable-opt",
540 llvm::cl::desc("Disable optimizations"),
541 };
542
543 llvm::cl::opt<bool> vbToBV{
544 "vb-to-bv",
545 llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
546 llvm::cl::init(false)};
547
548 llvm::cl::opt<bool> noDedup{
549 "no-dedup",
550 llvm::cl::desc("Disable deduplication of structurally identical modules"),
551 llvm::cl::init(false)};
552
553 llvm::cl::opt<bool> dedupClasses{
554 "dedup-classes",
555 llvm::cl::desc(
556 "Deduplicate FIRRTL classes, violating their nominal typing"),
557 llvm::cl::init(true)};
558
560 "grand-central-companion-mode",
561 llvm::cl::desc("Specifies the handling of Grand Central companions"),
562 ::llvm::cl::values(
563 clEnumValN(firrtl::CompanionMode::Bind, "bind",
564 "Lower companion instances to SystemVerilog binds"),
565 clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
566 "Instantiate companions in the design"),
567 clEnumValN(firrtl::CompanionMode::Drop, "drop",
568 "Remove companions from the design")),
569 llvm::cl::init(firrtl::CompanionMode::Bind),
570 llvm::cl::Hidden,
571 };
572
573 llvm::cl::opt<bool> noViews{
574 "no-views",
575 llvm::cl::desc(
576 "Disable lowering of FIRRTL view intrinsics (delete them instead)"),
577 llvm::cl::init(false),
578 };
579
580 llvm::cl::opt<bool> disableAggressiveMergeConnections{
581 "disable-aggressive-merge-connections",
582 llvm::cl::desc(
583 "Disable aggressive merge connections (i.e. merge all field-level "
584 "connections into bulk connections)"),
585 llvm::cl::init(false)};
586
587 llvm::cl::opt<bool> lowerMemories{
588 "lower-memories",
589 llvm::cl::desc("Lower memories to have memories with masks as an "
590 "array with one memory per ground type"),
591 llvm::cl::init(false)};
592
593 llvm::cl::opt<std::string> blackBoxRootPath{
594 "blackbox-path",
595 llvm::cl::desc(
596 "Optional path to use as the root of black box annotations"),
597 llvm::cl::value_desc("path"),
598 llvm::cl::init(""),
599 };
600
601 llvm::cl::opt<bool> replSeqMem{
602 "repl-seq-mem",
603 llvm::cl::desc("Replace the seq mem for macro replacement and emit "
604 "relevant metadata"),
605 llvm::cl::init(false)};
606
607 llvm::cl::opt<std::string> replSeqMemFile{
608 "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
609 llvm::cl::init("")};
610
611 llvm::cl::opt<bool> extractTestCode{
612 "extract-test-code", llvm::cl::desc("Run the extract test code pass"),
613 llvm::cl::init(false)};
614
615 llvm::cl::opt<bool> ignoreReadEnableMem{
616 "ignore-read-enable-mem",
617 llvm::cl::desc("Ignore the read enable signal, instead of "
618 "assigning X on read disable"),
619 llvm::cl::init(false)};
620
622 llvm::cl::desc(
623 "Disable random initialization code (may break semantics!)"),
624 llvm::cl::values(
625 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
626 "disable-mem-randomization",
627 "Disable emission of memory randomization code"),
628 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
629 "disable-reg-randomization",
630 "Disable emission of register randomization code"),
631 clEnumValN(firtool::FirtoolOptions::RandomKind::All,
632 "disable-all-randomization",
633 "Disable emission of all randomization code")),
634 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
635
636 llvm::cl::opt<std::string> outputAnnotationFilename{
637 "output-annotation-file",
638 llvm::cl::desc("Optional output annotation file"),
639 llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
640
641 llvm::cl::opt<bool> enableAnnotationWarning{
642 "warn-on-unprocessed-annotations",
643 llvm::cl::desc(
644 "Warn about annotations that were not removed by lower-to-hw"),
645 llvm::cl::init(false)};
646
647 llvm::cl::opt<bool> addMuxPragmas{
648 "add-mux-pragmas",
649 llvm::cl::desc("Annotate mux pragmas for memory array access"),
650 llvm::cl::init(false)};
651
653 "verification-flavor",
654 llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
655 llvm::cl::values(
656 clEnumValN(firrtl::VerificationFlavor::None, "none",
657 "Use the flavor specified by the op"),
658 clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
659 "Use Use `if(cond) else $fatal(..)` format"),
660 clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
661 "Use immediate verif statements"),
662 clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
663 llvm::cl::init(firrtl::VerificationFlavor::None)};
664
665 llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
666 "emit-separate-always-blocks",
667 llvm::cl::desc(
668 "Prevent always blocks from being merged and emit constructs into "
669 "separate always blocks whenever possible"),
670 llvm::cl::init(false)};
671
672 llvm::cl::opt<bool> etcDisableInstanceExtraction{
673 "etc-disable-instance-extraction",
674 llvm::cl::desc("Disable extracting instances only that feed test code"),
675 llvm::cl::init(false)};
676
677 llvm::cl::opt<bool> etcDisableRegisterExtraction{
678 "etc-disable-register-extraction",
679 llvm::cl::desc("Disable extracting registers that only feed test code"),
680 llvm::cl::init(false)};
681
682 llvm::cl::opt<bool> etcDisableModuleInlining{
683 "etc-disable-module-inlining",
684 llvm::cl::desc("Disable inlining modules that only feed test code"),
685 llvm::cl::init(false)};
686
687 llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
688 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
689 llvm::cl::desc(
690 "Add a vivado specific SV attribute (* ram_style = "
691 "\"distributed\" *) to unpacked array registers as a workaronud "
692 "for a vivado synthesis bug that incorrectly modifies "
693 "address conflict behavivor of combinational memories"),
694 llvm::cl::init(false)};
695
696 //===----------------------------------------------------------------------===
697 // External Clock Gate Options
698 //===----------------------------------------------------------------------===
699
700 llvm::cl::opt<std::string> ckgModuleName{
701 "ckg-name", llvm::cl::desc("Clock gate module name"),
702 llvm::cl::init("EICG_wrapper")};
703
704 llvm::cl::opt<std::string> ckgInputName{
705 "ckg-input", llvm::cl::desc("Clock gate input port name"),
706 llvm::cl::init("in")};
707
708 llvm::cl::opt<std::string> ckgOutputName{
709 "ckg-output", llvm::cl::desc("Clock gate output port name"),
710 llvm::cl::init("out")};
711
712 llvm::cl::opt<std::string> ckgEnableName{
713 "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
714 llvm::cl::init("en")};
715
716 llvm::cl::opt<std::string> ckgTestEnableName{
717 "ckg-test-enable",
718 llvm::cl::desc("Clock gate test enable port name (optional)"),
719 llvm::cl::init("test_en")};
720
721 llvm::cl::opt<bool> exportModuleHierarchy{
722 "export-module-hierarchy",
723 llvm::cl::desc("Export module and instance hierarchy as JSON"),
724 llvm::cl::init(false)};
725
726 llvm::cl::opt<bool> stripFirDebugInfo{
727 "strip-fir-debug-info",
728 llvm::cl::desc(
729 "Disable source fir locator information in output Verilog"),
730 llvm::cl::init(true)};
731
732 llvm::cl::opt<bool> stripDebugInfo{
733 "strip-debug-info",
734 llvm::cl::desc("Disable source locator information in output Verilog"),
735 llvm::cl::init(false)};
736
737 llvm::cl::opt<bool> fixupEICGWrapper{
738 "fixup-eicg-wrapper",
739 llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
740 llvm::cl::init(false)};
741
742 llvm::cl::opt<bool> selectDefaultInstanceChoice{
743 "select-default-for-unspecified-instance-choice",
744 llvm::cl::desc(
745 "Specialize instance choice to default, if no option selected"),
746 llvm::cl::init(false)};
747
749 "symbolic-values",
750 llvm::cl::desc("Control how symbolic values are lowered"),
751 llvm::cl::init(verif::SymbolicValueLowering::ExtModule),
752 verif::symbolicValueLoweringCLValues()};
753
754 llvm::cl::opt<bool> disableWireElimination{
755 "disable-wire-elimination", llvm::cl::desc("Disable wire elimination"),
756 llvm::cl::init(false)};
757
758 llvm::cl::opt<bool> emitAllBindFiles{
759 "emit-all-bind-files",
760 llvm::cl::desc("Emit bindfiles for private modules"),
761 llvm::cl::init(false)};
762
763 //===----------------------------------------------------------------------===
764 // Lint options
765 //===----------------------------------------------------------------------===
766
767 llvm::cl::opt<bool> lintStaticAsserts{
768 "lint-static-asserts", llvm::cl::desc("Lint static assertions"),
769 llvm::cl::init(true)};
770 // TODO: Change this default to 'true' once this has been better tested and
771 // `-sv-extract-test-code` has been removed.
772 llvm::cl::opt<bool> lintXmrsInDesign{
773 "lint-xmrs-in-design", llvm::cl::desc("Lint XMRs in the design"),
774 llvm::cl::init(false)};
775};
776} // namespace
777
778static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
779
780/// Register a set of useful command-line options that can be used to configure
781/// various flags within the MLIRContext. These flags are used when constructing
782/// an MLIR context for initialization.
784 // Make sure that the options struct has been initialized.
785 *clOptions;
786}
787
788// Initialize the firtool options with defaults supplied by the cl::opts above.
790 : outputFilename("-"), disableAnnotationsUnknown(false),
791 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
792 probesToSignals(false),
793 preserveAggregate(firrtl::PreserveAggregate::None),
794 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
795 buildMode(BuildModeRelease), disableLayerSink(false),
796 disableOptimization(false), vbToBV(false), noDedup(false),
797 dedupClasses(true), companionMode(firrtl::CompanionMode::Bind),
798 noViews(false), disableAggressiveMergeConnections(false),
799 lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
800 replSeqMemFile(""), extractTestCode(false), ignoreReadEnableMem(false),
801 disableRandom(RandomKind::None), outputAnnotationFilename(""),
802 enableAnnotationWarning(false), addMuxPragmas(false),
803 verificationFlavor(firrtl::VerificationFlavor::None),
804 emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
805 etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
806 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
807 ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
808 ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
809 exportModuleHierarchy(false), stripFirDebugInfo(true),
810 stripDebugInfo(false), fixupEICGWrapper(false),
811 disableCSEinClasses(false), selectDefaultInstanceChoice(false),
812 symbolicValueLowering(verif::SymbolicValueLowering::ExtModule),
813 disableWireElimination(false), lintStaticAsserts(true),
814 lintXmrsInDesign(true), emitAllBindFiles(false) {
815 if (!clOptions.isConstructed())
816 return;
817 outputFilename = clOptions->outputFilename;
818 disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
819 disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
820 lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
821 probesToSignals = clOptions->probesToSignals;
822 preserveAggregate = clOptions->preserveAggregate;
823 preserveMode = clOptions->preserveMode;
824 enableDebugInfo = clOptions->enableDebugInfo;
825 buildMode = clOptions->buildMode;
826 disableLayerSink = clOptions->disableLayerSink;
827 disableOptimization = clOptions->disableOptimization;
828 vbToBV = clOptions->vbToBV;
829 noDedup = clOptions->noDedup;
830 dedupClasses = clOptions->dedupClasses;
831 companionMode = clOptions->companionMode;
832 noViews = clOptions->noViews;
834 clOptions->disableAggressiveMergeConnections;
835 lowerMemories = clOptions->lowerMemories;
836 blackBoxRootPath = clOptions->blackBoxRootPath;
837 replSeqMem = clOptions->replSeqMem;
838 replSeqMemFile = clOptions->replSeqMemFile;
839 extractTestCode = clOptions->extractTestCode;
840 ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
841 disableRandom = clOptions->disableRandom;
842 outputAnnotationFilename = clOptions->outputAnnotationFilename;
843 enableAnnotationWarning = clOptions->enableAnnotationWarning;
844 addMuxPragmas = clOptions->addMuxPragmas;
845 verificationFlavor = clOptions->verificationFlavor;
846 emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
847 etcDisableInstanceExtraction = clOptions->etcDisableInstanceExtraction;
848 etcDisableRegisterExtraction = clOptions->etcDisableRegisterExtraction;
849 etcDisableModuleInlining = clOptions->etcDisableModuleInlining;
851 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
852 ckgModuleName = clOptions->ckgModuleName;
853 ckgInputName = clOptions->ckgInputName;
854 ckgOutputName = clOptions->ckgOutputName;
855 ckgEnableName = clOptions->ckgEnableName;
856 ckgTestEnableName = clOptions->ckgTestEnableName;
857 exportModuleHierarchy = clOptions->exportModuleHierarchy;
858 stripFirDebugInfo = clOptions->stripFirDebugInfo;
859 stripDebugInfo = clOptions->stripDebugInfo;
860 fixupEICGWrapper = clOptions->fixupEICGWrapper;
861 selectDefaultInstanceChoice = clOptions->selectDefaultInstanceChoice;
862 symbolicValueLowering = clOptions->symbolicValueLowering;
863 disableWireElimination = clOptions->disableWireElimination;
864 lintStaticAsserts = clOptions->lintStaticAsserts;
865 lintXmrsInDesign = clOptions->lintXmrsInDesign;
866 emitAllBindFiles = clOptions->emitAllBindFiles;
867}
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition Firtool.cpp:778
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:405
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:431
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:423
firrtl::VerificationFlavor verificationFlavor
Definition Firtool.h:426
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition Firtool.h:404
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:413
bool shouldDisableWireElimination() const
Definition Firtool.h:138
bool shouldSelectDefaultInstanceChoice() const
Definition Firtool.h:131
verif::SymbolicValueLowering symbolicValueLowering
Definition Firtool.h:444
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:222
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:783
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:434
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:366
Definition verif.py:1