CIRCT 23.0.0git
Loading...
Searching...
No Matches
FIRRTLInstanceInfo.h
Go to the documentation of this file.
1//===- FIRRTLInstanceInfo.h - Instance info analysis ------------*- 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 file defines the InstanceInfo analysis. This is an analysis that
10// depends on the InstanceGraph analysis, but provides additional information
11// about FIRRTL operations. This is useful if you find yourself needing to
12// selectively iterate over parts of the design.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEINFO_H
17#define CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEINFO_H
18
20#include "circt/Support/LLVM.h"
21#include "mlir/Pass/AnalysisManager.h"
22
23namespace circt {
24namespace firrtl {
25
27
28public:
29 explicit InstanceInfo(Operation *op, mlir::AnalysisManager &am);
30
31 /// Return true if an instance op should be considered "under a layer" for the
32 /// purposes of metadata emission and other analyses. This includes instances
33 /// that are:
34 /// - Under a LayerBlockOp
35 /// - Under an sv::IfDefOp
36 /// - Marked with getLowerToBind()
37 /// - Marked with getDoNotPrint()
38 static bool isInstanceUnderLayer(InstanceOp inst);
39
40 /// Return true if an instance choice op should be considered "under a layer"
41 /// for the purposes of metadata emission and other analyses. This includes
42 /// instances that are:
43 /// - Under a LayerBlockOp
44 /// - Under an sv::IfDefOp
45 static bool isInstanceUnderLayer(InstanceChoiceOp inst);
46
47 /// A lattice value to record the value of a property.
49
50 public:
51 enum Kind {
52 // Indicates that we have no information about this property. Properties
53 // start in this state and then are changed to Constant or Mixed.
55
56 // Indicates that the property has a true or false value.
58
59 // Indicates that the property was found to be both true and false.
60 Mixed
61 };
62
63 private:
64 /// Whether or not the property holds.
66
67 /// The value of the property if `kind` is `Constant`.
68 bool value = false;
69
70 public:
71 /// Return true if the kind is Unknown.
72 bool isUnknown() const;
73
74 /// Return true if the kind is Constant.
75 bool isConstant() const;
76
77 /// Return true if the kind is Mixed.
78 bool isMixed() const;
79
80 /// Return the value. This should only be used if the kind is Constant.
81 bool getConstant() const;
82
83 /// Set this LatticeValue to a constant.
84 void markConstant(bool constant);
85
86 /// Set this LatticeValue to mixed.
87 void markMixed();
88
89 /// Merge attributes from another LatticeValue into this one.
90 void mergeIn(LatticeValue that);
91
92 /// Merge a constant value into this one.
93 void mergeIn(bool value);
94
95 /// Invert the lattice value.
97 };
98
99 /// Information about a circuit
101 /// The design-under-test if one is defined.
102 igraph::ModuleOpInterface dut;
103
104 /// The design-under-test if one is defined or the top module.
105 igraph::ModuleOpInterface effectiveDut;
106 };
107
108 /// Information about a module
110 public:
111 /// Indicates if this module is instantiated under the design-under-test.
113
114 /// Indicates if this module is instantiated under a layer.
116
117 /// Indicates if this module is instantiated in the design. The "design" is
118 /// defined as being under the design-under-test, excluding verification
119 /// code (e.g., layers).
121
122 /// Indicates if this modules is instantiated in the effective design. The
123 /// "effective design" is defined as the design-under-test (DUT), excluding
124 /// verification code (e.g., layers). If a DUT is specified, then this is
125 /// the same as `inDesign`. However, if there is no DUT, then every module
126 /// is deemed to be in the design except those which are explicitly
127 /// verification code.
129
130 /// Indicates if this module is instantiated within (or transitively within)
131 /// an instance choice operation.
133
134 /// Indicates if this module has any property operations within (or
135 /// transitively within) it, or if it is public or contains (transitively)
136 /// any public modules.
137 bool hasProperties = false;
138
139 /// Return true if the product of post-order information is saturated
140 /// (cannot ever change). This corresponds to all attributes populated
141 /// during the post-order walk are true. This is an optimization that is
142 /// used to short circuit the walk when no more information can change.
144 if (!saturated)
146
147 return saturated;
148 }
149
150 private:
151 bool saturated = false;
152 };
153
154 //===--------------------------------------------------------------------===//
155 // Circuit Attribute Queries
156 //===--------------------------------------------------------------------===//
157
158 /// Return true if this circuit has a design-under-test.
159 bool hasDut();
160
161 /// Return the design-under-test if one is defined for the circuit, otherwise
162 /// return null.
163 igraph::ModuleOpInterface getDut();
164
165 /// Return the "effective" design-under-test. This will be the
166 /// design-under-test if one is defined. Otherwise, this will be the root
167 /// node of the instance graph.
168 igraph::ModuleOpInterface getEffectiveDut();
169
170 //===--------------------------------------------------------------------===//
171 // Module Attribute Queries
172 //===--------------------------------------------------------------------===//
173
174 /// Return true if this module is the design-under-test.
175 bool isDut(igraph::ModuleOpInterface op);
176
177 /// Return true if this module is the design-under-test and the circuit has a
178 /// design-under-test. If the circuit has no design-under-test, then return
179 /// true if this is the top module.
180 bool isEffectiveDut(igraph::ModuleOpInterface op);
181
182 /// Return true if at least one instance of this module is under (or
183 /// transitively under) the design-under-test. This is true if the module is
184 /// the design-under-test.
185 bool anyInstanceUnderDut(igraph::ModuleOpInterface op);
186
187 /// Return true if all instances of this module are under (or transitively
188 /// under) the design-under-test. This is true if the module is the
189 /// design-under-test.
190 bool allInstancesUnderDut(igraph::ModuleOpInterface op);
191
192 /// Return true if at least one instance is under (or transitively under) the
193 /// effective design-under-test. This is true if the module is the effective
194 /// design-under-test.
195 bool anyInstanceUnderEffectiveDut(igraph::ModuleOpInterface op);
196
197 /// Return true if all instances are under (or transitively under) the
198 /// effective design-under-test. This is true if the module is the effective
199 /// design-under-test.
200 bool allInstancesUnderEffectiveDut(igraph::ModuleOpInterface op);
201
202 /// Return true if at least one instance of this module is under (or
203 /// transitively under) a layer.
204 bool anyInstanceUnderLayer(igraph::ModuleOpInterface op);
205
206 /// Return true if all instances of this module are under (or transitively
207 /// under) layer blocks.
208 bool allInstancesUnderLayer(igraph::ModuleOpInterface op);
209
210 /// Return true if any instance of this module is within (or transitively
211 /// within) the design.
212 bool anyInstanceInDesign(igraph::ModuleOpInterface op);
213
214 /// Return true if all instances of this module are within (or transitively
215 /// within) the design.
216 bool allInstancesInDesign(igraph::ModuleOpInterface op);
217
218 /// Return true if any instance of this module is within (or transitively
219 /// within) the effective design
220 bool anyInstanceInEffectiveDesign(igraph::ModuleOpInterface op);
221
222 /// Return true if all instances of this module are within (or transitively
223 /// within) the effective design.
224 bool allInstancesInEffectiveDesign(igraph::ModuleOpInterface op);
225
226 /// Return true if any instance of this module is within (or transitively
227 /// within) an instance choice.
228 /// Note: allInstancesInInstanceChoice is intentionally not provided because
229 /// that property is relative to the public module.
230 bool anyInstanceInInstanceChoice(igraph::ModuleOpInterface op);
231
232 /// Return true if this module contains (or its children transitively contain)
233 /// any property operations, i.e., operations whose operands or results have
234 /// a PropertyType, if any port of the module has a PropertyType, if the
235 /// module is a class, or if the module is public or contains any public
236 /// modules.
237 bool moduleContainsProperties(igraph::ModuleOpInterface op);
238
239private:
240 /// Stores circuit-level attributes.
242 /*effectiveDut=*/nullptr};
243
244 /// Internal mapping of operations to module attributes.
245 DenseMap<Operation *, ModuleAttributes> moduleAttributes;
246
247 /// Return the module attributes associated with a module.
248 const ModuleAttributes &getModuleAttributes(igraph::ModuleOpInterface op);
249};
250
251#ifndef NDEBUG
252inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
253 const InstanceInfo::LatticeValue &value) {
254 if (value.isUnknown())
255 return os << "unknown";
256 if (value.isConstant())
257 return os << "constant<" << (value.getConstant() ? "true" : "false") << ">";
258 return os << "mixed";
259}
260#endif
261
262} // namespace firrtl
263} // namespace circt
264
265#endif // CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEINFO_H
A lattice value to record the value of a property.
LatticeValue operator!()
Invert the lattice value.
void mergeIn(LatticeValue that)
Merge attributes from another LatticeValue into this one.
bool value
The value of the property if kind is Constant.
Kind kind
Whether or not the property holds.
bool getConstant() const
Return the value. This should only be used if the kind is Constant.
void markMixed()
Set this LatticeValue to mixed.
bool isConstant() const
Return true if the kind is Constant.
bool isUnknown() const
Return true if the kind is Unknown.
void markConstant(bool constant)
Set this LatticeValue to a constant.
bool isMixed() const
Return true if the kind is Mixed.
InstanceInfo::LatticeValue inInstanceChoice
Indicates if this module is instantiated within (or transitively within) an instance choice operation...
InstanceInfo::LatticeValue inDesign
Indicates if this module is instantiated in the design.
InstanceInfo::LatticeValue underDut
Indicates if this module is instantiated under the design-under-test.
InstanceInfo::LatticeValue inEffectiveDesign
Indicates if this modules is instantiated in the effective design.
bool postOrderSaturated()
Return true if the product of post-order information is saturated (cannot ever change).
InstanceInfo::LatticeValue underLayer
Indicates if this module is instantiated under a layer.
bool hasProperties
Indicates if this module has any property operations within (or transitively within) it,...
bool allInstancesUnderLayer(igraph::ModuleOpInterface op)
Return true if all instances of this module are under (or transitively under) layer blocks.
igraph::ModuleOpInterface getDut()
Return the design-under-test if one is defined for the circuit, otherwise return null.
bool moduleContainsProperties(igraph::ModuleOpInterface op)
Return true if this module contains (or its children transitively contain) any property operations,...
bool isEffectiveDut(igraph::ModuleOpInterface op)
Return true if this module is the design-under-test and the circuit has a design-under-test.
static bool isInstanceUnderLayer(InstanceOp inst)
Return true if an instance op should be considered "under a layer" for the purposes of metadata emiss...
CircuitAttributes circuitAttributes
Stores circuit-level attributes.
bool hasDut()
Return true if this circuit has a design-under-test.
bool allInstancesInEffectiveDesign(igraph::ModuleOpInterface op)
Return true if all instances of this module are within (or transitively within) the effective design.
bool isDut(igraph::ModuleOpInterface op)
Return true if this module is the design-under-test.
bool anyInstanceUnderDut(igraph::ModuleOpInterface op)
Return true if at least one instance of this module is under (or transitively under) the design-under...
bool anyInstanceUnderEffectiveDut(igraph::ModuleOpInterface op)
Return true if at least one instance is under (or transitively under) the effective design-under-test...
bool allInstancesUnderEffectiveDut(igraph::ModuleOpInterface op)
Return true if all instances are under (or transitively under) the effective design-under-test.
DenseMap< Operation *, ModuleAttributes > moduleAttributes
Internal mapping of operations to module attributes.
igraph::ModuleOpInterface getEffectiveDut()
Return the "effective" design-under-test.
bool allInstancesUnderDut(igraph::ModuleOpInterface op)
Return true if all instances of this module are under (or transitively under) the design-under-test.
const ModuleAttributes & getModuleAttributes(igraph::ModuleOpInterface op)
Return the module attributes associated with a module.
bool anyInstanceInInstanceChoice(igraph::ModuleOpInterface op)
Return true if any instance of this module is within (or transitively within) an instance choice.
bool anyInstanceInEffectiveDesign(igraph::ModuleOpInterface op)
Return true if any instance of this module is within (or transitively within) the effective design.
bool allInstancesInDesign(igraph::ModuleOpInterface op)
Return true if all instances of this module are within (or transitively within) the design.
bool anyInstanceUnderLayer(igraph::ModuleOpInterface op)
Return true if at least one instance of this module is under (or transitively under) a layer.
bool anyInstanceInDesign(igraph::ModuleOpInterface op)
Return true if any instance of this module is within (or transitively within) the design.
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const InstanceInfo::LatticeValue &value)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
igraph::ModuleOpInterface dut
The design-under-test if one is defined.
igraph::ModuleOpInterface effectiveDut
The design-under-test if one is defined or the top module.