19 #include "mlir/IR/Attributes.h"
20 #include "mlir/IR/Builders.h"
21 #include "mlir/Pass/Pass.h"
22 #include "llvm/Support/Parallel.h"
26 #define GEN_PASS_DEF_RANDOMIZEREGISTERINIT
27 #include "circt/Dialect/FIRRTL/Passes.h.inc"
32 using namespace circt;
33 using namespace firrtl;
36 struct RandomizeRegisterInitPass
37 :
public circt::firrtl::impl::RandomizeRegisterInitBase<
38 RandomizeRegisterInitPass> {
39 void runOnOperation()
override;
45 return std::make_unique<RandomizeRegisterInitPass>();
54 OpBuilder builder(mod);
57 uint64_t currentWidth = 0;
58 auto ui64Type = builder.getIntegerType(64,
false);
59 mod.walk([&](Operation *op) {
60 if (!isa<RegOp, RegResetOp>(op))
65 auto regType = type_cast<FIRRTLBaseType>(op->getResult(0).getType());
66 std::optional<int64_t> regWidth =
getBitWidth(regType);
67 assert(regWidth.has_value() &&
"register must have a valid FIRRTL width");
69 auto start = builder.getIntegerAttr(ui64Type, currentWidth);
70 op->setAttr(
"firrtl.random_init_start", start);
72 currentWidth += *regWidth;
76 void RandomizeRegisterInitPass::runOnOperation() {
assert(baseType &&"element must be base type")
static void createRandomizationAttributes(FModuleOp mod)
Create attributes indicating the required size of random initialization values for each register in t...
std::unique_ptr< mlir::Pass > createRandomizeRegisterInitPass()
std::optional< int64_t > getBitWidth(FIRRTLBaseType type, bool ignoreFlip=false)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.