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
309 opt.getVerificationFlavor()));
310
311 if (!opt.shouldDisableOptimization()) {
312 auto &modulePM = pm.nest<hw::HWModuleOp>();
313 modulePM.addPass(mlir::createCSEPass());
314 modulePM.addPass(createSimpleCanonicalizerPass());
315 }
316
317 // Check inner symbols and inner refs.
318 pm.addPass(hw::createVerifyInnerRefNamespace());
319
320 // Check OM object fields.
321 pm.addPass(om::createVerifyObjectFieldsPass());
322
323 // Run the verif op verification pass
324 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
325
326 return success();
327}
328
329LogicalResult firtool::populateHWToSV(mlir::PassManager &pm,
330 const FirtoolOptions &opt) {
331 pm.nestAny().addPass(verif::createStripContractsPass());
332 pm.addPass(verif::createLowerTestsPass());
333 pm.addPass(
334 verif::createLowerSymbolicValuesPass({opt.getSymbolicValueLowering()}));
335
336 pm.addPass(seq::createExternalizeClockGate(opt.getClockGateOptions()));
337 pm.addPass(circt::createLowerSimToSVPass());
339 {/*disableRegRandomization=*/!opt.isRandomEnabled(
340 FirtoolOptions::RandomKind::Reg),
341 /*disableMemRandomization=*/
342 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
343 /*emitSeparateAlwaysBlocks=*/
345 pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
346 pm.addPass(seq::createHWMemSimImpl(
347 {/*disableMemRandomization=*/!opt.isRandomEnabled(
348 FirtoolOptions::RandomKind::Mem),
349 /*disableRegRandomization=*/
350 !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
351 /*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
352 /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
353 ? seq::ReadEnableMode::Ignore
354 : seq::ReadEnableMode::Undefined,
355 /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
356 /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
358
359 // If enabled, run the optimizer.
360 if (!opt.shouldDisableOptimization()) {
361 auto &modulePM = pm.nest<hw::HWModuleOp>();
362 modulePM.addPass(mlir::createCSEPass());
363 modulePM.addPass(createSimpleCanonicalizerPass());
364 modulePM.addPass(mlir::createCSEPass());
365 modulePM.addPass(sv::createHWCleanup(
366 {/*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()}));
367 }
368
369 // Check inner symbols and inner refs.
370 pm.addPass(hw::createVerifyInnerRefNamespace());
371
372 // Check OM object fields.
373 pm.addPass(om::createVerifyObjectFieldsPass());
374
375 return success();
376}
377
378namespace detail {
379LogicalResult
381 const firtool::FirtoolOptions &opt) {
382
383 // Run the verif op verification pass
384 pm.addNestedPass<hw::HWModuleOp>(verif::createVerifyClockedAssertLikePass());
385
386 // Legalize unsupported operations within the modules.
387 pm.nest<hw::HWModuleOp>().addPass(sv::createHWLegalizeModules());
388
389 // Tidy up the IR to improve verilog emission quality.
390 if (!opt.shouldDisableOptimization())
391 pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilog());
392
393 if (opt.shouldStripFirDebugInfo())
394 pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
395 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc))
396 return fileLoc.getFilename().getValue().ends_with(".fir");
397 return false;
398 }));
399
400 if (opt.shouldStripDebugInfo())
402 [](mlir::Location loc) { return true; }));
403
404 // Emit module and testbench hierarchy JSON files.
406 pm.addPass(sv::createHWExportModuleHierarchy());
407
408 // Check inner symbols and inner refs.
409 pm.addPass(hw::createVerifyInnerRefNamespace());
410
411 // Check OM object fields.
413
414 return success();
415}
416} // namespace detail
417
418LogicalResult
419firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
420 std::unique_ptr<llvm::raw_ostream> os) {
422 return failure();
423
424 pm.addPass(createExportVerilogPass(std::move(os)));
425 return success();
426}
427
428LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
429 const FirtoolOptions &opt,
430 llvm::raw_ostream &os) {
432 return failure();
433
434 pm.addPass(createExportVerilogPass(os));
435 return success();
436}
437
438LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
439 const FirtoolOptions &opt,
440 llvm::StringRef directory) {
442 return failure();
443
444 pm.addPass(createExportSplitVerilogPass(directory));
445 return success();
446}
447
448LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
449 const FirtoolOptions &opt) {
450 pm.addPass(firrtl::createFinalizeIR());
451 pm.addPass(om::createFreezePathsPass());
452
453 return success();
454}
455
456/// BTOR2 emission pipeline, triggered with `--btor2` flag.
457LogicalResult firtool::populateHWToBTOR2(mlir::PassManager &pm,
458 const FirtoolOptions &opt,
459 llvm::raw_ostream &os) {
460 auto &mpm = pm.nest<hw::HWModuleOp>();
461 // Lower all supported `ltl` ops
462 mpm.addPass(circt::createLowerLTLToCorePass());
463 // LTLToCore can generate shiftreg which should be lowered before emission
464 mpm.addPass(circt::seq::createLowerSeqShiftReg());
465 // ShiftReg Lowering generates compreg.ce, which we don't support, so lower
466 mpm.addPass(circt::seq::createLowerSeqCompRegCE());
467 // Do final formal specific lowerings, e.g. inline wires eagerly
468 mpm.addPass(circt::verif::createPrepareForFormalPass());
469 pm.addPass(circt::hw::createFlattenModules());
470 pm.addPass(circt::createConvertHWToBTOR2Pass(os));
471 return success();
472}
473
474//===----------------------------------------------------------------------===//
475// FIRTOOL CommandLine Options
476//===----------------------------------------------------------------------===//
477
478namespace {
479/// This struct contains command line options that can be used to initialize
480/// various bits of a Firtool pipeline. This uses a struct wrapper to avoid the
481/// need for global command line options.
482struct FirtoolCmdOptions {
483 llvm::cl::opt<std::string> outputFilename{
484 "o",
485 llvm::cl::desc("Output filename, or directory for split output"),
486 llvm::cl::value_desc("filename"),
487 llvm::cl::init("-"),
488 };
489
490 llvm::cl::opt<bool> disableAnnotationsUnknown{
491 "disable-annotation-unknown",
492 llvm::cl::desc("Ignore unknown annotations when parsing"),
493 llvm::cl::init(false)};
494
495 llvm::cl::opt<bool> disableAnnotationsClassless{
496 "disable-annotation-classless",
497 llvm::cl::desc("Ignore annotations without a class when parsing"),
498 llvm::cl::init(false)};
499
500 llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
501 "lower-annotations-no-ref-type-ports",
502 llvm::cl::desc(
503 "Create real ports instead of ref type ports when resolving "
504 "wiring problems inside the LowerAnnotations pass"),
505 llvm::cl::init(false), llvm::cl::Hidden};
506
507 llvm::cl::opt<bool> probesToSignals{
508 "probes-to-signals",
509 llvm::cl::desc("Convert probes to non-probe signals"),
510 llvm::cl::init(false), llvm::cl::Hidden};
511
513 preserveAggregate{
514 "preserve-aggregate",
515 llvm::cl::desc("Specify input file format:"),
516 llvm::cl::values(
518 "Preserve no aggregate"),
520 "Preserve only 1d vectors of ground type"),
522 "Preserve only vectors"),
524 "Preserve vectors and bundles")),
526 };
527
529 "preserve-values",
530 llvm::cl::desc("Specify the values which can be optimized away"),
531 llvm::cl::values(
532 clEnumValN(firrtl::PreserveValues::Strip, "strip",
533 "Strip all names. No name is preserved"),
534 clEnumValN(firrtl::PreserveValues::None, "none",
535 "Names could be preserved by best-effort unlike `strip`"),
536 clEnumValN(firrtl::PreserveValues::Named, "named",
537 "Preserve values with meaningful names"),
538 clEnumValN(firrtl::PreserveValues::All, "all",
539 "Preserve all values")),
540 llvm::cl::init(firrtl::PreserveValues::None)};
541
542 llvm::cl::opt<bool> enableDebugInfo{
543 "g", llvm::cl::desc("Enable the generation of debug information"),
544 llvm::cl::init(false)};
545
546 // Build mode options.
548 "O", llvm::cl::desc("Controls how much optimization should be performed"),
549 llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
550 "debug",
551 "Compile with only necessary optimizations"),
553 "release", "Compile with optimizations")),
555
556 llvm::cl::opt<bool> disableLayerSink{"disable-layer-sink",
557 llvm::cl::desc("Disable layer sink"),
558 cl::init(false)};
559
560 llvm::cl::opt<bool> disableOptimization{
561 "disable-opt",
562 llvm::cl::desc("Disable optimizations"),
563 };
564
565 llvm::cl::opt<bool> vbToBV{
566 "vb-to-bv",
567 llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
568 llvm::cl::init(false)};
569
570 llvm::cl::opt<bool> noDedup{
571 "no-dedup",
572 llvm::cl::desc("Disable deduplication of structurally identical modules"),
573 llvm::cl::init(false)};
574
575 llvm::cl::opt<bool> dedupClasses{
576 "dedup-classes",
577 llvm::cl::desc(
578 "Deduplicate FIRRTL classes, violating their nominal typing"),
579 llvm::cl::init(true)};
580
582 "grand-central-companion-mode",
583 llvm::cl::desc("Specifies the handling of Grand Central companions"),
584 ::llvm::cl::values(
585 clEnumValN(firrtl::CompanionMode::Bind, "bind",
586 "Lower companion instances to SystemVerilog binds"),
587 clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
588 "Instantiate companions in the design"),
589 clEnumValN(firrtl::CompanionMode::Drop, "drop",
590 "Remove companions from the design")),
591 llvm::cl::init(firrtl::CompanionMode::Bind),
592 llvm::cl::Hidden,
593 };
594
595 llvm::cl::opt<bool> noViews{
596 "no-views",
597 llvm::cl::desc(
598 "Disable lowering of FIRRTL view intrinsics (delete them instead)"),
599 llvm::cl::init(false),
600 };
601
602 llvm::cl::opt<bool> disableAggressiveMergeConnections{
603 "disable-aggressive-merge-connections",
604 llvm::cl::desc(
605 "Disable aggressive merge connections (i.e. merge all field-level "
606 "connections into bulk connections)"),
607 llvm::cl::init(false)};
608
609 llvm::cl::opt<bool> lowerMemories{
610 "lower-memories",
611 llvm::cl::desc("Lower memories to have memories with masks as an "
612 "array with one memory per ground type"),
613 llvm::cl::init(false)};
614
615 llvm::cl::opt<std::string> blackBoxRootPath{
616 "blackbox-path",
617 llvm::cl::desc(
618 "Optional path to use as the root of black box annotations"),
619 llvm::cl::value_desc("path"),
620 llvm::cl::init(""),
621 };
622
623 llvm::cl::opt<bool> replSeqMem{
624 "repl-seq-mem",
625 llvm::cl::desc("Replace the seq mem for macro replacement and emit "
626 "relevant metadata"),
627 llvm::cl::init(false)};
628
629 llvm::cl::opt<std::string> replSeqMemFile{
630 "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
631 llvm::cl::init("")};
632
633 llvm::cl::opt<bool> ignoreReadEnableMem{
634 "ignore-read-enable-mem",
635 llvm::cl::desc("Ignore the read enable signal, instead of "
636 "assigning X on read disable"),
637 llvm::cl::init(false)};
638
640 llvm::cl::desc(
641 "Disable random initialization code (may break semantics!)"),
642 llvm::cl::values(
643 clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
644 "disable-mem-randomization",
645 "Disable emission of memory randomization code"),
646 clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
647 "disable-reg-randomization",
648 "Disable emission of register randomization code"),
649 clEnumValN(firtool::FirtoolOptions::RandomKind::All,
650 "disable-all-randomization",
651 "Disable emission of all randomization code")),
652 llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
653
654 llvm::cl::opt<std::string> outputAnnotationFilename{
655 "output-annotation-file",
656 llvm::cl::desc("Optional output annotation file"),
657 llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
658
659 llvm::cl::opt<bool> enableAnnotationWarning{
660 "warn-on-unprocessed-annotations",
661 llvm::cl::desc(
662 "Warn about annotations that were not removed by lower-to-hw"),
663 llvm::cl::init(false)};
664
665 llvm::cl::opt<bool> addMuxPragmas{
666 "add-mux-pragmas",
667 llvm::cl::desc("Annotate mux pragmas for memory array access"),
668 llvm::cl::init(false)};
669
671 "verification-flavor",
672 llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
673 llvm::cl::values(
674 clEnumValN(firrtl::VerificationFlavor::None, "none",
675 "Use the flavor specified by the op"),
676 clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
677 "Use Use `if(cond) else $fatal(..)` format"),
678 clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
679 "Use immediate verif statements"),
680 clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
681 llvm::cl::init(firrtl::VerificationFlavor::None)};
682
683 llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
684 "emit-separate-always-blocks",
685 llvm::cl::desc(
686 "Prevent always blocks from being merged and emit constructs into "
687 "separate always blocks whenever possible"),
688 llvm::cl::init(false)};
689
690 llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
691 "add-vivado-ram-address-conflict-synthesis-bug-workaround",
692 llvm::cl::desc(
693 "Add a vivado specific SV attribute (* ram_style = "
694 "\"distributed\" *) to unpacked array registers as a workaronud "
695 "for a vivado synthesis bug that incorrectly modifies "
696 "address conflict behavivor of combinational memories"),
697 llvm::cl::init(false)};
698
699 //===----------------------------------------------------------------------===
700 // External Clock Gate Options
701 //===----------------------------------------------------------------------===
702
703 llvm::cl::opt<std::string> ckgModuleName{
704 "ckg-name", llvm::cl::desc("Clock gate module name"),
705 llvm::cl::init("EICG_wrapper")};
706
707 llvm::cl::opt<std::string> ckgInputName{
708 "ckg-input", llvm::cl::desc("Clock gate input port name"),
709 llvm::cl::init("in")};
710
711 llvm::cl::opt<std::string> ckgOutputName{
712 "ckg-output", llvm::cl::desc("Clock gate output port name"),
713 llvm::cl::init("out")};
714
715 llvm::cl::opt<std::string> ckgEnableName{
716 "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
717 llvm::cl::init("en")};
718
719 llvm::cl::opt<std::string> ckgTestEnableName{
720 "ckg-test-enable",
721 llvm::cl::desc("Clock gate test enable port name (optional)"),
722 llvm::cl::init("test_en")};
723
724 llvm::cl::opt<bool> exportModuleHierarchy{
725 "export-module-hierarchy",
726 llvm::cl::desc("Export module and instance hierarchy as JSON"),
727 llvm::cl::init(false)};
728
729 llvm::cl::opt<bool> stripFirDebugInfo{
730 "strip-fir-debug-info",
731 llvm::cl::desc(
732 "Disable source fir locator information in output Verilog"),
733 llvm::cl::init(true)};
734
735 llvm::cl::opt<bool> stripDebugInfo{
736 "strip-debug-info",
737 llvm::cl::desc("Disable source locator information in output Verilog"),
738 llvm::cl::init(false)};
739
740 llvm::cl::opt<bool> fixupEICGWrapper{
741 "fixup-eicg-wrapper",
742 llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
743 llvm::cl::init(false)};
744
745 llvm::cl::opt<bool> selectDefaultInstanceChoice{
746 "select-default-for-unspecified-instance-choice",
747 llvm::cl::desc(
748 "Specialize instance choice to default, if no option selected"),
749 llvm::cl::init(false)};
750
752 "symbolic-values",
753 llvm::cl::desc("Control how symbolic values are lowered"),
754 llvm::cl::init(verif::SymbolicValueLowering::ExtModule),
755 verif::symbolicValueLoweringCLValues()};
756
757 llvm::cl::opt<bool> disableWireElimination{
758 "disable-wire-elimination", llvm::cl::desc("Disable wire elimination"),
759 llvm::cl::init(false)};
760
761 llvm::cl::opt<bool> emitAllBindFiles{
762 "emit-all-bind-files",
763 llvm::cl::desc("Emit bindfiles for private modules"),
764 llvm::cl::init(false)};
765
766 llvm::cl::opt<bool> inlineInputOnlyModules{
767 "inline-input-only-modules", llvm::cl::desc("Inline input-only modules"),
768 llvm::cl::init(false)};
769
771 "domain-mode", llvm::cl::desc("Enable domain inference and checking"),
772 llvm::cl::init(firtool::FirtoolOptions::DomainMode::Strip),
773 llvm::cl::values(
774 clEnumValN(firtool::FirtoolOptions::DomainMode::Check, "check",
775 "Check domains without inference"),
776 clEnumValN(firtool::FirtoolOptions::DomainMode::Disable, "disable",
777 "Disable domain checking"),
778 clEnumValN(firtool::FirtoolOptions::DomainMode::Infer, "infer",
779 "Check domains with inference for private modules"),
780 clEnumValN(firtool::FirtoolOptions::DomainMode::InferAll, "infer-all",
781 "Check domains with inference for both public and private "
782 "modules"),
783 clEnumValN(firtool::FirtoolOptions::DomainMode::Strip, "strip",
784 "Erase all domain information"))};
785
786 //===----------------------------------------------------------------------===
787 // Lint options
788 //===----------------------------------------------------------------------===
789
790 llvm::cl::opt<bool> lintStaticAsserts{
791 "lint-static-asserts", llvm::cl::desc("Lint static assertions"),
792 llvm::cl::init(true)};
793 // TODO: Change this default to 'true' once this has been better tested and
794 // `-sv-extract-test-code` has been removed.
795 llvm::cl::opt<bool> lintXmrsInDesign{
796 "lint-xmrs-in-design", llvm::cl::desc("Lint XMRs in the design"),
797 llvm::cl::init(false)};
798};
799} // namespace
800
801static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
802
803/// Register a set of useful command-line options that can be used to configure
804/// various flags within the MLIRContext. These flags are used when constructing
805/// an MLIR context for initialization.
807 // Make sure that the options struct has been initialized.
808 *clOptions;
809}
810
811// Initialize the firtool options with defaults supplied by the cl::opts above.
813 : outputFilename("-"), disableAnnotationsUnknown(false),
814 disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
815 probesToSignals(false),
816 preserveAggregate(firrtl::PreserveAggregate::None),
817 preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
818 buildMode(BuildModeRelease), disableLayerSink(false),
819 disableOptimization(false), vbToBV(false), noDedup(false),
820 dedupClasses(true), companionMode(firrtl::CompanionMode::Bind),
821 noViews(false), disableAggressiveMergeConnections(false),
822 lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
823 replSeqMemFile(""), ignoreReadEnableMem(false),
824 disableRandom(RandomKind::None), outputAnnotationFilename(""),
825 enableAnnotationWarning(false), addMuxPragmas(false),
826 verificationFlavor(firrtl::VerificationFlavor::None),
827 emitSeparateAlwaysBlocks(false),
828 addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
829 ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
830 ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
831 exportModuleHierarchy(false), stripFirDebugInfo(true),
832 stripDebugInfo(false), fixupEICGWrapper(false),
833 disableCSEinClasses(false), selectDefaultInstanceChoice(false),
834 symbolicValueLowering(verif::SymbolicValueLowering::ExtModule),
835 disableWireElimination(false), lintStaticAsserts(true),
836 lintXmrsInDesign(true), emitAllBindFiles(false),
837 inlineInputOnlyModules(false), domainMode(DomainMode::Disable) {
838 if (!clOptions.isConstructed())
839 return;
840 outputFilename = clOptions->outputFilename;
841 disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
842 disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
843 lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
844 probesToSignals = clOptions->probesToSignals;
845 preserveAggregate = clOptions->preserveAggregate;
846 preserveMode = clOptions->preserveMode;
847 enableDebugInfo = clOptions->enableDebugInfo;
848 buildMode = clOptions->buildMode;
849 disableLayerSink = clOptions->disableLayerSink;
850 disableOptimization = clOptions->disableOptimization;
851 vbToBV = clOptions->vbToBV;
852 noDedup = clOptions->noDedup;
853 dedupClasses = clOptions->dedupClasses;
854 companionMode = clOptions->companionMode;
855 noViews = clOptions->noViews;
857 clOptions->disableAggressiveMergeConnections;
858 lowerMemories = clOptions->lowerMemories;
859 blackBoxRootPath = clOptions->blackBoxRootPath;
860 replSeqMem = clOptions->replSeqMem;
861 replSeqMemFile = clOptions->replSeqMemFile;
862 ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
863 disableRandom = clOptions->disableRandom;
864 outputAnnotationFilename = clOptions->outputAnnotationFilename;
865 enableAnnotationWarning = clOptions->enableAnnotationWarning;
866 addMuxPragmas = clOptions->addMuxPragmas;
867 verificationFlavor = clOptions->verificationFlavor;
868 emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
870 clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
871 ckgModuleName = clOptions->ckgModuleName;
872 ckgInputName = clOptions->ckgInputName;
873 ckgOutputName = clOptions->ckgOutputName;
874 ckgEnableName = clOptions->ckgEnableName;
875 ckgTestEnableName = clOptions->ckgTestEnableName;
876 exportModuleHierarchy = clOptions->exportModuleHierarchy;
877 stripFirDebugInfo = clOptions->stripFirDebugInfo;
878 stripDebugInfo = clOptions->stripDebugInfo;
879 fixupEICGWrapper = clOptions->fixupEICGWrapper;
880 selectDefaultInstanceChoice = clOptions->selectDefaultInstanceChoice;
881 symbolicValueLowering = clOptions->symbolicValueLowering;
882 disableWireElimination = clOptions->disableWireElimination;
883 lintStaticAsserts = clOptions->lintStaticAsserts;
884 lintXmrsInDesign = clOptions->lintXmrsInDesign;
885 emitAllBindFiles = clOptions->emitAllBindFiles;
886 inlineInputOnlyModules = clOptions->inlineInputOnlyModules;
887 domainMode = clOptions->domainMode;
888}
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition Firtool.cpp:801
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:237
LogicalResult populateHWToBTOR2(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::raw_ostream &os)
BTOR2 emission pipeline, triggered with --btor2 flag.
Definition Firtool.cpp:457
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition Firtool.cpp:438
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:329
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition Firtool.cpp:419
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:806
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition Firtool.cpp:448
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< 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:380
Definition verif.py:1