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