Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLOpInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ struct PortInfo {
annotations(annos), domains(domains) {}
};

inline bool operator==(const PortInfo &lhs, const PortInfo &rhs) {
if (lhs.name != rhs.name)
return false;
if (lhs.type != rhs.type)
return false;
if (lhs.direction != rhs.direction)
return false;
if (lhs.sym != rhs.sym)
return false;
if (lhs.loc != rhs.loc)
return false;
if (lhs.annotations != rhs.annotations)
return false;
if (lhs.domains != rhs.domains)
return false;
return true;
}

inline bool operator!=(const PortInfo &lhs, const PortInfo &rhs) {
return !(lhs == rhs);
}

enum class ConnectBehaviorKind {
/// Classic FIRRTL connections: last connect 'wins' across paths;
/// conditionally applied under 'when'.
Expand Down
20 changes: 20 additions & 0 deletions include/circt/Dialect/FIRRTL/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ enum class CompanionMode {
Drop,
};

/// The mode for the InferDomains pass.
enum class InferDomainsMode {
/// Check domains with inference for private modules (default).
Infer,
/// Check domains without inference.
Check,
/// Check domains with inference for both public and private modules.
InferAll,
};

/// True if the mode indicates we should infer domains on public modules.
constexpr bool shouldInferPublicModules(InferDomainsMode mode) {
return mode == InferDomainsMode::InferAll;
}

/// True if the mode indicates we should infer domains on private modules.
constexpr bool shouldInferPrivateModules(InferDomainsMode mode) {
return mode == InferDomainsMode::Infer || mode == InferDomainsMode::InferAll;
}

#define GEN_PASS_DECL
#include "circt/Dialect/FIRRTL/Passes.h.inc"

Expand Down
25 changes: 25 additions & 0 deletions include/circt/Dialect/FIRRTL/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,31 @@ def CheckLayers : Pass<"firrtl-check-layers", "firrtl::CircuitOp"> {
}];
}

def InferDomains : Pass<"firrtl-infer-domains", "firrtl::CircuitOp"> {
let summary = "Infer and type check all firrtl domains";
let description = [{
This pass does domain inference on a FIRRTL circuit. The end result of this
is either a corrrctly domain-checked FIRRTL circuit or failure with verbose
error messages indicating why the FIRRTL circuit has illegal domain
constructs.

E.g., this pass can be used to check for illegal clock-domain-crossings if
clock domains are specified for signals in the design.
}];
let options = [Option<"mode", "mode", "InferDomainsMode",
"InferDomainsMode::Infer", "infer, check, infer-all.",
[{
llvm::cl::values(
clEnumValN(InferDomainsMode::Infer, "infer",
"Check domains with inference for private modules"),
clEnumValN(InferDomainsMode::Check, "check",
"Check domains without inference"),
clEnumValN(InferDomainsMode::InferAll, "infer-all",
"Check domains with inference for both public and private "
"modules"))
}]>];
}

def LowerDomains : Pass<"firrtl-lower-domains", "firrtl::CircuitOp"> {
let summary = "lower domain information to properties";
let description = [{
Expand Down
36 changes: 36 additions & 0 deletions include/circt/Firtool/Firtool.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require updates to the C-API?

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@

namespace circt {
namespace firtool {

enum class DomainMode {
/// Disable domain checking.
Disable,
/// Check domains with inference for private modules.
Infer,
/// Check domains without inference.
Check,
/// Check domains with inference for both public and private modules.
InferAll,
};

/// Convert the "domain mode" firtool option to a "firrtl::InferDomainsMode",
/// the configuration for a pass.
constexpr std::optional<firrtl::InferDomainsMode>
toInferDomainsPassMode(DomainMode mode) {
switch (mode) {
case DomainMode::Disable:
return std::nullopt;
case DomainMode::Infer:
return firrtl::InferDomainsMode::Infer;
case DomainMode::Check:
return firrtl::InferDomainsMode::Check;
case DomainMode::InferAll:
return firrtl::InferDomainsMode::InferAll;
}
}

//===----------------------------------------------------------------------===//
// FirtoolOptions
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -144,6 +172,8 @@ class FirtoolOptions {

bool getEmitAllBindFiles() const { return emitAllBindFiles; }

DomainMode getDomainMode() const { return domainMode; }

// Setters, used by the CAPI
FirtoolOptions &setOutputFilename(StringRef name) {
outputFilename = name;
Expand Down Expand Up @@ -393,6 +423,11 @@ class FirtoolOptions {
return *this;
}

FirtoolOptions &setdomainMode(DomainMode value) {
domainMode = value;
return *this;
}

private:
std::string outputFilename;

Expand Down Expand Up @@ -447,6 +482,7 @@ class FirtoolOptions {
bool lintStaticAsserts;
bool lintXmrsInDesign;
bool emitAllBindFiles;
DomainMode domainMode;
};

void registerFirtoolCLOptions();
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/FIRRTL/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_circt_dialect_library(CIRCTFIRRTLTransforms
GrandCentral.cpp
IMConstProp.cpp
IMDeadCodeElim.cpp
InferDomains.cpp
InferReadWrite.cpp
InferResets.cpp
InferWidths.cpp
Expand Down
Loading
Loading