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 /// Indicates if this module is instantiated under the design-under-test.
112
113 /// Indicates if this module is instantiated under a layer.
115
116 /// Indicates if this module is instantiated in the design. The "design" is
117 /// defined as being under the design-under-test, excluding verification
118 /// code (e.g., layers).
120
121 /// Indicates if this modules is instantiated in the effective design. The
122 /// "effective design" is defined as the design-under-test (DUT), excluding
123 /// verification code (e.g., layers). If a DUT is specified, then this is
124 /// the same as `inDesign`. However, if there is no DUT, then every module
125 /// is deemed to be in the design except those which are explicitly
126 /// verification code.
128
129 /// Indicates if this module is instantiated within (or transitively within)
130 /// an instance choice operation.
132 };
133
134 //===--------------------------------------------------------------------===//
135 // Circuit Attribute Queries
136 //===--------------------------------------------------------------------===//
137
138 /// Return true if this circuit has a design-under-test.
139 bool hasDut();
140
141 /// Return the design-under-test if one is defined for the circuit, otherwise
142 /// return null.
143 igraph::ModuleOpInterface getDut();
144
145 /// Return the "effective" design-under-test. This will be the
146 /// design-under-test if one is defined. Otherwise, this will be the root
147 /// node of the instance graph.
148 igraph::ModuleOpInterface getEffectiveDut();
149
150 //===--------------------------------------------------------------------===//
151 // Module Attribute Queries
152 //===--------------------------------------------------------------------===//
153
154 /// Return true if this module is the design-under-test.
155 bool isDut(igraph::ModuleOpInterface op);
156
157 /// Return true if this module is the design-under-test and the circuit has a
158 /// design-under-test. If the circuit has no design-under-test, then return
159 /// true if this is the top module.
160 bool isEffectiveDut(igraph::ModuleOpInterface op);
161
162 /// Return true if at least one instance of this module is under (or
163 /// transitively under) the design-under-test. This is true if the module is
164 /// the design-under-test.
165 bool anyInstanceUnderDut(igraph::ModuleOpInterface op);
166
167 /// Return true if all instances of this module are under (or transitively
168 /// under) the design-under-test. This is true if the module is the
169 /// design-under-test.
170 bool allInstancesUnderDut(igraph::ModuleOpInterface op);
171
172 /// Return true if at least one instance is under (or transitively under) the
173 /// effective design-under-test. This is true if the module is the effective
174 /// design-under-test.
175 bool anyInstanceUnderEffectiveDut(igraph::ModuleOpInterface op);
176
177 /// Return true if all instances are under (or transitively under) the
178 /// effective design-under-test. This is true if the module is the effective
179 /// design-under-test.
180 bool allInstancesUnderEffectiveDut(igraph::ModuleOpInterface op);
181
182 /// Return true if at least one instance of this module is under (or
183 /// transitively under) a layer.
184 bool anyInstanceUnderLayer(igraph::ModuleOpInterface op);
185
186 /// Return true if all instances of this module are under (or transitively
187 /// under) layer blocks.
188 bool allInstancesUnderLayer(igraph::ModuleOpInterface op);
189
190 /// Return true if any instance of this module is within (or transitively
191 /// within) the design.
192 bool anyInstanceInDesign(igraph::ModuleOpInterface op);
193
194 /// Return true if all instances of this module are within (or transitively
195 /// withiin) the design.
196 bool allInstancesInDesign(igraph::ModuleOpInterface op);
197
198 /// Return true if any instance of this module is within (or transitively
199 /// within) the effective design
200 bool anyInstanceInEffectiveDesign(igraph::ModuleOpInterface op);
201
202 /// Return true if all instances of this module are within (or transitively
203 /// withiin) the effective design.
204 bool allInstancesInEffectiveDesign(igraph::ModuleOpInterface op);
205
206 /// Return true if any instance of this module is within (or transitively
207 /// within) an instance choice.
208 /// Note: allInstancesInInstanceChoice is intentionally not provided because
209 /// that property is relative to the public module.
210 bool anyInstanceInInstanceChoice(igraph::ModuleOpInterface op);
211
212private:
213 /// Stores circuit-level attributes.
215 /*effectiveDut=*/nullptr};
216
217 /// Internal mapping of operations to module attributes.
218 DenseMap<Operation *, ModuleAttributes> moduleAttributes;
219
220 /// Return the module attributes associated with a module.
221 const ModuleAttributes &getModuleAttributes(igraph::ModuleOpInterface op);
222};
223
224#ifndef NDEBUG
225inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
226 const InstanceInfo::LatticeValue &value) {
227 if (value.isUnknown())
228 return os << "unknown";
229 if (value.isConstant())
230 return os << "constant<" << (value.getConstant() ? "true" : "false") << ">";
231 return os << "mixed";
232}
233#endif
234
235} // namespace firrtl
236} // namespace circt
237
238#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.
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 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 withiin) 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 withiin) 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.
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.
InstanceInfo::LatticeValue underLayer
Indicates if this module is instantiated under a layer.