CIRCT 24.0.0git
Loading...
Searching...
No Matches
LoweringOptions.h
Go to the documentation of this file.
1//===- LoweringOptions.h - CIRCT Lowering Options ---------------*- 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// Options for controlling the lowering process and verilog exporting.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_SUPPORT_LOWERINGOPTIONS_H
14#define CIRCT_SUPPORT_LOWERINGOPTIONS_H
15
16#include "mlir/IR/BuiltinAttributes.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/Twine.h"
19
20namespace mlir {
21class ModuleOp;
22}
23
24namespace circt {
25
26/// Options which control the emission from CIRCT to Verilog.
28 /// Error callback type used to indicate errors parsing the options string.
29 using ErrorHandlerT = llvm::function_ref<void(llvm::Twine)>;
30
31 /// Create a LoweringOptions with the default values.
32 LoweringOptions() = default;
33
34 /// Create a LoweringOptions and read in options from a string,
35 /// overriding only the set options in the string.
36 LoweringOptions(llvm::StringRef options, ErrorHandlerT errorHandler);
37
38 /// Create a LoweringOptions with values loaded from an MLIR ModuleOp. This
39 /// loads a string attribute with the key `circt.loweringOptions`. If there is
40 /// an error parsing the attribute this will print an error using the
41 /// ModuleOp.
42 LoweringOptions(mlir::ModuleOp module);
43
44 /// Return the value of the `circt.loweringOptions` in the specified module
45 /// if present, or a null attribute if not.
46 static mlir::StringAttr getAttributeFrom(mlir::ModuleOp module);
47
48 /// Read in options from a string, overriding only the set options in the
49 /// string.
50 void parse(llvm::StringRef options, ErrorHandlerT callback);
51
52 /// Returns a string representation of the options.
53 std::string toString() const;
54
55 /// Write the verilog emitter options to a module's attributes.
56 void setAsAttribute(mlir::ModuleOp module);
57
58 /// Load any emitter options from the module. If there is an error validating
59 /// the attribute, this will print an error using the ModuleOp.
60 void parseFromAttribute(mlir::ModuleOp module);
61
62 /// If true, emits `sv.alwayscomb` as Verilog `always @(*)` statements.
63 /// Otherwise, print them as `always_comb`.
64 bool noAlwaysComb = false;
65
66 /// If true, expressions are allowed in the sensitivity list of `always`
67 /// statements, otherwise they are forced to be simple wires. Some EDA
68 /// tools rely on these being simple wires.
70
71 /// If true, eliminate packed arrays for tools that don't support them (e.g.
72 /// Yosys).
74
75 /// If true, eliminate packed struct assignments in favor of a wire +
76 /// assignments to the individual fields.
78
79 /// If true, do not emit SystemVerilog locally scoped "automatic" or logic
80 /// declarations - emit top level wire and reg's instead.
82
83 /// If true, verification statements like `assert`, `assume`, and `cover` will
84 /// always be emitted with a label. If the statement has no label in the IR, a
85 /// generic one will be created. Some EDA tools require verification
86 /// statements to be labeled.
87 bool enforceVerifLabels = false;
88
89 /// This is the maximum number of terms in an expression before that
90 /// expression spills a wire.
91 enum { DEFAULT_TERM_LIMIT = 256 };
93
94 /// This is the target width of lines in an emitted Verilog source file in
95 /// columns. Zero indicates no wrapping. Must be < 2^14.
96 enum { DEFAULT_LINE_LENGTH = 90, MAX_LINE_LENGTH = (1 << 14) - 1 };
98
99 /// Return std::nullopt if not wrapping, else the target emission line length.
100 std::optional<unsigned> getEmittedLineLength() const {
101 if (emittedLineLength == 0)
102 return std::nullopt;
103 // This should be rejected in parsing, but in case set directly, saturate.
104 return std::min<unsigned>(MAX_LINE_LENGTH, emittedLineLength);
105 }
106
107 /// Add an explicit bitcast for avoiding bitwidth mismatch LINT errors.
108 bool explicitBitcast = false;
109
110 /// If true, replicated ops are emitted to a header file.
112
113 /// This option controls emitted location information style.
115 Plain, // Default.
116 WrapInAtSquareBracket, // Wrap location info in @[..].
117 None, // No location info comment.
119
120 /// If true, every port is declared separately
121 /// (each includes direction and type (e.g., `input [3:0]`)).
122 /// When false (default), ports share declarations when possible.
124
125 /// Print debug info.
126 bool printDebugInfo = false;
127
128 /// If true, every mux expression is spilled to a wire.
130
131 /// If true, expand `comb.replicate` into an explicit concatenation instead
132 /// of emitting the `{N{...}}` replication operator (unsupported in some
133 /// tools).
134 bool disallowReplicate = false;
135
136 /// This controls extra wire spilling performed in PrepareForEmission to
137 /// improve readablitiy and debuggability.
138 enum WireSpillingHeuristic : unsigned {
139 SpillLargeTermsWithNamehints = 1, // Spill wires for expressions with
140 // namehints if the term size is greater
141 // than `wireSpillingNamehintTermLimit`.
142 };
143
145
147 return static_cast<bool>(wireSpillingHeuristicSet & heurisic);
148 }
149
152
153 /// If true, every expression passed to an instance port is driven by a wire.
154 /// Some lint tools dislike expressions being inlined into input ports so this
155 /// option avoids such warnings.
157
158 /// If true, every expression used as an array index is driven by a wire, and
159 /// the wire is marked as `(* keep = "true" *)`. Certain versions of Vivado
160 /// produce incorrect synthesis results for certain arithmetic ops inlined
161 /// into the array index.
163
164 /// Controls the port declaration syntax for module ports.
165 ///
166 /// - emitVarLogic: Emits `var logic` in the port lists rather than nothing,
167 /// i.e., default plain (non-handle) ports to a variable (`input var logic
168 /// ...`, `output var logic ...`).
169 /// - emitWire: Emits 'wire' in port lists rather than nothing. Used in cases
170 /// where `default_nettype` is not set to wire.
171 /// - emitNone: Omits both `var logic` and `wire` in port lists; relies
172 /// on standard SystemVerilog implicit net-kind port declaration.
178
179 /// If true, emit a comment wherever an instance wasn't printed, because
180 /// it's emitted elsewhere as a bind.
181 bool emitBindComments = false;
182
183 /// If true, do not emit a version comment at the top of each verilog file.
184 bool omitVersionComment = false;
185
186 /// If true, then unique names that collide with keywords case insensitively.
187 /// This is used to avoid stricter lint warnings which, e.g., treat "REG" as a
188 /// Verilog keyword.
190
191 /// If true, then update the the mlir to include output verilog locations.
193
194 /// If true, add a dummy wire to empty modules to prevent tools from regarding
195 /// the module as blackbox.
196 bool fixUpEmptyModules = false;
197
198 // If true, wrap concurrent assertions with explicit clocking events into
199 // procedural form, by hoisting the clock event into an enclosing always
200 // block. The same transformation is applied to `assume property` and `cover
201 // property`.
203
204 // If true, always emit assignments (both continuous and blocking) separately
205 // rather than inlining them in net and variable declarations
207
208 /// If true, always emit begin/end blocks around if/else/always bodies, even
209 /// when there is only a single statement.
210 bool alwaysEmitBeginEnd = false;
211
212 /// Controls the declaration syntax emitted for `sv.var`.
213 ///
214 /// - VarLogic: Always emits the `var` keyword. Integer vectors print as `var
215 /// logic [3:0] x`; types that supply their own data type (structs, unions,
216 /// enums, typedefs) print as `var my_struct x`.
217 /// - Logic: Omits the `var` keyword, Integer vectors print as `logic [3:0]
218 /// x`; types that supply their own data type print with no prefix (`my_struct
219 /// x`).
220 /// - Reg: Omits the `var` keyword, Integer vectors print as `reg [3:0] x`;
221 /// types that supply their own data type print with no prefix (`my_struct
222 /// x`).
223 ///
224 /// All there styles are equivalent in meaning and differ only in spelling.
230};
231} // namespace circt
232
233#endif // CIRCT_SUPPORT_LOWERINGOPTIONS_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
bool isWireSpillingHeuristicEnabled(WireSpillingHeuristic heurisic) const
bool noAlwaysComb
If true, emits sv.alwayscomb as Verilog always @(*) statements.
bool mitigateVivadoArrayIndexConstPropBug
If true, every expression used as an array index is driven by a wire, and the wire is marked as (* ke...
bool disallowLocalVariables
If true, do not emit SystemVerilog locally scoped "automatic" or logic declarations - emit top level ...
bool omitVersionComment
If true, do not emit a version comment at the top of each verilog file.
bool enforceVerifLabels
If true, verification statements like assert, assume, and cover will always be emitted with a label.
bool disallowExpressionInliningInPorts
If true, every expression passed to an instance port is driven by a wire.
bool printDebugInfo
Print debug info.
llvm::function_ref< void(llvm::Twine)> ErrorHandlerT
Error callback type used to indicate errors parsing the options string.
LocationInfoStyle
This option controls emitted location information style.
unsigned maximumNumberOfTermsPerExpression
EmitPortType
Controls the port declaration syntax for module ports.
WireSpillingHeuristic
This controls extra wire spilling performed in PrepareForEmission to improve readablitiy and debuggab...
void setAsAttribute(mlir::ModuleOp module)
Write the verilog emitter options to a module's attributes.
VarOpDeclStyle
Controls the declaration syntax emitted for sv.var.
enum circt::LoweringOptions::LocationInfoStyle locationInfoStyle
enum circt::LoweringOptions::EmitPortType emitPortType
bool disallowPortDeclSharing
If true, every port is declared separately (each includes direction and type (e.g....
bool disallowPackedArrays
If true, eliminate packed arrays for tools that don't support them (e.g.
std::optional< unsigned > getEmittedLineLength() const
Return std::nullopt if not wrapping, else the target emission line length.
LoweringOptions(llvm::StringRef options, ErrorHandlerT errorHandler)
Create a LoweringOptions and read in options from a string, overriding only the set options in the st...
bool explicitBitcast
Add an explicit bitcast for avoiding bitwidth mismatch LINT errors.
bool disallowReplicate
If true, expand comb.replicate into an explicit concatenation instead of emitting the {N{....
bool disallowMuxInlining
If true, every mux expression is spilled to a wire.
bool fixUpEmptyModules
If true, add a dummy wire to empty modules to prevent tools from regarding the module as blackbox.
bool disallowPackedStructAssignments
If true, eliminate packed struct assignments in favor of a wire + assignments to the individual field...
void parse(llvm::StringRef options, ErrorHandlerT callback)
Read in options from a string, overriding only the set options in the string.
static mlir::StringAttr getAttributeFrom(mlir::ModuleOp module)
Return the value of the circt.loweringOptions in the specified module if present, or a null attribute...
bool caseInsensitiveKeywords
If true, then unique names that collide with keywords case insensitively.
void parseFromAttribute(mlir::ModuleOp module)
Load any emitter options from the module.
bool alwaysEmitBeginEnd
If true, always emit begin/end blocks around if/else/always bodies, even when there is only a single ...
bool emitReplicatedOpsToHeader
If true, replicated ops are emitted to a header file.
std::string toString() const
Returns a string representation of the options.
LoweringOptions()=default
Create a LoweringOptions with the default values.
bool allowExprInEventControl
If true, expressions are allowed in the sensitivity list of always statements, otherwise they are for...
bool emitVerilogLocations
If true, then update the the mlir to include output verilog locations.
bool emitBindComments
If true, emit a comment wherever an instance wasn't printed, because it's emitted elsewhere as a bind...
enum circt::LoweringOptions::VarOpDeclStyle varOpDeclStyle