Skip to content

Commit

Permalink
[ExternalizeRegisters][NFC] Clean up initial value fetching with unwr…
Browse files Browse the repository at this point in the history
…apImmutableValue
  • Loading branch information
TaoBi22 committed Nov 19, 2024
1 parent 6754869 commit 9a7c11c
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lib/Tools/circt-bmc/ExternalizeRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,16 @@ 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<seq::InitialOp>();
if (!initialOp) {
// Find the constant op that defines the reset value in an initial
// block (if it exists)
if (isa<BlockArgument>(initVal) ||
!isa<seq::InitialOp>(initVal.getDefiningOp())) {
regOp.emitError("registers with initial values not directly "
"defined by a seq.initial op not yet supported");
return signalPassFailure();
}
auto index = cast<OpResult>(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<hw::ConstantOp>()) {
if (auto constantOp = circt::seq::unwrapImmutableValue(initVal)
.getDefiningOp<hw::ConstantOp>()) {
// Fetch value from constant op - leave removing the dead op to
// DCE
initState = constantOp.getValueAttr();
Expand Down

0 comments on commit 9a7c11c

Please sign in to comment.