CIRCT  19.0.0git
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 
17 #include "circt/Support/Passes.h"
19 #include "mlir/Transforms/Passes.h"
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/Path.h"
22 
23 using namespace llvm;
24 using namespace circt;
25 
26 LogicalResult firtool::populatePreprocessTransforms(mlir::PassManager &pm,
27  const FirtoolOptions &opt) {
28  // Legalize away "open" aggregates to hw-only versions.
29  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerOpenAggsPass());
30 
31  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createResolvePathsPass());
32 
33  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotationsPass(
37 
38  if (opt.shouldEnableDebugInfo())
39  pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
41 
42  pm.nest<firrtl::CircuitOp>().addPass(
44  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
46 
47  return success();
48 }
49 
50 LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
51  const FirtoolOptions &opt,
52  StringRef inputFilename) {
53  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerSignaturesPass());
54 
55  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInjectDUTHierarchyPass());
56 
57  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
59 
60  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
62 
63  if (!opt.shouldDisableOptimization())
64  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
65  mlir::createCSEPass());
66 
67  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
69 
70  // Run LowerMatches before InferWidths, as the latter does not support the
71  // match statement, but it does support what they lower to.
72  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
74 
75  // Width inference creates canonicalization opportunities.
76  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidthsPass());
77 
78  pm.nest<firrtl::CircuitOp>().addPass(
81 
82  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResetsPass());
83 
84  if (opt.shouldExportChiselInterface()) {
85  StringRef outdir = opt.getChiselInterfaceOutputDirectory();
86  if (opt.isDefaultOutputFilename() && outdir.empty()) {
87  pm.nest<firrtl::CircuitOp>().addPass(createExportChiselInterfacePass());
88  } else {
89  if (outdir.empty())
90  outdir = opt.getOutputFilename();
91  pm.nest<firrtl::CircuitOp>().addPass(
93  }
94  }
95 
96  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDropConstPass());
97 
98  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createHoistPassthroughPass(
99  /*hoistHWDrivers=*/!opt.shouldDisableOptimization() &&
101  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createProbeDCEPass());
102 
103  if (opt.shouldDedup())
104  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDedupPass());
105 
106  if (opt.shouldConvertVecOfBundle()) {
107  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
109  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createVBToBVPass());
110  }
111 
112  if (!opt.shouldLowerMemories())
113  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
115 
116  // The input mlir file could be firrtl dialect so we might need to clean
117  // things up.
118  // pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerSignaturesPass());
119  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
120  opt.getPreserveAggregate(), firrtl::PreserveAggregate::None));
121 
122  pm.nest<firrtl::CircuitOp>().nestAny().addPass(
124 
125  auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
126  modulePM.addPass(firrtl::createSFCCompatPass());
127  modulePM.addPass(firrtl::createLayerMergePass());
128  modulePM.addPass(firrtl::createLayerSinkPass());
129 
130  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
131 
132  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInlinerPass());
133 
134  // Preset the random initialization parameters for each module. The current
135  // implementation assumes it can run at a time where every register is
136  // currently in the final module it will be emitted in, all registers have
137  // been created, and no registers have yet been removed.
138  if (opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg))
139  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
141 
142  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createCheckCombLoopsPass());
143 
144  // If we parsed a FIRRTL file and have optimizations enabled, clean it up.
145  if (!opt.shouldDisableOptimization())
146  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
148 
149  // Run the infer-rw pass, which merges read and write ports of a memory with
150  // mutually exclusive enables.
151  if (!opt.shouldDisableOptimization())
152  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
154 
156  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerMemoryPass());
157 
158  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createPrefixModulesPass());
159 
160  if (opt.shouldAddCompanionAssume())
161  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
163 
164  if (!opt.shouldDisableOptimization()) {
165  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
166 
167  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createHoistPassthroughPass(
168  /*hoistHWDrivers=*/!opt.shouldDisableOptimization() &&
170  // Cleanup after hoisting passthroughs, for separation-of-concerns.
171  pm.addPass(firrtl::createIMDeadCodeElimPass());
172  }
173 
174  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createAddSeqMemPortsPass());
175 
179 
180  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstancesPass());
181 
182  // Run passes to resolve Grand Central features. This should run before
183  // BlackBoxReader because Grand Central needs to inform BlackBoxReader where
184  // certain black boxes should be placed. Note: all Grand Central Taps related
185  // collateral is resolved entirely by LowerAnnotations.
186  pm.addNestedPass<firrtl::CircuitOp>(
188 
189  // Read black box source files into the IR.
190  StringRef blackBoxRoot = opt.getBlackBoxRootPath().empty()
191  ? llvm::sys::path::parent_path(inputFilename)
192  : opt.getBlackBoxRootPath();
193  pm.nest<firrtl::CircuitOp>().addPass(
194  firrtl::createBlackBoxReaderPass(blackBoxRoot));
195 
196  // Run SymbolDCE as late as possible, but before InnerSymbolDCE. This is for
197  // hierpathop's and just for general cleanup.
198  pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
199 
200  // Run InnerSymbolDCE as late as possible, but before IMDCE.
201  pm.addPass(firrtl::createInnerSymbolDCEPass());
202 
203  // The above passes, IMConstProp in particular, introduce additional
204  // canonicalization opportunities that we should pick up here before we
205  // proceed to output-specific pipelines.
206  if (!opt.shouldDisableOptimization()) {
207  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
209  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
211  // Re-run IMConstProp to propagate constants produced by register
212  // optimizations.
213  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
214  pm.addPass(firrtl::createIMDeadCodeElimPass());
215  }
216 
217  if (opt.shouldEmitOMIR())
218  pm.nest<firrtl::CircuitOp>().addPass(
220 
221  // Always run this, required for legalization.
222  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
225 
226  if (!opt.shouldDisableOptimization())
227  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
229 
230  return success();
231 }
232 
233 LogicalResult firtool::populateLowFIRRTLToHW(mlir::PassManager &pm,
234  const FirtoolOptions &opt) {
235  // Remove TraceAnnotations and write their updated paths to an output
236  // annotation file.
237  pm.nest<firrtl::CircuitOp>().addPass(
239 
240  // Lower the ref.resolve and ref.send ops and remove the RefType ports.
241  // LowerToHW cannot handle RefType so, this pass must be run to remove all
242  // RefType ports and ops.
243  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMRPass());
244 
245  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerClassesPass());
246 
247  // Check for static asserts.
248  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
250 
252  opt.getVerificationFlavor()));
253 
254  if (!opt.shouldDisableOptimization()) {
255  auto &modulePM = pm.nest<hw::HWModuleOp>();
256  modulePM.addPass(mlir::createCSEPass());
257  modulePM.addPass(createSimpleCanonicalizerPass());
258  }
259 
260  // Check inner symbols and inner refs.
262 
263  return success();
264 }
265 
266 LogicalResult firtool::populateHWToSV(mlir::PassManager &pm,
267  const FirtoolOptions &opt) {
268  if (opt.shouldExtractTestCode())
273 
275  pm.addPass(circt::createLowerSimToSVPass());
277  {/*disableRegRandomization=*/!opt.isRandomEnabled(
278  FirtoolOptions::RandomKind::Reg),
279  /*disableMemRandomization=*/
280  !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
281  /*emitSeparateAlwaysBlocks=*/
283  pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
284  pm.addPass(seq::createHWMemSimImplPass(
285  {/*disableMemRandomization=*/!opt.isRandomEnabled(
286  FirtoolOptions::RandomKind::Mem),
287  /*disableRegRandomization=*/
288  !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
289  /*replSeqMem=*/opt.shouldReplicateSequentialMemories(),
290  /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
291  ? seq::ReadEnableMode::Ignore
292  : seq::ReadEnableMode::Undefined,
293  /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
294  /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
296 
297  // If enabled, run the optimizer.
298  if (!opt.shouldDisableOptimization()) {
299  auto &modulePM = pm.nest<hw::HWModuleOp>();
300  modulePM.addPass(mlir::createCSEPass());
301  modulePM.addPass(createSimpleCanonicalizerPass());
302  modulePM.addPass(mlir::createCSEPass());
303  modulePM.addPass(sv::createHWCleanupPass(
304  /*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()));
305  }
306 
307  // Check inner symbols and inner refs.
309 
310  return success();
311 }
312 
313 namespace detail {
314 LogicalResult
315 populatePrepareForExportVerilog(mlir::PassManager &pm,
316  const firtool::FirtoolOptions &opt) {
317 
318  // Legalize unsupported operations within the modules.
319  pm.nest<hw::HWModuleOp>().addPass(sv::createHWLegalizeModulesPass());
320 
321  // Tidy up the IR to improve verilog emission quality.
322  if (!opt.shouldDisableOptimization())
323  pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilogPass());
324 
325  if (opt.shouldStripFirDebugInfo())
326  pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
327  if (auto fileLoc = loc.dyn_cast<FileLineColLoc>())
328  return fileLoc.getFilename().getValue().ends_with(".fir");
329  return false;
330  }));
331 
332  if (opt.shouldStripDebugInfo())
334  [](mlir::Location loc) { return true; }));
335 
336  // Emit module and testbench hierarchy JSON files.
337  if (opt.shouldExportModuleHierarchy())
339 
340  // Check inner symbols and inner refs.
342 
343  return success();
344 }
345 } // namespace detail
346 
347 LogicalResult
348 firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
349  std::unique_ptr<llvm::raw_ostream> os) {
350  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
351  return failure();
352 
353  pm.addPass(createExportVerilogPass(std::move(os)));
354  return success();
355 }
356 
357 LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
358  const FirtoolOptions &opt,
359  llvm::raw_ostream &os) {
360  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
361  return failure();
362 
363  pm.addPass(createExportVerilogPass(os));
364  return success();
365 }
366 
367 LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
368  const FirtoolOptions &opt,
369  llvm::StringRef directory) {
370  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
371  return failure();
372 
373  pm.addPass(createExportSplitVerilogPass(directory));
374  return success();
375 }
376 
377 LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
378  const FirtoolOptions &opt) {
379  pm.addPass(firrtl::createFinalizeIRPass());
380  pm.addPass(om::createFreezePathsPass());
381 
382  return success();
383 }
384 
385 //===----------------------------------------------------------------------===//
386 // FIRTOOL CommandLine Options
387 //===----------------------------------------------------------------------===//
388 
389 namespace {
390 /// This struct contains command line options that can be used to initialize
391 /// various bits of a Firtool pipeline. This uses a struct wrapper to avoid the
392 /// need for global command line options.
393 struct FirtoolCmdOptions {
394  llvm::cl::opt<std::string> outputFilename{
395  "o",
396  llvm::cl::desc("Output filename, or directory for split output"),
397  llvm::cl::value_desc("filename"),
398  llvm::cl::init("-"),
399  };
400 
401  llvm::cl::opt<bool> disableAnnotationsUnknown{
402  "disable-annotation-unknown",
403  llvm::cl::desc("Ignore unknown annotations when parsing"),
404  llvm::cl::init(false)};
405 
406  llvm::cl::opt<bool> disableAnnotationsClassless{
407  "disable-annotation-classless",
408  llvm::cl::desc("Ignore annotations without a class when parsing"),
409  llvm::cl::init(false)};
410 
411  llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
412  "lower-annotations-no-ref-type-ports",
413  llvm::cl::desc(
414  "Create real ports instead of ref type ports when resolving "
415  "wiring problems inside the LowerAnnotations pass"),
416  llvm::cl::init(false), llvm::cl::Hidden};
417 
419  preserveAggregate{
420  "preserve-aggregate",
421  llvm::cl::desc("Specify input file format:"),
422  llvm::cl::values(
423  clEnumValN(circt::firrtl::PreserveAggregate::None, "none",
424  "Preserve no aggregate"),
425  clEnumValN(circt::firrtl::PreserveAggregate::OneDimVec, "1d-vec",
426  "Preserve only 1d vectors of ground type"),
427  clEnumValN(circt::firrtl::PreserveAggregate::Vec, "vec",
428  "Preserve only vectors"),
429  clEnumValN(circt::firrtl::PreserveAggregate::All, "all",
430  "Preserve vectors and bundles")),
432  };
433 
435  "preserve-values",
436  llvm::cl::desc("Specify the values which can be optimized away"),
437  llvm::cl::values(
438  clEnumValN(firrtl::PreserveValues::Strip, "strip",
439  "Strip all names. No name is preserved"),
440  clEnumValN(firrtl::PreserveValues::None, "none",
441  "Names could be preserved by best-effort unlike `strip`"),
442  clEnumValN(firrtl::PreserveValues::Named, "named",
443  "Preserve values with meaningful names"),
444  clEnumValN(firrtl::PreserveValues::All, "all",
445  "Preserve all values")),
446  llvm::cl::init(firrtl::PreserveValues::None)};
447 
448  llvm::cl::opt<bool> enableDebugInfo{
449  "g", llvm::cl::desc("Enable the generation of debug information"),
450  llvm::cl::init(false)};
451 
452  // Build mode options.
454  "O", llvm::cl::desc("Controls how much optimization should be performed"),
455  llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
456  "debug",
457  "Compile with only necessary optimizations"),
458  clEnumValN(firtool::FirtoolOptions::BuildModeRelease,
459  "release", "Compile with optimizations")),
460  llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};
461 
462  llvm::cl::opt<bool> disableOptimization{
463  "disable-opt",
464  llvm::cl::desc("Disable optimizations"),
465  };
466 
468  "export-chisel-interface",
469  llvm::cl::desc("Generate a Scala Chisel interface to the top level "
470  "module of the firrtl circuit"),
471  llvm::cl::init(false)};
472 
473  llvm::cl::opt<std::string> chiselInterfaceOutDirectory{
474  "chisel-interface-out-dir",
475  llvm::cl::desc(
476  "The output directory for generated Chisel interface files"),
477  llvm::cl::init("")};
478 
479  llvm::cl::opt<bool> vbToBV{
480  "vb-to-bv",
481  llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
482  llvm::cl::init(false)};
483 
484  llvm::cl::opt<bool> noDedup{
485  "no-dedup",
486  llvm::cl::desc("Disable deduplication of structurally identical modules"),
487  llvm::cl::init(false)};
488 
490  "grand-central-companion-mode",
491  llvm::cl::desc("Specifies the handling of Grand Central companions"),
492  ::llvm::cl::values(
493  clEnumValN(firrtl::CompanionMode::Bind, "bind",
494  "Lower companion instances to SystemVerilog binds"),
495  clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
496  "Instantiate companions in the design"),
497  clEnumValN(firrtl::CompanionMode::Drop, "drop",
498  "Remove companions from the design")),
499  llvm::cl::init(firrtl::CompanionMode::Bind),
500  llvm::cl::Hidden,
501  };
502 
503  llvm::cl::opt<bool> disableAggressiveMergeConnections{
504  "disable-aggressive-merge-connections",
505  llvm::cl::desc(
506  "Disable aggressive merge connections (i.e. merge all field-level "
507  "connections into bulk connections)"),
508  llvm::cl::init(false)};
509 
510  llvm::cl::opt<bool> disableHoistingHWPassthrough{
511  "disable-hoisting-hw-passthrough",
512  llvm::cl::desc("Disable hoisting HW passthrough signals"),
513  llvm::cl::init(true), llvm::cl::Hidden};
514 
515  llvm::cl::opt<bool> emitOMIR{
516  "emit-omir", llvm::cl::desc("Emit OMIR annotations to a JSON file"),
517  llvm::cl::init(true)};
518 
519  llvm::cl::opt<std::string> omirOutFile{
520  "output-omir", llvm::cl::desc("File name for the output omir"),
521  llvm::cl::init("")};
522 
523  llvm::cl::opt<bool> lowerMemories{
524  "lower-memories",
525  llvm::cl::desc("Lower memories to have memories with masks as an "
526  "array with one memory per ground type"),
527  llvm::cl::init(false)};
528 
529  llvm::cl::opt<std::string> blackBoxRootPath{
530  "blackbox-path",
531  llvm::cl::desc(
532  "Optional path to use as the root of black box annotations"),
533  llvm::cl::value_desc("path"),
534  llvm::cl::init(""),
535  };
536 
537  llvm::cl::opt<bool> replSeqMem{
538  "repl-seq-mem",
539  llvm::cl::desc("Replace the seq mem for macro replacement and emit "
540  "relevant metadata"),
541  llvm::cl::init(false)};
542 
543  llvm::cl::opt<std::string> replSeqMemFile{
544  "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
545  llvm::cl::init("")};
546 
547  llvm::cl::opt<bool> extractTestCode{
548  "extract-test-code", llvm::cl::desc("Run the extract test code pass"),
549  llvm::cl::init(false)};
550 
551  llvm::cl::opt<bool> ignoreReadEnableMem{
552  "ignore-read-enable-mem",
553  llvm::cl::desc("Ignore the read enable signal, instead of "
554  "assigning X on read disable"),
555  llvm::cl::init(false)};
556 
558  llvm::cl::desc(
559  "Disable random initialization code (may break semantics!)"),
560  llvm::cl::values(
561  clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
562  "disable-mem-randomization",
563  "Disable emission of memory randomization code"),
564  clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
565  "disable-reg-randomization",
566  "Disable emission of register randomization code"),
568  "disable-all-randomization",
569  "Disable emission of all randomization code")),
570  llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
571 
572  llvm::cl::opt<std::string> outputAnnotationFilename{
573  "output-annotation-file",
574  llvm::cl::desc("Optional output annotation file"),
575  llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
576 
577  llvm::cl::opt<bool> enableAnnotationWarning{
578  "warn-on-unprocessed-annotations",
579  llvm::cl::desc(
580  "Warn about annotations that were not removed by lower-to-hw"),
581  llvm::cl::init(false)};
582 
583  llvm::cl::opt<bool> addMuxPragmas{
584  "add-mux-pragmas",
585  llvm::cl::desc("Annotate mux pragmas for memory array access"),
586  llvm::cl::init(false)};
587 
589  "verification-flavor",
590  llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
591  llvm::cl::values(
592  clEnumValN(firrtl::VerificationFlavor::None, "none",
593  "Use the flavor specified by the op"),
594  clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
595  "Use Use `if(cond) else $fatal(..)` format"),
596  clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
597  "Use immediate verif statements"),
598  clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
599  llvm::cl::init(firrtl::VerificationFlavor::None)};
600 
601  llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
602  "emit-separate-always-blocks",
603  llvm::cl::desc(
604  "Prevent always blocks from being merged and emit constructs into "
605  "separate always blocks whenever possible"),
606  llvm::cl::init(false)};
607 
608  llvm::cl::opt<bool> etcDisableInstanceExtraction{
609  "etc-disable-instance-extraction",
610  llvm::cl::desc("Disable extracting instances only that feed test code"),
611  llvm::cl::init(false)};
612 
613  llvm::cl::opt<bool> etcDisableRegisterExtraction{
614  "etc-disable-register-extraction",
615  llvm::cl::desc("Disable extracting registers that only feed test code"),
616  llvm::cl::init(false)};
617 
618  llvm::cl::opt<bool> etcDisableModuleInlining{
619  "etc-disable-module-inlining",
620  llvm::cl::desc("Disable inlining modules that only feed test code"),
621  llvm::cl::init(false)};
622 
623  llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
624  "add-vivado-ram-address-conflict-synthesis-bug-workaround",
625  llvm::cl::desc(
626  "Add a vivado specific SV attribute (* ram_style = "
627  "\"distributed\" *) to unpacked array registers as a workaronud "
628  "for a vivado synthesis bug that incorrectly modifies "
629  "address conflict behavivor of combinational memories"),
630  llvm::cl::init(false)};
631 
632  //===----------------------------------------------------------------------===
633  // External Clock Gate Options
634  //===----------------------------------------------------------------------===
635 
636  llvm::cl::opt<std::string> ckgModuleName{
637  "ckg-name", llvm::cl::desc("Clock gate module name"),
638  llvm::cl::init("EICG_wrapper")};
639 
640  llvm::cl::opt<std::string> ckgInputName{
641  "ckg-input", llvm::cl::desc("Clock gate input port name"),
642  llvm::cl::init("in")};
643 
644  llvm::cl::opt<std::string> ckgOutputName{
645  "ckg-output", llvm::cl::desc("Clock gate output port name"),
646  llvm::cl::init("out")};
647 
648  llvm::cl::opt<std::string> ckgEnableName{
649  "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
650  llvm::cl::init("en")};
651 
652  llvm::cl::opt<std::string> ckgTestEnableName{
653  "ckg-test-enable",
654  llvm::cl::desc("Clock gate test enable port name (optional)"),
655  llvm::cl::init("test_en")};
656 
657  llvm::cl::opt<bool> exportModuleHierarchy{
658  "export-module-hierarchy",
659  llvm::cl::desc("Export module and instance hierarchy as JSON"),
660  llvm::cl::init(false)};
661 
662  llvm::cl::opt<bool> stripFirDebugInfo{
663  "strip-fir-debug-info",
664  llvm::cl::desc(
665  "Disable source fir locator information in output Verilog"),
666  llvm::cl::init(true)};
667 
668  llvm::cl::opt<bool> stripDebugInfo{
669  "strip-debug-info",
670  llvm::cl::desc("Disable source locator information in output Verilog"),
671  llvm::cl::init(false)};
672 
673  llvm::cl::opt<bool> fixupEICGWrapper{
674  "fixup-eicg-wrapper",
675  llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
676  llvm::cl::init(false)};
677 
678  llvm::cl::opt<bool> addCompanionAssume{
679  "add-companion-assume",
680  llvm::cl::desc("Add companion assumes to assertions"),
681  llvm::cl::init(false)};
682 };
683 } // namespace
684 
685 static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
686 
687 /// Register a set of useful command-line options that can be used to configure
688 /// various flags within the MLIRContext. These flags are used when constructing
689 /// an MLIR context for initialization.
691  // Make sure that the options struct has been initialized.
692  *clOptions;
693 }
694 
695 // Initialize the firtool options with defaults supplied by the cl::opts above.
697  : outputFilename("-"), disableAnnotationsUnknown(false),
698  disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
699  preserveAggregate(firrtl::PreserveAggregate::None),
700  preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
701  buildMode(BuildModeRelease), disableOptimization(false),
702  exportChiselInterface(false), chiselInterfaceOutDirectory(""),
703  vbToBV(false), noDedup(false), companionMode(firrtl::CompanionMode::Bind),
704  disableAggressiveMergeConnections(false),
705  disableHoistingHWPassthrough(true), emitOMIR(true), omirOutFile(""),
706  lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
707  replSeqMemFile(""), extractTestCode(false), ignoreReadEnableMem(false),
708  disableRandom(RandomKind::None), outputAnnotationFilename(""),
709  enableAnnotationWarning(false), addMuxPragmas(false),
710  verificationFlavor(firrtl::VerificationFlavor::None),
711  emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
712  etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
713  addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
714  ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
715  ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
716  exportModuleHierarchy(false), stripFirDebugInfo(true),
717  stripDebugInfo(false), fixupEICGWrapper(false),
718  addCompanionAssume(false) {
719  if (!clOptions.isConstructed())
720  return;
721  outputFilename = clOptions->outputFilename;
722  disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
723  disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
724  lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
725  preserveAggregate = clOptions->preserveAggregate;
726  preserveMode = clOptions->preserveMode;
727  enableDebugInfo = clOptions->enableDebugInfo;
728  buildMode = clOptions->buildMode;
729  disableOptimization = clOptions->disableOptimization;
730  exportChiselInterface = clOptions->exportChiselInterface;
731  chiselInterfaceOutDirectory = clOptions->chiselInterfaceOutDirectory;
732  vbToBV = clOptions->vbToBV;
733  noDedup = clOptions->noDedup;
734  companionMode = clOptions->companionMode;
736  clOptions->disableAggressiveMergeConnections;
737  disableHoistingHWPassthrough = clOptions->disableHoistingHWPassthrough;
738  emitOMIR = clOptions->emitOMIR;
739  omirOutFile = clOptions->omirOutFile;
740  lowerMemories = clOptions->lowerMemories;
741  blackBoxRootPath = clOptions->blackBoxRootPath;
742  replSeqMem = clOptions->replSeqMem;
743  replSeqMemFile = clOptions->replSeqMemFile;
744  extractTestCode = clOptions->extractTestCode;
745  ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
746  disableRandom = clOptions->disableRandom;
747  outputAnnotationFilename = clOptions->outputAnnotationFilename;
748  enableAnnotationWarning = clOptions->enableAnnotationWarning;
749  addMuxPragmas = clOptions->addMuxPragmas;
750  verificationFlavor = clOptions->verificationFlavor;
751  emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
752  etcDisableInstanceExtraction = clOptions->etcDisableInstanceExtraction;
753  etcDisableRegisterExtraction = clOptions->etcDisableRegisterExtraction;
754  etcDisableModuleInlining = clOptions->etcDisableModuleInlining;
756  clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
757  ckgModuleName = clOptions->ckgModuleName;
758  ckgInputName = clOptions->ckgInputName;
759  ckgOutputName = clOptions->ckgOutputName;
760  ckgEnableName = clOptions->ckgEnableName;
761  ckgTestEnableName = clOptions->ckgTestEnableName;
762  exportModuleHierarchy = clOptions->exportModuleHierarchy;
763  stripFirDebugInfo = clOptions->stripFirDebugInfo;
764  stripDebugInfo = clOptions->stripDebugInfo;
765  fixupEICGWrapper = clOptions->fixupEICGWrapper;
766  addCompanionAssume = clOptions->addCompanionAssume;
767 }
static LogicalResult exportChiselInterface(CircuitOp circuit, llvm::raw_ostream &os)
Exports a Chisel interface to the output stream.
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition: Firtool.cpp:685
Set of options used to control the behavior of the firtool pipeline.
Definition: Firtool.h:30
bool shouldStripDebugInfo() const
Definition: Firtool.h:116
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition: Firtool.h:65
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition: Firtool.h:128
firrtl::PreserveValues::PreserveMode preserveMode
Definition: Firtool.h:365
bool shouldAddCompanionAssume() const
Definition: Firtool.h:133
auto getVerificationFlavor() const
Definition: Firtool.h:123
StringRef getOmirOutputFile() const
Definition: Firtool.h:55
bool isDefaultOutputFilename() const
Definition: Firtool.h:85
StringRef getOutputFilename() const
Definition: Firtool.h:54
bool shouldDisableAggressiveMergeConnections() const
Definition: Firtool.h:119
StringRef getReplaceSequentialMemoriesFile() const
Definition: Firtool.h:60
bool shouldDisableHoistingHWPassthrough() const
Definition: Firtool.h:103
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition: Firtool.h:393
bool shouldExportChiselInterface() const
Definition: Firtool.h:102
bool shouldExtractTestCode() const
Definition: Firtool.h:131
std::string chiselInterfaceOutDirectory
Definition: Firtool.h:370
bool shouldFixupEICGWrapper() const
Definition: Firtool.h:132
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition: Firtool.h:42
StringRef getBlackBoxRootPath() const
Definition: Firtool.h:56
bool shouldDisableOptimization() const
Definition: Firtool.h:96
firrtl::CompanionMode getCompanionMode() const
Definition: Firtool.h:68
bool shouldDisableClasslessAnnotations() const
Definition: Firtool.h:89
bool shouldIgnoreReadEnableMemories() const
Definition: Firtool.h:100
bool isRandomEnabled(RandomKind kind) const
Definition: Firtool.h:38
bool shouldDisableUnknownAnnotations() const
Definition: Firtool.h:86
bool shouldAddMuxPragmas() const
Definition: Firtool.h:127
bool shouldEnableAnnotationWarning() const
Definition: Firtool.h:122
bool shouldReplicateSequentialMemories() const
Definition: Firtool.h:95
bool shouldEtcDisableInstanceExtraction() const
Definition: Firtool.h:107
bool shouldConvertVecOfBundle() const
Definition: Firtool.h:106
StringRef getOutputAnnotationFilename() const
Definition: Firtool.h:61
bool shouldStripFirDebugInfo() const
Definition: Firtool.h:117
bool shouldEtcDisableRegisterExtraction() const
Definition: Firtool.h:110
std::string outputAnnotationFilename
Definition: Firtool.h:385
firrtl::VerificationFlavor verificationFlavor
Definition: Firtool.h:388
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition: Firtool.h:364
bool shouldLowerMemories() const
Definition: Firtool.h:97
bool shouldEtcDisableModuleInlining() const
Definition: Firtool.h:113
bool shouldLowerNoRefTypePortAnnotations() const
Definition: Firtool.h:92
bool shouldExportModuleHierarchy() const
Definition: Firtool.h:118
firrtl::CompanionMode companionMode
Definition: Firtool.h:373
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition: Firtool.h:70
bool shouldEnableDebugInfo() const
Definition: Firtool.h:99
bool shouldEmitSeparateAlwaysBlocks() const
Definition: Firtool.h:124
StringRef getChiselInterfaceOutputDirectory() const
Definition: Firtool.h:57
std::unique_ptr< mlir::Pass > createDedupPass()
Definition: Dedup.cpp:743
@ All
Preserve all aggregate values.
Definition: Passes.h:51
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
Definition: Passes.h:45
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
Definition: Passes.h:48
@ None
Don't preserve aggregate at all.
Definition: Passes.h:42
@ Strip
Strip all names. No name on declaration is preserved.
Definition: Passes.h:155
std::unique_ptr< mlir::Pass > createInferReadWritePass()
std::unique_ptr< mlir::Pass > createCheckCombLoopsPass()
std::unique_ptr< mlir::Pass > createFinalizeIRPass()
Definition: FinalizeIR.cpp:38
std::unique_ptr< mlir::Pass > createLowerFIRRTLTypesPass(PreserveAggregate::PreserveMode mode=PreserveAggregate::None, PreserveAggregate::PreserveMode memoryMode=PreserveAggregate::None)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createResolveTracesPass(mlir::StringRef outputAnnotationFilename="")
std::unique_ptr< mlir::Pass > createEmitOMIRPass(mlir::StringRef outputFilename="")
std::unique_ptr< mlir::Pass > createResolvePathsPass()
std::unique_ptr< mlir::Pass > createLowerSignaturesPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createVBToBVPass()
Definition: VBToBV.cpp:988
std::unique_ptr< mlir::Pass > createGrandCentralPass(CompanionMode companionMode=CompanionMode::Bind)
std::unique_ptr< mlir::Pass > createLowerIntmodulesPass(bool fixupEICGWrapper=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createIMConstPropPass()
std::unique_ptr< mlir::Pass > createBlackBoxReaderPass(std::optional< mlir::StringRef > inputPrefix={})
std::unique_ptr< mlir::Pass > createCreateCompanionAssume()
std::unique_ptr< mlir::Pass > createCreateSiFiveMetadataPass(bool replSeqMem=false, mlir::StringRef replSeqMemFile="")
std::unique_ptr< mlir::Pass > createLayerMergePass()
Definition: LayerMerge.cpp:73
std::unique_ptr< mlir::Pass > createInlinerPass()
std::unique_ptr< mlir::Pass > createVectorizationPass()
std::unique_ptr< mlir::Pass > createLowerMemoryPass()
std::unique_ptr< mlir::Pass > createDropNamesPass(PreserveValues::PreserveMode mode=PreserveValues::None)
Definition: DropName.cpp:92
std::unique_ptr< mlir::Pass > createLowerLayersPass()
std::unique_ptr< mlir::Pass > createIMDeadCodeElimPass()
std::unique_ptr< mlir::Pass > createLintingPass()
Definition: Lint.cpp:69
std::unique_ptr< mlir::Pass > createPassiveWiresPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createExtractInstancesPass()
std::unique_ptr< mlir::Pass > createLayerSinkPass()
Definition: LayerSink.cpp:52
std::unique_ptr< mlir::Pass > createHoistPassthroughPass(bool hoistHWDrivers=true)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createProbeDCEPass()
This is the pass constructor.
Definition: ProbeDCE.cpp:78
std::unique_ptr< mlir::Pass > createLowerCHIRRTLPass()
std::unique_ptr< mlir::Pass > createInnerSymbolDCEPass()
std::unique_ptr< mlir::Pass > createExpandWhensPass()
std::unique_ptr< mlir::Pass > createLowerXMRPass()
Definition: LowerXMR.cpp:851
std::unique_ptr< mlir::Pass > createLowerIntrinsicsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createInferWidthsPass()
std::unique_ptr< mlir::Pass > createMemToRegOfVecPass(bool replSeqMem=false, bool ignoreReadEnable=false)
std::unique_ptr< mlir::Pass > createLowerOpenAggsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createDropConstPass()
Definition: DropConst.cpp:96
std::unique_ptr< mlir::Pass > createSFCCompatPass()
Definition: SFCCompat.cpp:155
std::unique_ptr< mlir::Pass > createPrefixModulesPass()
std::unique_ptr< mlir::Pass > createInjectDUTHierarchyPass()
std::unique_ptr< mlir::Pass > createRandomizeRegisterInitPass()
std::unique_ptr< mlir::Pass > createLowerClassesPass()
std::unique_ptr< mlir::Pass > createAddSeqMemPortsPass()
std::unique_ptr< mlir::Pass > createLowerFIRRTLAnnotationsPass(bool ignoreUnhandledAnnotations=false, bool ignoreClasslessAnnotations=false, bool noRefTypePorts=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createRegisterOptimizerPass()
std::unique_ptr< mlir::Pass > createLowerMatchesPass()
std::unique_ptr< mlir::Pass > createMergeConnectionsPass(bool enableAggressiveMerging=false)
std::unique_ptr< mlir::Pass > createInferResetsPass()
std::unique_ptr< mlir::Pass > createFlattenMemoryPass()
std::unique_ptr< mlir::Pass > createMaterializeDebugInfoPass()
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition: Firtool.cpp:367
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:266
LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:233
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition: Firtool.cpp:348
LogicalResult populatePreprocessTransforms(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:26
void registerFirtoolCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
Definition: Firtool.cpp:690
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:377
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition: Firtool.cpp:50
std::unique_ptr< mlir::Pass > createVerifyInnerRefNamespacePass()
std::unique_ptr< mlir::Pass > createFreezePathsPass()
std::unique_ptr< mlir::Pass > createHWMemSimImplPass(const HWMemSimImplOptions &options={})
std::unique_ptr< mlir::Pass > createExternalizeClockGatePass(const ExternalizeClockGateOptions &options={})
std::unique_ptr< mlir::Pass > createHWExportModuleHierarchyPass()
std::unique_ptr< mlir::Pass > createSVExtractTestCodePass(bool disableInstanceExtraction=false, bool disableRegisterExtraction=false, bool disableModuleInlining=false)
std::unique_ptr< mlir::Pass > createHWLegalizeModulesPass()
std::unique_ptr< mlir::Pass > createPrettifyVerilogPass()
std::unique_ptr< mlir::Pass > createHWCleanupPass(bool mergeAlwaysBlocks=true)
Definition: HWCleanup.cpp:245
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
std::unique_ptr< mlir::Pass > createExportSplitChiselInterfacePass(mlir::StringRef outputDirectory="./")
std::unique_ptr< mlir::Pass > createExportVerilogPass(std::unique_ptr< llvm::raw_ostream > os)
std::unique_ptr< mlir::Pass > createExportChiselInterfacePass(llvm::raw_ostream &os)
std::unique_ptr< mlir::Pass > createExportSplitVerilogPass(llvm::StringRef directory="./")
std::unique_ptr< OperationPass< hw::HWModuleOp > > createLowerVerifToSVPass()
Create the Verif to SV conversion pass.
Definition: VerifToSV.cpp:153
std::unique_ptr< mlir::Pass > createLowerSeqToSVPass(const LowerSeqToSVOptions &options={})
Definition: SeqToSV.cpp:646
std::unique_ptr< mlir::Pass > createLowerFIRRTLToHWPass(bool enableAnnotationWarning=false, firrtl::VerificationFlavor assertionFlavor=firrtl::VerificationFlavor::None)
This is the pass constructor.
Definition: LowerToHW.cpp:581
std::unique_ptr< mlir::Pass > createLowerSimToSVPass()
Definition: SimToSV.cpp:206
std::unique_ptr< Pass > createSimpleCanonicalizerPass()
Create a simple canonicalizer pass.
Definition: Passes.cpp:15
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:315