diff --git a/lib/Tools/circt-bmc/ExternalizeRegisters.cpp b/lib/Tools/circt-bmc/ExternalizeRegisters.cpp index 659ef0dfbff8..08358b270898 100644 --- a/lib/Tools/circt-bmc/ExternalizeRegisters.cpp +++ b/lib/Tools/circt-bmc/ExternalizeRegisters.cpp @@ -96,22 +96,15 @@ void ExternalizeRegistersPass::runOnOperation() { } mlir::Attribute initState; if (auto initVal = regOp.getInitialValue()) { - // Find the seq.initial op where the initial value is defined and - // fetch the operation inside that defines the value - auto initialOp = - regOp.getInitialValue().getDefiningOp(); - if (!initialOp) { + // Find the constant op that defines the reset value in an initial + // block (if it exists) + if (!initVal.getDefiningOp()) { regOp.emitError("registers with initial values not directly " "defined by a seq.initial op not yet supported"); return signalPassFailure(); } - auto index = cast(initVal).getResultNumber(); - auto initValDef = - initialOp->getRegion(0).front().getTerminator()->getOperand( - index); - // If it's defined by a constant op then just fetch the constant - // value - otherwise unsupported - if (auto constantOp = initValDef.getDefiningOp()) { + if (auto constantOp = circt::seq::unwrapImmutableValue(initVal) + .getDefiningOp()) { // Fetch value from constant op - leave removing the dead op to // DCE initState = constantOp.getValueAttr();