Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions include/circt/Dialect/FIRRTL/FIRRTLDeclarations.td
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ def InstanceOp : HardwareDeclOp<"instance", [
/// Hooks for domain information.
ArrayAttr getPortDomain(unsigned portIdx);

/// Builds a new instance with the ports listed in `portIndices` erased, and
/// updates any users of the remaining ports to point at the new instance.
InstanceOp erasePorts(OpBuilder &builder, const llvm::BitVector &portIndices);
/// Clone this instance with inserted ports.
InstanceOp cloneWithInsertedPorts(
ArrayRef<std::pair<unsigned, PortInfo>> insertions);

/// Clone the instance op and add ports. This is usually used in
/// conjuction with adding ports to the referenced module. This will emit
/// the new InstanceOp to the same location.
InstanceOp cloneAndInsertPorts(ArrayRef<std::pair<unsigned, PortInfo>> ports);
/// Clone this instance with inserted ports, then replaces uses.
InstanceOp cloneWithInsertedPortsAndReplaceUses(
ArrayRef<std::pair<unsigned, PortInfo>> insertions);

/// Clone this instance with erased ports.
InstanceOp cloneWithErasedPorts(const llvm::BitVector &erasures);

/// Clone this instance with erased ports, then replaces uses.
InstanceOp cloneWithErasedPortsAndReplaceUses(
const llvm::BitVector &erasures);

//===------------------------------------------------------------------===//
// Instance graph methods
Expand Down Expand Up @@ -211,12 +217,6 @@ def InstanceChoiceOp : HardwareDeclOp<"instance_choice", [
StringAttr getPortName(size_t resultNo) {
return cast<StringAttr>(getPortNames()[resultNo]);
}

/// Builds a new instance with the ports listed in `portIndices` erased, and
/// updates any users of the remaining ports to point at the new instance.
InstanceChoiceOp erasePorts(OpBuilder &builder,
const llvm::BitVector &portIndices);

/// Return the default target attribute.
FlatSymbolRefAttr getDefaultTargetAttr() {
return llvm::cast<FlatSymbolRefAttr>(getModuleNamesAttr()[0]);
Expand All @@ -233,6 +233,21 @@ def InstanceChoiceOp : HardwareDeclOp<"instance_choice", [
/// Return the list of case-module mappings.
SmallVector<std::pair<SymbolRefAttr, FlatSymbolRefAttr>, 1>
getTargetChoices();

/// Clone this instance with inserted ports.
InstanceChoiceOp cloneWithInsertedPorts(
ArrayRef<std::pair<unsigned, PortInfo>> insertions);

/// Clone this instance with inserted ports, then replaces uses.
InstanceChoiceOp cloneWithInsertedPortsAndReplaceUses(
ArrayRef<std::pair<unsigned, PortInfo>> insertions);

/// Clone this instance with erased ports.
InstanceChoiceOp cloneWithErasedPorts(const llvm::BitVector &erasures);

/// Clone this instance with erased ports, then replaces uses.
InstanceChoiceOp cloneWithErasedPortsAndReplaceUses(
const llvm::BitVector &erasures);
}];

let builders = [
Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/FIRRTL/FIRRTLAnnotationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ InstanceOp firrtl::addPortsToModule(FModuleLike mod, InstanceOp instOnPath,
// Now update all the instances of `mod`.
for (auto *use : instancePathcache.instanceGraph.lookup(mod)->uses()) {
InstanceOp useInst = cast<InstanceOp>(use->getInstance());
auto clonedInst = useInst.cloneAndInsertPorts({{portNo, portInfo}});
auto clonedInst =
useInst.cloneWithInsertedPortsAndReplaceUses({{portNo, portInfo}});
if (useInst == instOnPath)
clonedInstOnPath = clonedInst;
// Update all occurences of old instance.
instancePathcache.replaceInstance(useInst, clonedInst);
if (targetCaches)
targetCaches->replaceOp(useInst, clonedInst);
useInst->replaceAllUsesWith(clonedInst.getResults().drop_back());
useInst->erase();
}
return clonedInstOnPath;
Expand Down
Loading