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  }
100  bool shouldLowerMemories() const { return lowerMemories; }
101  bool shouldDedup() const { return !noDedup; }
102  bool shouldEnableDebugInfo() const { return enableDebugInfo; }
104  bool shouldEmitOMIR() const { return emitOMIR; }
108  }
109  bool shouldConvertVecOfBundle() const { return vbToBV; }
112  }
115  }
118  }
119  bool shouldStripDebugInfo() const { return stripDebugInfo; }
124  }
126  auto getVerificationFlavor() const { return verificationFlavor; }
129  }
130  bool shouldAddMuxPragmas() const { return addMuxPragmas; }
133  }
134  bool shouldExtractTestCode() const { return extractTestCode; }
135  bool shouldFixupEICGWrapper() const { return fixupEICGWrapper; }
137 
138  // Setters, used by the CAPI
140  outputFilename = name;
141  return *this;
142  }
143 
145  disableAnnotationsUnknown = disable;
146  return *this;
147  }
148 
151  return *this;
152  }
153 
156  return *this;
157  }
158 
160  allowAddingPortsOnPublic = value;
161  return *this;
162  }
163 
166  preserveAggregate = value;
167  return *this;
168  }
169 
172  preserveMode = value;
173  return *this;
174  }
175 
177  enableDebugInfo = value;
178  return *this;
179  }
180 
182  buildMode = value;
183  return *this;
184  }
185 
187  disableOptimization = value;
188  return *this;
189  }
190 
192  exportChiselInterface = value;
193  return *this;
194  }
195 
198  return *this;
199  }
200 
201  FirtoolOptions &setVbToBV(bool value) {
202  vbToBV = value;
203  return *this;
204  }
205 
206  FirtoolOptions &setNoDedup(bool value) {
207  noDedup = value;
208  return *this;
209  }
210 
212  companionMode = value;
213  return *this;
214  }
215 
218  return *this;
219  }
220 
223  return *this;
224  }
225 
227  emitOMIR = value;
228  return *this;
229  }
230 
231  FirtoolOptions &setOmirOutFile(StringRef value) {
232  omirOutFile = value;
233  return *this;
234  }
235 
237  lowerMemories = value;
238  return *this;
239  }
240 
242  blackBoxRootPath = value;
243  return *this;
244  }
245 
247  replSeqMem = value;
248  return *this;
249  }
250 
251  FirtoolOptions &setReplSeqMemFile(StringRef value) {
252  replSeqMemFile = value;
253  return *this;
254  }
255 
257  extractTestCode = value;
258  return *this;
259  }
260 
262  ignoreReadEnableMem = value;
263  return *this;
264  }
265 
267  disableRandom = value;
268  return *this;
269  }
270 
272  outputAnnotationFilename = value;
273  return *this;
274  }
275 
277  enableAnnotationWarning = value;
278  return *this;
279  }
280 
282  addMuxPragmas = value;
283  return *this;
284  }
285 
287  verificationFlavor = value;
288  return *this;
289  }
290 
292  emitSeparateAlwaysBlocks = value;
293  return *this;
294  }
295 
298  return *this;
299  }
300 
303  return *this;
304  }
305 
307  etcDisableModuleInlining = value;
308  return *this;
309  }
310 
314  return *this;
315  }
316 
317  FirtoolOptions &setCkgModuleName(StringRef value) {
318  ckgModuleName = value;
319  return *this;
320  }
321 
322  FirtoolOptions &setCkgInputName(StringRef value) {
323  ckgInputName = value;
324  return *this;
325  }
326 
327  FirtoolOptions &setCkgOutputName(StringRef value) {
328  ckgOutputName = value;
329  return *this;
330  }
331 
332  FirtoolOptions &setCkgEnableName(StringRef value) {
333  ckgEnableName = value;
334  return *this;
335  }
336 
338  ckgTestEnableName = value;
339  return *this;
340  }
341 
343  exportModuleHierarchy = value;
344  return *this;
345  }
346 
348  stripFirDebugInfo = value;
349  return *this;
350  }
351 
353  stripDebugInfo = value;
354  return *this;
355  }
356 
358  fixupEICGWrapper = value;
359  return *this;
360  }
361 
363  addCompanionAssume = value;
364  return *this;
365  }
366 
367 private:
368  std::string outputFilename;
380  bool vbToBV;
381  bool noDedup;
385  bool emitOMIR;
386  std::string omirOutFile;
388  std::string blackBoxRootPath;
390  std::string replSeqMemFile;
403  std::string ckgModuleName;
404  std::string ckgInputName;
405  std::string ckgOutputName;
406  std::string ckgEnableName;
407  std::string ckgTestEnableName;
408  std::string ckgInstName;
414 };
415 
417 
418 LogicalResult populatePreprocessTransforms(mlir::PassManager &pm,
419  const FirtoolOptions &opt);
420 
421 LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
422  const FirtoolOptions &opt,
423  StringRef inputFilename);
424 
425 LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm,
426  const FirtoolOptions &opt);
427 
428 LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt);
429 
430 LogicalResult populateExportVerilog(mlir::PassManager &pm,
431  const FirtoolOptions &opt,
432  std::unique_ptr<llvm::raw_ostream> os);
433 
434 LogicalResult populateExportVerilog(mlir::PassManager &pm,
435  const FirtoolOptions &opt,
436  llvm::raw_ostream &os);
437 
438 LogicalResult populateExportSplitVerilog(mlir::PassManager &pm,
439  const FirtoolOptions &opt,
440  llvm::StringRef directory);
441 
442 LogicalResult populateFinalizeIR(mlir::PassManager &pm,
443  const FirtoolOptions &opt);
444 
445 LogicalResult populateHWToBTOR2(mlir::PassManager &pm,
446  const FirtoolOptions &opt,
447  llvm::raw_ostream &os);
448 
449 } // namespace firtool
450 } // namespace circt
451 
452 #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:337
FirtoolOptions & setOutputFilename(StringRef name)
Definition: Firtool.h:139
FirtoolOptions & setCkgModuleName(StringRef value)
Definition: Firtool.h:317
bool shouldStripDebugInfo() const
Definition: Firtool.h:119
FirtoolOptions & setChiselInterfaceOutDirectory(StringRef value)
Definition: Firtool.h:196
FirtoolOptions & setIgnoreReadEnableMem(bool value)
Definition: Firtool.h:261
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition: Firtool.h:65
FirtoolOptions & setLowerAnnotationsNoRefTypePorts(bool value)
Definition: Firtool.h:154
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition: Firtool.h:131
firrtl::PreserveValues::PreserveMode preserveMode
Definition: Firtool.h:374
FirtoolOptions & setExportChiselInterface(bool value)
Definition: Firtool.h:191
bool shouldAddCompanionAssume() const
Definition: Firtool.h:136
auto getVerificationFlavor() const
Definition: Firtool.h:126
StringRef getOmirOutputFile() const
Definition: Firtool.h:55
bool isDefaultOutputFilename() const
Definition: Firtool.h:85
FirtoolOptions & setFixupEICGWrapper(bool value)
Definition: Firtool.h:357
StringRef getOutputFilename() const
Definition: Firtool.h:54
bool shouldDisableAggressiveMergeConnections() const
Definition: Firtool.h:122
FirtoolOptions & setDisableUnknownAnnotations(bool disable)
Definition: Firtool.h:144
StringRef getReplaceSequentialMemoriesFile() const
Definition: Firtool.h:60
FirtoolOptions & setPreserveAggregate(firrtl::PreserveAggregate::PreserveMode value)
Definition: Firtool.h:165
bool shouldDisableHoistingHWPassthrough() const
Definition: Firtool.h:106
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition: Firtool.h:402
FirtoolOptions & setCkgEnableName(StringRef value)
Definition: Firtool.h:332
FirtoolOptions & setReplSeqMemFile(StringRef value)
Definition: Firtool.h:251
bool shouldExportChiselInterface() const
Definition: Firtool.h:105
bool shouldExtractTestCode() const
Definition: Firtool.h:134
FirtoolOptions & setEtcDisableModuleInlining(bool value)
Definition: Firtool.h:306
std::string chiselInterfaceOutDirectory
Definition: Firtool.h:379
bool shouldFixupEICGWrapper() const
Definition: Firtool.h:135
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition: Firtool.h:42
StringRef getBlackBoxRootPath() const
Definition: Firtool.h:56
bool shouldDisableOptimization() const
Definition: Firtool.h:99
FirtoolOptions & setCkgOutputName(StringRef value)
Definition: Firtool.h:327
FirtoolOptions & setExtractTestCode(bool value)
Definition: Firtool.h:256
firrtl::CompanionMode getCompanionMode() const
Definition: Firtool.h:68
FirtoolOptions & setOmirOutFile(StringRef value)
Definition: Firtool.h:231
bool shouldDisableClasslessAnnotations() const
Definition: Firtool.h:89
FirtoolOptions & setEtcDisableInstanceExtraction(bool value)
Definition: Firtool.h:296
FirtoolOptions & setStripDebugInfo(bool value)
Definition: Firtool.h:352
FirtoolOptions & setAddCompanionAssume(bool value)
Definition: Firtool.h:362
bool shouldIgnoreReadEnableMemories() const
Definition: Firtool.h:103
FirtoolOptions & setVbToBV(bool value)
Definition: Firtool.h:201
FirtoolOptions & setDisableAnnotationsClassless(bool value)
Definition: Firtool.h:149
FirtoolOptions & setLowerMemories(bool value)
Definition: Firtool.h:236
bool isRandomEnabled(RandomKind kind) const
Definition: Firtool.h:38
FirtoolOptions & setReplSeqMem(bool value)
Definition: Firtool.h:246
bool shouldDisableUnknownAnnotations() const
Definition: Firtool.h:86
FirtoolOptions & setDisableRandom(RandomKind value)
Definition: Firtool.h:266
bool shouldAddMuxPragmas() const
Definition: Firtool.h:130
bool shouldEnableAnnotationWarning() const
Definition: Firtool.h:125
bool shouldReplicateSequentialMemories() const
Definition: Firtool.h:98
FirtoolOptions & setVerificationFlavor(firrtl::VerificationFlavor value)
Definition: Firtool.h:286
bool shouldEtcDisableInstanceExtraction() const
Definition: Firtool.h:110
bool shouldConvertVecOfBundle() const
Definition: Firtool.h:109
FirtoolOptions & setEmitOMIR(bool value)
Definition: Firtool.h:226
StringRef getOutputAnnotationFilename() const
Definition: Firtool.h:61
FirtoolOptions & setCompanionMode(firrtl::CompanionMode value)
Definition: Firtool.h:211
bool shouldStripFirDebugInfo() const
Definition: Firtool.h:120
bool shouldEtcDisableRegisterExtraction() const
Definition: Firtool.h:113
FirtoolOptions & setBuildMode(BuildMode value)
Definition: Firtool.h:181
std::string outputAnnotationFilename
Definition: Firtool.h:394
firrtl::VerificationFlavor verificationFlavor
Definition: Firtool.h:397
FirtoolOptions & setNoDedup(bool value)
Definition: Firtool.h:206
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition: Firtool.h:373
bool shouldLowerMemories() const
Definition: Firtool.h:100
FirtoolOptions & setClockGateOptions(seq::ExternalizeClockGateOptions &opts)
Definition: Firtool.h:75
bool shouldEtcDisableModuleInlining() const
Definition: Firtool.h:116
FirtoolOptions & setAddVivadoRAMAddressConflictSynthesisBugWorkaround(bool value)
Definition: Firtool.h:312
bool shouldAllowAddingPortsOnPublic() const
Definition: Firtool.h:95
FirtoolOptions & setDisableHoistingHWPassthrough(bool value)
Definition: Firtool.h:221
FirtoolOptions & setEnableDebugInfo(bool value)
Definition: Firtool.h:176
FirtoolOptions & setEmitSeparateAlwaysBlocks(bool value)
Definition: Firtool.h:291
bool shouldLowerNoRefTypePortAnnotations() const
Definition: Firtool.h:92
bool shouldExportModuleHierarchy() const
Definition: Firtool.h:121
FirtoolOptions & setPreserveValues(firrtl::PreserveValues::PreserveMode value)
Definition: Firtool.h:171
firrtl::CompanionMode companionMode
Definition: Firtool.h:382
FirtoolOptions & setCkgInputName(StringRef value)
Definition: Firtool.h:322
FirtoolOptions & setStripFirDebugInfo(bool value)
Definition: Firtool.h:347
FirtoolOptions & setOutputAnnotationFilename(StringRef value)
Definition: Firtool.h:271
FirtoolOptions & setEnableAnnotationWarning(bool value)
Definition: Firtool.h:276
FirtoolOptions & setBlackBoxRootPath(StringRef value)
Definition: Firtool.h:241
FirtoolOptions & setDisableAggressiveMergeConnections(bool value)
Definition: Firtool.h:216
FirtoolOptions & setAllowAddingPortsOnPublic(bool value)
Definition: Firtool.h:159
FirtoolOptions & setAddMuxPragmas(bool value)
Definition: Firtool.h:281
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition: Firtool.h:70
bool shouldEnableDebugInfo() const
Definition: Firtool.h:102
bool shouldEmitSeparateAlwaysBlocks() const
Definition: Firtool.h:127
FirtoolOptions & setDisableOptimization(bool value)
Definition: Firtool.h:186
FirtoolOptions & setEtcDisableRegisterExtraction(bool value)
Definition: Firtool.h:301
StringRef getChiselInterfaceOutputDirectory() const
Definition: Firtool.h:57
FirtoolOptions & setExportModuleHierarchy(bool value)
Definition: Firtool.h:342
@ None
Don't explicitly preserve any named values.
Definition: Passes.h:158
LogicalResult populateHWToBTOR2(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::raw_ostream &os)
Definition: Firtool.cpp:395
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition: Firtool.cpp:377
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:270
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:358
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:714
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:387
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition: Firtool.cpp:51
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21