22#include "llvm/ADT/PostOrderIterator.h"
23#include "llvm/Support/Debug.h"
26#include "llvm/ADT/DepthFirstIterator.h"
29#define DEBUG_TYPE "firrtl-analysis-instanceinfo"
32using namespace firrtl;
35 return inst.getLowerToBind() || inst.getDoNotPrint() ||
36 inst->getParentOfType<LayerBlockOp>() ||
62 if (kind < that.
kind) {
75 mergeIn(latticeValue);
79 if (isUnknown() || isMixed())
92 for (
auto *node : iGraph) {
93 auto moduleOp = node->getModule();
102 for (
auto *node : iGraph) {
106 auto moduleOp = node->getModule();
118 iGraph.walkInversePostOrder([&](
auto &modIt) {
119 auto moduleOp = modIt.getModule();
124 auto isGCCompanion = annotations.
hasAnnotation(companionAnnoClass);
139 for (
auto *useIt : modIt.uses()) {
140 auto parentOp = useIt->getParent()->getModule();
148 bool underLayer =
false;
149 if (
auto instanceOp = useIt->template getInstance<InstanceOp>())
153 if (
auto instanceChoiceOp =
154 useIt->template getInstance<InstanceChoiceOp>()) {
156 if (instanceChoiceOp->template getParentOfType<LayerBlockOp>() ||
157 instanceChoiceOp->template getParentOfType<sv::IfDefOp>())
162 if (!isGCCompanion) {
173 }
else if (!
isDut && !isGCCompanion) {
181 mlir::OpPrintingFlags flags;
185 << llvm::indent(2) <<
"circuit attributes:\n"
186 << llvm::indent(4) <<
"hasDut: " << (
hasDut() ?
"true" :
"false")
188 << llvm::indent(4) <<
"dut: ";
190 dut->print(llvm::dbgs(), flags);
192 llvm::dbgs() <<
"null";
193 llvm::dbgs() <<
"\n" << llvm::indent(4) <<
"effectiveDut: ";
195 llvm::dbgs() <<
"\n" << llvm::indent(2) <<
"module attributes:\n";
196 iGraph.walkInversePostOrder([&](
auto &modIt) {
197 auto moduleOp = modIt.getModule();
199 llvm::dbgs().indent(4)
200 <<
"- module: " << moduleOp.getModuleName() <<
"\n"
202 <<
"isDut: " << (
isDut(moduleOp) ?
"true" :
"false") <<
"\n"
204 <<
"isEffectiveDue: " << (
isEffectiveDut(moduleOp) ?
"true" :
"false")
206 << llvm::indent(6) <<
"underDut: " << attributes.underDut <<
"\n"
207 << llvm::indent(6) <<
"underLayer: " << attributes.underLayer <<
"\n"
208 << llvm::indent(6) <<
"inDesign: " << attributes.inDesign <<
"\n"
210 <<
"inEffectiveDesign: " << attributes.inEffectiveDesign <<
"\n"
212 <<
"inInstanceChoice: " << attributes.inInstanceChoice <<
"\n";
251 return underDut.
isConstant() && underDut.getConstant();
269 return underLayer.
isConstant() && underLayer.getConstant();
279 return inDesign.
isConstant() && inDesign.getConstant();
289 return inEffectiveDesign.
isConstant() && inEffectiveDesign.getConstant();
294 return inInstanceChoice.
isMixed() ||
295 (inInstanceChoice.isConstant() && inInstanceChoice.getConstant());
assert(baseType &&"element must be base type")
static std::optional< APSInt > getConstant(Attribute operand)
Determine the value of a constant operand for the sake of constant folding.
This class provides a read-only projection over the MLIR attributes that represent a set of annotatio...
bool hasAnnotation(StringRef className) const
Return true if we have an annotation with the specified class name.
This graph tracks modules and where they are instantiated.
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.
InstanceInfo(Operation *op, mlir::AnalysisManager &am)
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.
bool isConstant(Operation *op)
Return true if the specified operation has a constant value.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
llvm::raw_ostream & debugHeader(const llvm::Twine &str, unsigned width=80)
Write a "header"-like string to the debug stream with a certain width.
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.
Information about a 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.