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