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