Skip to content

Commit 4ceeecc

Browse files
seldridgerwy7
authored andcommitted
[FIRRTL] Add InferDomains pass
Add a pass that does domain inference and checking. This is used to verify the legality of a FIRRTL circuit with respect to its domains. E.g., this pass is intended to be used for checking for illegal clock domain crossings. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 78721e6 commit 4ceeecc

File tree

9 files changed

+1778
-1
lines changed

9 files changed

+1778
-1
lines changed

include/circt/Dialect/FIRRTL/FIRRTLOpInterfaces.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ struct PortInfo {
8585
annotations(annos), domains(domains) {}
8686
};
8787

88+
inline bool operator==(const PortInfo &lhs, const PortInfo &rhs) {
89+
if (lhs.name != rhs.name)
90+
return false;
91+
if (lhs.type != rhs.type)
92+
return false;
93+
if (lhs.direction != rhs.direction)
94+
return false;
95+
if (lhs.sym != rhs.sym)
96+
return false;
97+
if (lhs.loc != rhs.loc)
98+
return false;
99+
if (lhs.annotations != rhs.annotations)
100+
return false;
101+
if (lhs.domains != rhs.domains)
102+
return false;
103+
return true;
104+
}
105+
106+
inline bool operator!=(const PortInfo &lhs, const PortInfo &rhs) {
107+
return !(lhs == rhs);
108+
}
109+
88110
enum class ConnectBehaviorKind {
89111
/// Classic FIRRTL connections: last connect 'wins' across paths;
90112
/// conditionally applied under 'when'.

include/circt/Dialect/FIRRTL/Passes.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,19 @@ def CheckLayers : Pass<"firrtl-check-layers", "firrtl::CircuitOp"> {
909909
}];
910910
}
911911

912+
def InferDomains : Pass<"firrtl-infer-domains", "firrtl::CircuitOp"> {
913+
let summary = "Infer and type check all firrtl domains";
914+
let description = [{
915+
This pass does domain inference on a FIRRTL circuit. The end result of this
916+
is either a corrrctly domain-checked FIRRTL circuit or failure with verbose
917+
error messages indicating why the FIRRTL circuit has illegal domain
918+
constructs.
919+
920+
E.g., this pass can be used to check for illegal clock-domain-crossings if
921+
clock domains are specified for signals in the design.
922+
}];
923+
}
924+
912925
def LowerDomains : Pass<"firrtl-lower-domains", "firrtl::CircuitOp"> {
913926
let summary = "lower domain information to properties";
914927
let description = [{

include/circt/Firtool/Firtool.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class FirtoolOptions {
144144

145145
bool getEmitAllBindFiles() const { return emitAllBindFiles; }
146146

147+
bool shouldInferDomains() const { return inferDomains; }
148+
147149
// Setters, used by the CAPI
148150
FirtoolOptions &setOutputFilename(StringRef name) {
149151
outputFilename = name;
@@ -393,6 +395,11 @@ class FirtoolOptions {
393395
return *this;
394396
}
395397

398+
FirtoolOptions &setInferDomains(bool value) {
399+
inferDomains = value;
400+
return *this;
401+
}
402+
396403
private:
397404
std::string outputFilename;
398405

@@ -447,6 +454,7 @@ class FirtoolOptions {
447454
bool lintStaticAsserts;
448455
bool lintXmrsInDesign;
449456
bool emitAllBindFiles;
457+
bool inferDomains;
450458
};
451459

452460
void registerFirtoolCLOptions();

include/circt/Support/InstanceGraph.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class InstanceGraphNode;
5959
class InstanceRecord
6060
: public llvm::ilist_node_with_parent<InstanceRecord, InstanceGraphNode> {
6161
public:
62+
/// Get the op that this is tracking.
63+
Operation *getOperation() {
64+
return instance.getOperation();
65+
}
66+
6267
/// Get the instance-like op that this is tracking.
6368
template <typename TTarget = InstanceOpInterface>
6469
auto getInstance() {
@@ -113,6 +118,8 @@ class InstanceGraphNode : public llvm::ilist_node<InstanceGraphNode> {
113118
public:
114119
InstanceGraphNode() : module(nullptr) {}
115120

121+
Operation *getOperation() { return module.getOperation(); }
122+
116123
/// Get the module that this node is tracking.
117124
template <typename TTarget = ModuleOpInterface>
118125
auto getModule() {

lib/Dialect/FIRRTL/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_circt_dialect_library(CIRCTFIRRTLTransforms
1717
GrandCentral.cpp
1818
IMConstProp.cpp
1919
IMDeadCodeElim.cpp
20+
InferDomains.cpp
2021
InferReadWrite.cpp
2122
InferResets.cpp
2223
InferWidths.cpp

0 commit comments

Comments
 (0)