17 #include "mlir/IR/Attributes.h"
18 #include "mlir/IR/Builders.h"
19 #include "mlir/Pass/Pass.h"
23 #define GEN_PASS_DEF_RANDOMIZEREGISTERINIT
24 #include "circt/Dialect/FIRRTL/Passes.h.inc"
29 using namespace circt;
30 using namespace firrtl;
33 struct RandomizeRegisterInitPass
34 :
public circt::firrtl::impl::RandomizeRegisterInitBase<
35 RandomizeRegisterInitPass> {
36 void runOnOperation()
override;
42 return std::make_unique<RandomizeRegisterInitPass>();
51 OpBuilder builder(mod);
54 uint64_t currentWidth = 0;
55 auto ui64Type = builder.getIntegerType(64,
false);
56 mod.walk([&](Operation *op) {
57 if (!isa<RegOp, RegResetOp>(op))
62 auto regType = type_cast<FIRRTLBaseType>(op->getResult(0).getType());
63 std::optional<int64_t> regWidth =
getBitWidth(regType);
64 assert(regWidth.has_value() &&
"register must have a valid FIRRTL width");
66 auto start = builder.getIntegerAttr(ui64Type, currentWidth);
67 op->setAttr(
"firrtl.random_init_start", start);
69 currentWidth += *regWidth;
73 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.