13#include "mlir/Analysis/Liveness.h"
14#include "mlir/Dialect/SCF/IR/SCF.h"
15#include "mlir/IR/Dominance.h"
16#include "llvm/Support/Debug.h"
18#define DEBUG_TYPE "llhd-hoist-nets"
22#define GEN_PASS_DEF_HOISTNETSPASS
23#include "circt/Dialect/LLHD/LLHDPasses.h.inc"
32struct HoistNetsPass :
public llhd::impl::HoistNetsPassBase<HoistNetsPass> {
34 void runOnOperation()
override;
37 void hoistProbes(Region *region);
41void HoistNetsPass::hoistProbes(Region *region) {
42 Operation *parentOp = region->getParentOp();
43 DominanceInfo dominance(parentOp);
46 SmallVector<ProbeNetOp> probes;
47 region->walk([&](ProbeNetOp probe) {
48 if (dominance.properlyDominates(probe.getNet(), parentOp))
49 probes.push_back(probe);
57 if (
auto processOp = dyn_cast<ProcessOp>(parentOp)) {
58 SmallVector<WaitOp> waitOps;
59 for (
auto &block : *region)
60 if (
auto waitOp = dyn_cast<WaitOp>(block.getTerminator()))
61 waitOps.push_back(waitOp);
62 if (!waitOps.empty()) {
63 Liveness liveness(processOp);
64 for (
auto probe : probes)
69 OpBuilder builder(parentOp);
70 for (
auto probe : probes) {
71 auto *clone = builder.clone(*probe);
72 probe.replaceAllUsesWith(clone);
77void HoistNetsPass::runOnOperation() {
78 SmallVector<Region *> regions;
79 getOperation()->walk([&](Operation *op) {
80 if (isa<ProcessOp, FinalOp, CombinationalOp, scf::IfOp>(op))
81 for (
auto ®ion : op->getRegions())
83 regions.push_back(®ion);
85 for (
auto *region : regions) {
void captureAcrossWait(Value value, ArrayRef< WaitOp > waitOps, mlir::Liveness &liveness, mlir::DominanceInfo &dominance)
Add a value as block argument to a list of wait ops and update uses of the value to use the added blo...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.