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