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"
33struct RandomizeRegisterInitPass
34 :
public circt::firrtl::impl::RandomizeRegisterInitBase<
35 RandomizeRegisterInitPass> {
36 void runOnOperation()
override;
47 OpBuilder builder(mod);
50 uint64_t currentWidth = 0;
51 auto ui64Type = builder.getIntegerType(64,
false);
52 mod.walk([&](Operation *op) {
53 if (!isa<RegOp, RegResetOp>(op))
59 std::optional<int64_t> regWidth =
getBitWidth(regType);
60 assert(regWidth.has_value() &&
"register must have a valid FIRRTL width");
62 auto start = builder.getIntegerAttr(ui64Type, currentWidth);
63 op->setAttr(
"firrtl.random_init_start", start);
65 currentWidth += *regWidth;
69void 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...
BaseTy type_cast(Type type)
std::optional< int64_t > getBitWidth(FIRRTLBaseType type, bool ignoreFlip=false)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.