|
CIRCT 24.0.0git
|
Sink gated-clock enables into ops across module boundaries. More...
#include <GatedClockConversion.h>

Classes | |
| struct | ClockPairPlan |
| (baseClk, enable) pair planned for a clock value. More... | |
| struct | EnableNode |
Enable accumulation DAG node: value(id) = parent == kNoEnable ? term : (value(parent) & term) Nodes are shared by every consumer of a pair, so a cascade of gates emits one and per gate no matter how many roots it feeds. More... | |
| struct | InstanceDrive |
| Caller-side connects driving a planned input port pair. More... | |
| class | MatRef |
| A reference to a clock/enable value that can also name values which do not exist yet (a planned port, a planned wire). More... | |
| struct | PortPairPlan |
| (baseClock, enable) port pair to append to a module. More... | |
| struct | RootRewrite |
Root rewrite applied by applyPlan(): clock the op by baseClk and sink enableId into it. More... | |
| struct | WirePairPlan |
Temporary (base clock, enable) carrier wires at the top of mod, standing in for a wire/node alias of a gated clock. More... | |
Public Member Functions | |
| GatedClockConversion (InstanceGraph &ig) | |
| LogicalResult | addRoot (Operation *op) |
| LogicalResult | run () |
| void | dump () const |
Private Types | |
| using | PortPlanKey = std::pair< FModuleOp, unsigned > |
The (module, clock port index) key of a PortPairPlan. | |
Private Member Functions | |
| LogicalResult | analyzeFrom (ArrayRef< Value > seeds) |
| void | computeGatedClocks () |
| void | plan () |
| Value | processEdge (const ClockEdge &edge, Value srcClk, FModuleOp srcMod, MatRef baseClk, unsigned enableId) |
| unsigned | newEnableNode (unsigned parent, MatRef term, Location loc, MatRef anchor) |
| unsigned | newEnableLeaf (MatRef term, Location loc) |
| LogicalResult | applyPlan () |
| void | createPlannedWires () |
| void | insertPlannedPorts () |
| LogicalResult | emitPlannedIR () |
| Value | resolve (MatRef ref) |
| Value | lower (unsigned enableId) |
| LogicalResult | rewriteRoot (Operation *op, Value baseClk, Value enable) |
| Value | gateEnableOf (ClockGateIntrinsicOp gate) |
| Value | getOrCreateConstU1One (FModuleOp mod) |
| void | connectMaterializedToInstancePorts (InstanceOp inst, unsigned clkPortIndex, unsigned enPortIndex, Value materializedClk, Value materializedEn) |
| void | eliminateTemporaryWires () |
| Operation * | liveInstance (Operation *inst) const |
| void | dumpPlan () const |
| void | planAlias (Value dstClk, FModuleOp srcMod, MatRef baseClk, unsigned enableId) |
| void | planGate (ClockGateIntrinsicOp gate, Value dstClk, MatRef baseClk, unsigned enableId) |
| void | planInstancePort (Direction dir, InstanceOp inst, Value dstClk, Value srcClk, MatRef baseClk, unsigned enableId) |
| void | planMultiplyInstantiatedInput (Value srcClk, MatRef baseClk, unsigned enableId) |
| std::pair< unsigned, unsigned > | planGatedPorts (InstanceOp inst, FModuleOp childMod, unsigned gatedClkIndex, Direction dir, MatRef baseClk, unsigned enableId) |
| void | recordInstanceDrive (InstanceOp inst, const PortPairPlan &plan, MatRef baseClk, unsigned enableId) |
Private Attributes | |
| InstanceGraph & | ig |
| SmallVector< std::pair< Operation *, Value > > | roots |
| DenseSet< Value > | visited |
| DenseMap< Value, SmallVector< ClockEdge > > | srcToDstClocks |
| SmallVector< Value > | baseClks |
| DenseSet< Value > | gatedClocks |
| DenseMap< Value, ClockPairPlan > | clockEnablePairs |
| SmallVector< EnableNode > | enableNodes |
| SmallVector< Value > | plannedWireValues |
| SmallVector< Value > | loweredEnables |
| SmallVector< RootRewrite > | rootRewrites |
| SmallVector< WirePairPlan > | wirePlans |
| llvm::MapVector< PortPlanKey, PortPairPlan > | portPlans |
| llvm::MapVector< FModuleOp, SmallVector< PortPlanKey > > | plansPerModule |
| DenseMap< FModuleOp, unsigned > | nextPortIdx |
| llvm::MapVector< std::pair< InstanceOp, unsigned >, InstanceDrive > | instanceDrives |
| DenseMap< ClockGateIntrinsicOp, Value > | gateEnableCache |
| DenseMap< FModuleOp, Value > | constU1Cache |
| DenseMap< Operation *, Operation * > | instClones |
| SmallVector< InstanceOp > | deadInstances |
| SmallVector< WireOp > | wireOps |
| MLIRContext * | context |
| Type | clockType |
| Type | u1Type |
Static Private Attributes | |
| static constexpr unsigned | kNoEnable = ~0u |
Sentinel EnableNode index meaning "no enable at all". | |
Sink gated-clock enables into ops across module boundaries.
Backward traversal from each root's clock builds the clock flow graph, a forward pass plans the (base, AND-of-enables) pair of every clock value, and applyPlan() then materializes the whole plan in one shot.
Invariant: analysis and planning never mutate the IR, and no plan record is read after the mutation it describes happened. That is what makes stale value remapping structurally impossible; see MatRef.
Preconditions: run after firrtl-expand-whens, so every clock net and register has a single driver. Clock loops are not diagnosed here; see firrtl-check-comb-loops.
NOT thread-safe: port insertion mutates module signatures globally.
Definition at line 50 of file GatedClockConversion.h.
|
private |
The (module, clock port index) key of a PortPairPlan.
Definition at line 180 of file GatedClockConversion.h.
|
inlineexplicit |
Definition at line 52 of file GatedClockConversion.h.
| LogicalResult GatedClockConversion::addRoot | ( | Operation * | op | ) |
Definition at line 229 of file GatedClockConversion.cpp.
References circt::firrtl::clk, and roots.
|
private |
Definition at line 240 of file GatedClockConversion.cpp.
References circt::firrtl::Alias, assert(), baseClks, circt::firrtl::clk, circt::firrtl::Gate, circt::firrtl::getModuleScopedDriver(), ig, circt::firrtl::In, circt::firrtl::InstanceIn, circt::firrtl::InstanceOut, circt::igraph::InstanceGraph::lookup(), srcToDstClocks, and visited.
Referenced by run().
|
private |
Definition at line 765 of file GatedClockConversion.cpp.
References createPlannedWires(), emitPlannedIR(), and insertPlannedPorts().
Referenced by run().
|
private |
Definition at line 566 of file GatedClockConversion.cpp.
References circt::firrtl::clk, circt::firrtl::Gate, gatedClocks, and srcToDstClocks.
Referenced by run().
|
private |
Definition at line 209 of file GatedClockConversion.cpp.
References context, and getOrCreateConstU1One().
Referenced by emitPlannedIR().
|
private |
Definition at line 661 of file GatedClockConversion.cpp.
References clockType, plannedWireValues, u1Type, wireOps, and wirePlans.
Referenced by applyPlan().
| void GatedClockConversion::dump | ( | ) | const |
Definition at line 884 of file GatedClockConversion.cpp.
References baseClks, and srcToDstClocks.
Referenced by run().
|
private |
Definition at line 912 of file GatedClockConversion.cpp.
References enableNodes, circt::firrtl::In, instanceDrives, kNoEnable, circt::firrtl::Out, portPlans, rootRewrites, and wirePlans.
Referenced by run().
|
private |
|
private |
Definition at line 716 of file GatedClockConversion.cpp.
References connectMaterializedToInstancePorts(), context, instanceDrives, liveInstance(), lower(), circt::firrtl::Out, plannedWireValues, portPlans, resolve(), rewriteRoot(), rootRewrites, and wirePlans.
Referenced by applyPlan().
|
private |
Definition at line 186 of file GatedClockConversion.cpp.
References gateEnableCache.
Referenced by resolve().
|
private |
Definition at line 195 of file GatedClockConversion.cpp.
References constU1Cache, and context.
Referenced by connectMaterializedToInstancePorts().
|
private |
Definition at line 677 of file GatedClockConversion.cpp.
References assert(), circt::firrtl::GatedClockConversion::PortPairPlan::baseIdx, clockType, context, deadInstances, circt::firrtl::GatedClockConversion::PortPairPlan::dir, circt::firrtl::GatedClockConversion::PortPairPlan::gatedClkIndex, ig, instClones, circt::igraph::InstanceGraph::lookup(), plansPerModule, portPlans, circt::igraph::InstanceGraph::replaceInstance(), and u1Type.
Referenced by applyPlan().
|
inlineprivate |
Definition at line 272 of file GatedClockConversion.h.
References instClones.
Referenced by emitPlannedIR(), and resolve().
|
private |
Definition at line 147 of file GatedClockConversion.cpp.
References circt::firrtl::GatedClockConversion::EnableNode::anchor, assert(), context, enableNodes, kNoEnable, circt::firrtl::GatedClockConversion::EnableNode::loc, loweredEnables, circt::firrtl::GatedClockConversion::EnableNode::parent, resolve(), and circt::firrtl::GatedClockConversion::EnableNode::term.
Referenced by emitPlannedIR().
|
inlineprivate |
Definition at line 225 of file GatedClockConversion.h.
References kNoEnable, and newEnableNode().
Referenced by planAlias(), and planInstancePort().
|
private |
Definition at line 141 of file GatedClockConversion.cpp.
References enableNodes.
Referenced by newEnableLeaf(), and planGate().
|
private |
Definition at line 622 of file GatedClockConversion.cpp.
References assert(), baseClks, clockEnablePairs, kNoEnable, circt::firrtl::GatedClockConversion::MatRef::of(), processEdge(), and srcToDstClocks.
Referenced by planGatedPorts(), recordInstanceDrive(), and run().
|
private |
Definition at line 426 of file GatedClockConversion.cpp.
References clockEnablePairs, kNoEnable, newEnableLeaf(), circt::firrtl::GatedClockConversion::MatRef::plannedWire(), and wirePlans.
Referenced by processEdge().
|
private |
Definition at line 441 of file GatedClockConversion.cpp.
References clockEnablePairs, circt::firrtl::GatedClockConversion::MatRef::gateEnable(), newEnableNode(), and circt::firrtl::GatedClockConversion::MatRef::of().
Referenced by processEdge().
|
private |
Definition at line 469 of file GatedClockConversion.cpp.
References assert(), circt::firrtl::In, kNoEnable, nextPortIdx, circt::firrtl::Out, plan(), plansPerModule, portPlans, and recordInstanceDrive().
Referenced by planInstancePort().
|
private |
Definition at line 499 of file GatedClockConversion.cpp.
References assert(), clockEnablePairs, gatedClocks, ig, circt::firrtl::GatedClockConversion::MatRef::instResult(), kNoEnable, circt::firrtl::GatedClockConversion::MatRef::moduleArg(), newEnableLeaf(), circt::firrtl::GatedClockConversion::MatRef::of(), circt::firrtl::Out, and planGatedPorts().
Referenced by processEdge().
|
private |
Definition at line 546 of file GatedClockConversion.cpp.
References assert(), ig, portPlans, and recordInstanceDrive().
Referenced by processEdge().
|
private |
Definition at line 588 of file GatedClockConversion.cpp.
References circt::firrtl::Alias, assert(), clockEnablePairs, circt::firrtl::ClockEdge::dst, circt::firrtl::Gate, circt::firrtl::ClockEdge::gate(), circt::firrtl::In, circt::firrtl::ClockEdge::instance(), circt::firrtl::InstanceIn, circt::firrtl::InstanceOut, circt::firrtl::ClockEdge::kind, circt::firrtl::Out, planAlias(), planGate(), planInstancePort(), and planMultiplyInstantiatedInput().
Referenced by plan().
|
private |
Definition at line 450 of file GatedClockConversion.cpp.
References assert(), circt::firrtl::GatedClockConversion::InstanceDrive::baseIdx, circt::firrtl::In, instanceDrives, and plan().
Referenced by planGatedPorts(), and planMultiplyInstantiatedInput().
|
private |
Definition at line 121 of file GatedClockConversion.cpp.
References circt::firrtl::GatedClockConversion::MatRef::Direct, circt::firrtl::GatedClockConversion::MatRef::gate(), circt::firrtl::GatedClockConversion::MatRef::GateEnable, gateEnableOf(), circt::firrtl::GatedClockConversion::MatRef::getIndex(), circt::firrtl::GatedClockConversion::MatRef::getKind(), circt::firrtl::GatedClockConversion::MatRef::getOp(), circt::firrtl::GatedClockConversion::MatRef::getValue(), circt::firrtl::GatedClockConversion::MatRef::InstResult, liveInstance(), circt::firrtl::GatedClockConversion::MatRef::ModuleArg, circt::firrtl::GatedClockConversion::MatRef::None, circt::firrtl::GatedClockConversion::MatRef::PlannedWire, and plannedWireValues.
Referenced by emitPlannedIR(), and lower().
|
private |
Definition at line 363 of file GatedClockConversion.cpp.
Referenced by emitPlannedIR().
| LogicalResult GatedClockConversion::run | ( | ) |
Definition at line 822 of file GatedClockConversion.cpp.
References analyzeFrom(), applyPlan(), circt::firrtl::clk, clockEnablePairs, clockType, computeGatedClocks(), context, deadInstances, dump(), dumpPlan(), eliminateTemporaryWires(), plan(), rootRewrites, roots, and u1Type.
|
private |
Definition at line 313 of file GatedClockConversion.h.
Referenced by analyzeFrom(), dump(), and plan().
|
private |
Definition at line 318 of file GatedClockConversion.h.
Referenced by plan(), planAlias(), planGate(), planInstancePort(), processEdge(), and run().
|
private |
Definition at line 366 of file GatedClockConversion.h.
Referenced by createPlannedWires(), insertPlannedPorts(), and run().
|
private |
Definition at line 353 of file GatedClockConversion.h.
Referenced by getOrCreateConstU1One().
|
private |
Definition at line 364 of file GatedClockConversion.h.
Referenced by connectMaterializedToInstancePorts(), emitPlannedIR(), getOrCreateConstU1One(), insertPlannedPorts(), lower(), and run().
|
private |
Definition at line 359 of file GatedClockConversion.h.
Referenced by insertPlannedPorts(), and run().
|
private |
Definition at line 322 of file GatedClockConversion.h.
Referenced by dumpPlan(), lower(), and newEnableNode().
|
private |
Definition at line 316 of file GatedClockConversion.h.
Referenced by computeGatedClocks(), and planInstancePort().
|
private |
Definition at line 350 of file GatedClockConversion.h.
Referenced by gateEnableOf().
|
private |
Definition at line 303 of file GatedClockConversion.h.
Referenced by analyzeFrom(), insertPlannedPorts(), planInstancePort(), and planMultiplyInstantiatedInput().
|
private |
Definition at line 346 of file GatedClockConversion.h.
Referenced by dumpPlan(), emitPlannedIR(), and recordInstanceDrive().
|
private |
Definition at line 356 of file GatedClockConversion.h.
Referenced by insertPlannedPorts(), and liveInstance().
|
staticconstexprprivate |
Sentinel EnableNode index meaning "no enable at all".
Definition at line 64 of file GatedClockConversion.h.
Referenced by dumpPlan(), lower(), newEnableLeaf(), plan(), planAlias(), planGatedPorts(), and planInstancePort().
|
private |
Definition at line 329 of file GatedClockConversion.h.
Referenced by lower().
|
private |
Definition at line 341 of file GatedClockConversion.h.
Referenced by planGatedPorts().
|
private |
Definition at line 326 of file GatedClockConversion.h.
Referenced by createPlannedWires(), emitPlannedIR(), and resolve().
|
private |
Definition at line 338 of file GatedClockConversion.h.
Referenced by insertPlannedPorts(), and planGatedPorts().
|
private |
Definition at line 337 of file GatedClockConversion.h.
Referenced by dumpPlan(), emitPlannedIR(), insertPlannedPorts(), planGatedPorts(), and planMultiplyInstantiatedInput().
|
private |
Definition at line 331 of file GatedClockConversion.h.
Referenced by dumpPlan(), emitPlannedIR(), and run().
|
private |
Definition at line 305 of file GatedClockConversion.h.
|
private |
Definition at line 311 of file GatedClockConversion.h.
Referenced by analyzeFrom(), computeGatedClocks(), dump(), and plan().
|
private |
Definition at line 366 of file GatedClockConversion.h.
Referenced by createPlannedWires(), insertPlannedPorts(), and run().
|
private |
Definition at line 309 of file GatedClockConversion.h.
Referenced by analyzeFrom().
|
private |
Definition at line 362 of file GatedClockConversion.h.
Referenced by createPlannedWires(), and eliminateTemporaryWires().
|
private |
Definition at line 333 of file GatedClockConversion.h.
Referenced by createPlannedWires(), dumpPlan(), emitPlannedIR(), and planAlias().