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 /// A lattice value to record the value of a property.
42
43 public:
44 enum Kind {
45 // Indicates that we have no information about this property. Properties
46 // start in this state and then are changed to Constant or Mixed.
48
49 // Indicates that the property has a true or false value.
51
52 // Indicates that the property was found to be both true and false.
53 Mixed
54 };
55
56 private:
57 /// Whether or not the property holds.
59
60 /// The value of the property if `kind` is `Constant`.
61 bool value = false;
62
63 public:
64 /// Return true if the kind is Unknown.
65 bool isUnknown() const;
66
67 /// Return true if the kind is Constant.
68 bool isConstant() const;
69
70 /// Return true if the kind is Mixed.
71 bool isMixed() const;
72
73 /// Return the value. This should only be used if the kind is Constant.
74 bool getConstant() const;
75
76 /// Set this LatticeValue to a constant.
77 void markConstant(bool constant);
78
79 /// Set this LatticeValue to mixed.
80 void markMixed();
81
82 /// Merge attributes from another LatticeValue into this one.
83 void mergeIn(LatticeValue that);
84
85 /// Merge a constant value into this one.
86 void mergeIn(bool value);
87
88 /// Invert the lattice value.
90 };
91
92 /// Information about a circuit
94 /// The design-under-test if one is defined.
95 igraph::ModuleOpInterface dut;
96
97 /// The design-under-test if one is defined or the top module.
98 igraph::ModuleOpInterface effectiveDut;
99 };
100
101 /// Information about a module
103 /// Indicates if this module is instantiated under the design-under-test.
105
106 /// Indicates if this module is instantiated under a layer.
108
109 /// Indicates if this module is instantiated in the design. The "design" is
110 /// defined as being under the design-under-test, excluding verification
111 /// code (e.g., layers).
113
114 /// Indicates if this modules is instantiated in the effective design. The
115 /// "effective design" is defined as the design-under-test (DUT), excluding
116 /// verification code (e.g., layers). If a DUT is specified, then this is
117 /// the same as `inDesign`. However, if there is no DUT, then every module
118 /// is deemed to be in the design except those which are explicitly
119 /// verification code.
121
122 /// Indicates if this module is instantiated within (or transitively within)
123 /// an instance choice operation.
125 };
126
127 //===--------------------------------------------------------------------===//
128 // Circuit Attribute Queries
129 //===--------------------------------------------------------------------===//
130
131 /// Return true if this circuit has a design-under-test.
132 bool hasDut();
133
134 /// Return the design-under-test if one is defined for the circuit, otherwise
135 /// return null.
136 igraph::ModuleOpInterface getDut();
137
138 /// Return the "effective" design-under-test. This will be the
139 /// design-under-test if one is defined. Otherwise, this will be the root
140 /// node of the instance graph.
141 igraph::ModuleOpInterface getEffectiveDut();
142
143 //===--------------------------------------------------------------------===//
144 // Module Attribute Queries
145 //===--------------------------------------------------------------------===//
146
147 /// Return true if this module is the design-under-test.
148 bool isDut(igraph::ModuleOpInterface op);
149
150 /// Return true if this module is the design-under-test and the circuit has a
151 /// design-under-test. If the circuit has no design-under-test, then return
152 /// true if this is the top module.
153 bool isEffectiveDut(igraph::ModuleOpInterface op);
154
155 /// Return true if at least one instance of this module is under (or
156 /// transitively under) the design-under-test. This is true if the module is
157 /// the design-under-test.
158 bool anyInstanceUnderDut(igraph::ModuleOpInterface op);
159
160 /// Return true if all instances of this module are under (or transitively
161 /// under) the design-under-test. This is true if the module is the
162 /// design-under-test.
163 bool allInstancesUnderDut(igraph::ModuleOpInterface op);
164
165 /// Return true if at least one instance is under (or transitively under) the
166 /// effective design-under-test. This is true if the module is the effective
167 /// design-under-test.
168 bool anyInstanceUnderEffectiveDut(igraph::ModuleOpInterface op);
169
170 /// Return true if all instances are under (or transitively under) the
171 /// effective design-under-test. This is true if the module is the effective
172 /// design-under-test.
173 bool allInstancesUnderEffectiveDut(igraph::ModuleOpInterface op);
174
175 /// Return true if at least one instance of this module is under (or
176 /// transitively under) a layer.
177 bool anyInstanceUnderLayer(igraph::ModuleOpInterface op);
178
179 /// Return true if all instances of this module are under (or transitively
180 /// under) layer blocks.
181 bool allInstancesUnderLayer(igraph::ModuleOpInterface op);
182
183 /// Return true if any instance of this module is within (or transitively
184 /// within) the design.
185 bool anyInstanceInDesign(igraph::ModuleOpInterface op);
186
187 /// Return true if all instances of this module are within (or transitively
188 /// withiin) the design.
189 bool allInstancesInDesign(igraph::ModuleOpInterface op);
190
191 /// Return true if any instance of this module is within (or transitively
192 /// within) the effective design
193 bool anyInstanceInEffectiveDesign(igraph::ModuleOpInterface op);
194
195 /// Return true if all instances of this module are within (or transitively
196 /// withiin) the effective design.
197 bool allInstancesInEffectiveDesign(igraph::ModuleOpInterface op);
198
199 /// Return true if any instance of this module is within (or transitively
200 /// within) an instance choice.
201 /// Note: allInstancesInInstanceChoice is intentionally not provided because
202 /// that property is relative to the public module.
203 bool anyInstanceInInstanceChoice(igraph::ModuleOpInterface op);
204
205private:
206 /// Stores circuit-level attributes.
208 /*effectiveDut=*/nullptr};
209
210 /// Internal mapping of operations to module attributes.
211 DenseMap<Operation *, ModuleAttributes> moduleAttributes;
212
213 /// Return the module attributes associated with a module.
214 const ModuleAttributes &getModuleAttributes(igraph::ModuleOpInterface op);
215};
216
217#ifndef NDEBUG
218inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
219 const InstanceInfo::LatticeValue &value) {
220 if (value.isUnknown())
221 return os << "unknown";
222 if (value.isConstant())
223 return os << "constant<" << (value.getConstant() ? "true" : "false") << ">";
224 return os << "mixed";
225}
226#endif
227
228} // namespace firrtl
229} // namespace circt
230
231#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.