20 #include "mlir/IR/Attributes.h"
21 #include "mlir/IR/Builders.h"
22 #include "llvm/Support/Parallel.h"
25 using namespace circt;
26 using namespace firrtl;
29 struct RandomizeRegisterInitPass
30 :
public RandomizeRegisterInitBase<RandomizeRegisterInitPass> {
31 void runOnOperation()
override;
37 return std::make_unique<RandomizeRegisterInitPass>();
49 uint64_t currentWidth = 0;
50 auto ui64Type =
builder.getIntegerType(64,
false);
51 mod.walk([&](Operation *op) {
52 if (!isa<RegOp, RegResetOp>(op))
57 auto regType = type_cast<FIRRTLBaseType>(op->getResult(0).getType());
58 std::optional<int64_t> regWidth =
getBitWidth(regType);
59 assert(regWidth.has_value() &&
"register must have a valid FIRRTL width");
61 auto start =
builder.getIntegerAttr(ui64Type, currentWidth);
62 op->setAttr(
"firrtl.random_init_start", start);
64 currentWidth += *regWidth;
68 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)
This file defines an intermediate representation for circuits acting as an abstraction for constraint...