CIRCT  19.0.0git
Firtool.h
Go to the documentation of this file.
1 //===- Firtool.h - 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 //
9 // This library parses options for firtool and sets up its pipeline.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_FIRTOOL_FIRTOOL_H
14 #define CIRCT_FIRTOOL_FIRTOOL_H
15 
19 #include "circt/Support/LLVM.h"
20 #include "mlir/Pass/PassManager.h"
21 #include "llvm/Support/CommandLine.h"
22 
23 namespace circt {
24 namespace firtool {
25 //===----------------------------------------------------------------------===//
26 // FirtoolOptions
27 //===----------------------------------------------------------------------===//
28 
29 /// Set of options used to control the behavior of the firtool pipeline.
31 public:
33 
34  // Helper Types
36  enum class RandomKind { None, Mem, Reg, All };
37 
38  bool isRandomEnabled(RandomKind kind) const {
39  return disableRandom != RandomKind::All && disableRandom != kind;
40  }
41 
43  switch (buildMode) {
44  case BuildModeDebug:
46  case BuildModeRelease:
48  case BuildModeDefault:
49  return preserveMode;
50  }
51  llvm_unreachable("unknown build mode");
52  }
53 
54  StringRef getOutputFilename() const { return outputFilename; }
55  StringRef getOmirOutputFile() const { return omirOutFile; }
56  StringRef getBlackBoxRootPath() const { return blackBoxRootPath; }
59  }
60  StringRef getReplaceSequentialMemoriesFile() const { return replSeqMemFile; }
61  StringRef getOutputAnnotationFilename() const {
63  }
64 
66  return preserveAggregate;
67  }
69 
70  seq::ExternalizeClockGateOptions getClockGateOptions() const {
73  }
74 
75  FirtoolOptions &setClockGateOptions(seq::ExternalizeClockGateOptions &opts) {
76  ckgModuleName = opts.moduleName;
77  ckgInputName = opts.inputName;
78  ckgOutputName = opts.outputName;
79  ckgEnableName = opts.enableName;
80  ckgTestEnableName = opts.testEnableName;
81  ckgInstName = opts.instName;
82  return *this;
83  }
84 
85  bool isDefaultOutputFilename() const { return outputFilename == "-"; }
88  }
91  }
94  }
97  bool shouldLowerMemories() const { return lowerMemories; }
98  bool shouldDedup() const { return !noDedup; }
99  bool shouldEnableDebugInfo() const { return enableDebugInfo; }
101  bool shouldEmitOMIR() const { return emitOMIR; }
105  }
106  bool shouldConvertVecOfBundle() const { return vbToBV; }
109  }
112  }
115  }
116  bool shouldStripDebugInfo() const { return stripDebugInfo; }
121  }
123  auto getVerificationFlavor() const { return verificationFlavor; }
126  }
127  bool shouldAddMuxPragmas() const { return addMuxPragmas; }
130  }
131  bool shouldExtractTestCode() const { return extractTestCode; }
132  bool shouldFixupEICGWrapper() const { return fixupEICGWrapper; }
134 
135  // Setters, used by the CAPI
137  outputFilename = name;
138  return *this;
139  }
140 
142  disableAnnotationsUnknown = disable;
143  return *this;
144  }
145 
148  return *this;
149  }
150 
153  return *this;
154  }
155 
158  preserveAggregate = value;
159  return *this;
160  }
161 
164  preserveMode = value;
165  return *this;
166  }
167 
169  enableDebugInfo = value;
170  return *this;
171  }
172 
174  buildMode = value;
175  return *this;
176  }
177 
179  disableOptimization = value;
180  return *this;
181  }
182 
184  exportChiselInterface = value;
185  return *this;
186  }
187 
190  return *this;
191  }
192 
193  FirtoolOptions &setVbToBV(bool value) {
194  vbToBV = value;
195  return *this;
196  }
197 
198  FirtoolOptions &setNoDedup(bool value) {
199  noDedup = value;
200  return *this;
201  }
202 
204  companionMode = value;
205  return *this;
206  }
207 
210  return *this;
211  }
212 
215  return *this;
216  }
217 
219  emitOMIR = value;
220  return *this;
221  }
222 
223  FirtoolOptions &setOmirOutFile(StringRef value) {
224  omirOutFile = value;
225  return *this;
226  }
227 
229  lowerMemories = value;
230  return *this;
231  }
232 
234  blackBoxRootPath = value;
235  return *this;
236  }
237 
239  replSeqMem = value;
240  return *this;
241  }
242 
243  FirtoolOptions &setReplSeqMemFile(StringRef value) {
244  replSeqMemFile = value;
245  return *this;
246  }
247 
249  extractTestCode = value;
250  return *this;
251  }
252 
254  ignoreReadEnableMem = value;
255  return *this;
256  }
257 
259  disableRandom = value;
260  return *this;
261  }
262 
264  outputAnnotationFilename = value;
265  return *this;
266  }
267 
269  enableAnnotationWarning = value;
270  return *this;
271  }
272 
274  addMuxPragmas = value;
275  return *this;
276  }
277 
279  verificationFlavor = value;
280  return *this;
281  }
282 
284  emitSeparateAlwaysBlocks = value;
285  return *this;
286  }
287 
290  return *this;
291  }
292 
295  return *this;
296  }
297 
299  etcDisableModuleInlining = value;
300  return *this;
301  }
302 
306  return *this;
307  }
308 
309  FirtoolOptions &setCkgModuleName(StringRef value) {
310  ckgModuleName = value;
311  return *this;
312  }
313 
314  FirtoolOptions &setCkgInputName(StringRef value) {
315  ckgInputName = value;
316  return *this;
317  }
318 
319  FirtoolOptions &setCkgOutputName(StringRef value) {
320  ckgOutputName = value;
321  return *this;
322  }
323 
324  FirtoolOptions &setCkgEnableName(StringRef value) {
325  ckgEnableName = value;
326  return *this;
327  }
328 
330  ckgTestEnableName = value;
331  return *this;
332  }
333 
335  exportModuleHierarchy = value;
336  return *this;
337  }
338 
340  stripFirDebugInfo = value;
341  return *this;
342  }
343 
345  stripDebugInfo = value;
346  return *this;
347  }
348 
350  fixupEICGWrapper = value;
351  return *this;
352  }
353 
355  addCompanionAssume = value;
356  return *this;
357  }
358 
359 private:
360  std::string outputFilename;
371  bool vbToBV;
372  bool noDedup;
376  bool emitOMIR;
377  std::string omirOutFile;
379  std::string blackBoxRootPath;
381  std::string replSeqMemFile;
394  std::string ckgModuleName;
395  std::string ckgInputName;
396  std::string ckgOutputName;
397  std::string ckgEnableName;
398  std::string ckgTestEnableName;
399  std::string ckgInstName;
405 };
406 
408 
409 LogicalResult populatePreprocessTransforms(mlir::PassManager &pm,
410  const FirtoolOptions &opt);
411 
412 LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
413  const FirtoolOptions &opt,
414  StringRef inputFilename);
415 
416 LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm,
417  const FirtoolOptions &opt);
418 
419 LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt);
420 
421 LogicalResult populateExportVerilog(mlir::PassManager &pm,
422  const FirtoolOptions &opt,
423  std::unique_ptr<llvm::raw_ostream> os);
424 
425 LogicalResult populateExportVerilog(mlir::PassManager &pm,
426  const FirtoolOptions &opt,
427  llvm::raw_ostream &os);
428 
429 LogicalResult populateExportSplitVerilog(mlir::PassManager &pm,
430  const FirtoolOptions &opt,
431  llvm::StringRef directory);
432 
433 LogicalResult populateFinalizeIR(mlir::PassManager &pm,
434  const FirtoolOptions &opt);
435 
436 } // namespace firtool
437 } // namespace circt
438 
439 #endif // CIRCT_FIRTOOL_FIRTOOL_H
Set of options used to control the behavior of the firtool pipeline.
Definition: Firtool.h:30
FirtoolOptions & setCkgTestEnableName(StringRef value)
Definition: Firtool.h:329
FirtoolOptions & setOutputFilename(StringRef name)
Definition: Firtool.h:136
FirtoolOptions & setCkgModuleName(StringRef value)
Definition: Firtool.h:309
bool shouldStripDebugInfo() const
Definition: Firtool.h:116
FirtoolOptions & setChiselInterfaceOutDirectory(StringRef value)
Definition: Firtool.h:188
FirtoolOptions & setIgnoreReadEnableMem(bool value)
Definition: Firtool.h:253
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition: Firtool.h:65
FirtoolOptions & setLowerAnnotationsNoRefTypePorts(bool value)
Definition: Firtool.h:151
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition: Firtool.h:128
firrtl::PreserveValues::PreserveMode preserveMode
Definition: Firtool.h:365
FirtoolOptions & setExportChiselInterface(bool value)
Definition: Firtool.h:183
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
FirtoolOptions & setFixupEICGWrapper(bool value)
Definition: Firtool.h:349
StringRef getOutputFilename() const
Definition: Firtool.h:54
bool shouldDisableAggressiveMergeConnections() const
Definition: Firtool.h:119
FirtoolOptions & setDisableUnknownAnnotations(bool disable)
Definition: Firtool.h:141
StringRef getReplaceSequentialMemoriesFile() const
Definition: Firtool.h:60
FirtoolOptions & setPreserveAggregate(firrtl::PreserveAggregate::PreserveMode value)
Definition: Firtool.h:157
bool shouldDisableHoistingHWPassthrough() const
Definition: Firtool.h:103
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition: Firtool.h:393
FirtoolOptions & setCkgEnableName(StringRef value)
Definition: Firtool.h:324
FirtoolOptions & setReplSeqMemFile(StringRef value)
Definition: Firtool.h:243
bool shouldExportChiselInterface() const
Definition: Firtool.h:102
bool shouldExtractTestCode() const
Definition: Firtool.h:131
FirtoolOptions & setEtcDisableModuleInlining(bool value)
Definition: Firtool.h:298
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
FirtoolOptions & setCkgOutputName(StringRef value)
Definition: Firtool.h:319
FirtoolOptions & setExtractTestCode(bool value)
Definition: Firtool.h:248
firrtl::CompanionMode getCompanionMode() const
Definition: Firtool.h:68
FirtoolOptions & setOmirOutFile(StringRef value)
Definition: Firtool.h:223
bool shouldDisableClasslessAnnotations() const
Definition: Firtool.h:89
FirtoolOptions & setEtcDisableInstanceExtraction(bool value)
Definition: Firtool.h:288
FirtoolOptions & setStripDebugInfo(bool value)
Definition: Firtool.h:344
FirtoolOptions & setAddCompanionAssume(bool value)
Definition: Firtool.h:354
bool shouldIgnoreReadEnableMemories() const
Definition: Firtool.h:100
FirtoolOptions & setVbToBV(bool value)
Definition: Firtool.h:193
FirtoolOptions & setDisableAnnotationsClassless(bool value)
Definition: Firtool.h:146
FirtoolOptions & setLowerMemories(bool value)
Definition: Firtool.h:228
bool isRandomEnabled(RandomKind kind) const
Definition: Firtool.h:38
FirtoolOptions & setReplSeqMem(bool value)
Definition: Firtool.h:238
bool shouldDisableUnknownAnnotations() const
Definition: Firtool.h:86
FirtoolOptions & setDisableRandom(RandomKind value)
Definition: Firtool.h:258
bool shouldAddMuxPragmas() const
Definition: Firtool.h:127
bool shouldEnableAnnotationWarning() const
Definition: Firtool.h:122
bool shouldReplicateSequentialMemories() const
Definition: Firtool.h:95
FirtoolOptions & setVerificationFlavor(firrtl::VerificationFlavor value)
Definition: Firtool.h:278
bool shouldEtcDisableInstanceExtraction() const
Definition: Firtool.h:107
bool shouldConvertVecOfBundle() const
Definition: Firtool.h:106
FirtoolOptions & setEmitOMIR(bool value)
Definition: Firtool.h:218
StringRef getOutputAnnotationFilename() const
Definition: Firtool.h:61
FirtoolOptions & setCompanionMode(firrtl::CompanionMode value)
Definition: Firtool.h:203
bool shouldStripFirDebugInfo() const
Definition: Firtool.h:117
bool shouldEtcDisableRegisterExtraction() const
Definition: Firtool.h:110
FirtoolOptions & setBuildMode(BuildMode value)
Definition: Firtool.h:173
std::string outputAnnotationFilename
Definition: Firtool.h:385
firrtl::VerificationFlavor verificationFlavor
Definition: Firtool.h:388
FirtoolOptions & setNoDedup(bool value)
Definition: Firtool.h:198
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition: Firtool.h:364
bool shouldLowerMemories() const
Definition: Firtool.h:97
FirtoolOptions & setClockGateOptions(seq::ExternalizeClockGateOptions &opts)
Definition: Firtool.h:75
bool shouldEtcDisableModuleInlining() const
Definition: Firtool.h:113
FirtoolOptions & setAddVivadoRAMAddressConflictSynthesisBugWorkaround(bool value)
Definition: Firtool.h:304
FirtoolOptions & setDisableHoistingHWPassthrough(bool value)
Definition: Firtool.h:213
FirtoolOptions & setEnableDebugInfo(bool value)
Definition: Firtool.h:168
FirtoolOptions & setEmitSeparateAlwaysBlocks(bool value)
Definition: Firtool.h:283
bool shouldLowerNoRefTypePortAnnotations() const
Definition: Firtool.h:92
bool shouldExportModuleHierarchy() const
Definition: Firtool.h:118
FirtoolOptions & setPreserveValues(firrtl::PreserveValues::PreserveMode value)
Definition: Firtool.h:163
firrtl::CompanionMode companionMode
Definition: Firtool.h:373
FirtoolOptions & setCkgInputName(StringRef value)
Definition: Firtool.h:314
FirtoolOptions & setStripFirDebugInfo(bool value)
Definition: Firtool.h:339
FirtoolOptions & setOutputAnnotationFilename(StringRef value)
Definition: Firtool.h:263
FirtoolOptions & setEnableAnnotationWarning(bool value)
Definition: Firtool.h:268
FirtoolOptions & setBlackBoxRootPath(StringRef value)
Definition: Firtool.h:233
FirtoolOptions & setDisableAggressiveMergeConnections(bool value)
Definition: Firtool.h:208
FirtoolOptions & setAddMuxPragmas(bool value)
Definition: Firtool.h:273
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition: Firtool.h:70
bool shouldEnableDebugInfo() const
Definition: Firtool.h:99
bool shouldEmitSeparateAlwaysBlocks() const
Definition: Firtool.h:124
FirtoolOptions & setDisableOptimization(bool value)
Definition: Firtool.h:178
FirtoolOptions & setEtcDisableRegisterExtraction(bool value)
Definition: Firtool.h:293
StringRef getChiselInterfaceOutputDirectory() const
Definition: Firtool.h:57
FirtoolOptions & setExportModuleHierarchy(bool value)
Definition: Firtool.h:334
@ None
Don't explicitly preserve any named values.
Definition: Passes.h:159
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
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21