CIRCT 24.0.0git
Loading...
Searching...
No Matches
HWIMDeadCodeElim.cpp
Go to the documentation of this file.
1//===- IMDeadCodeElim.cpp - Intermodule Dead Code Elimination ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13#include "circt/Support/Utils.h"
14#include "mlir/IR/BuiltinAttributes.h"
15#include "mlir/IR/Iterators.h"
16#include "mlir/Interfaces/SideEffectInterfaces.h"
17#include "llvm/ADT/DenseMapInfoVariant.h"
18#include "llvm/ADT/PostOrderIterator.h"
19#include "llvm/ADT/SmallVector.h"
20#include <variant>
21
22#define DEBUG_TYPE "hw-imdeadcodeelim"
23
24namespace circt {
25namespace hw {
26#define GEN_PASS_DEF_IMDEADCODEELIM
27#include "circt/Dialect/HW/Passes.h.inc"
28} // namespace hw
29} // namespace circt
30
31using namespace circt;
32using namespace hw;
33
34namespace {
35struct HWIMDeadCodeElim
36 : circt::hw::impl::IMDeadCodeElimBase<HWIMDeadCodeElim> {
37 using Base::Base;
38
39 void runOnOperation() override;
40
41private:
42 using ElementType = std::variant<Value, HWModuleLike, HWInstanceLike>;
43
44 void markAlive(ElementType element) {
45 if (!liveElements.insert(element).second)
46 return;
47 worklist.push_back(element);
48 }
49
50 bool isKnownAlive(HWInstanceLike instanceLike) const {
51 return liveElements.count(instanceLike);
52 }
53 bool isKnownAlive(Value value) const {
54 assert(value && "null should not be used");
55 return liveElements.count(value);
56 }
57 bool isAssumedDead(Value value) const { return !isKnownAlive(value); }
58 bool isAssumedDead(Operation *op) const {
59 return llvm::none_of(op->getResults(),
60 [&](Value value) { return isKnownAlive(value); });
61 }
62 bool isBlockExecutable(Block *block) { return executableBlocks.count(block); }
63
64 SmallVector<ElementType, 64> worklist;
65 llvm::DenseSet<ElementType> liveElements;
66
67 InstanceGraph *instanceGraph;
68 DenseSet<Block *> executableBlocks;
69
70 void markBlockExecutable(Block *block);
71
72 void visitInstanceLike(HWInstanceLike instanceLike);
73 void visitValue(Value value);
74
75 void rewriteModuleSignature(HWModuleOp module);
76 void eraseEmptyModule(HWModuleOp module);
77 void rewriteModuleBody(HWModuleOp module);
78
79 void markUnknownSideEffectOp(Operation *op);
80 void markInstanceLike(HWInstanceLike instanceLike);
81
82 void markBlockUndeletable(Operation *op) {
83
84 markAlive(op->getParentOfType<HWModuleLike>());
85 }
86};
87} // namespace
88
89static bool hasUnknownSideEffect(Operation *op) {
90 if (!(mlir::isMemoryEffectFree(op) ||
91 mlir::hasSingleEffect<mlir::MemoryEffects::Allocate>(op) ||
92 mlir::hasSingleEffect<mlir::MemoryEffects::Read>(op))) {
93 return true;
94 }
95 if (auto innerSymOp = dyn_cast<InnerSymbolOpInterface>(op)) {
96 if (innerSymOp.getInnerName().has_value())
97 return true;
98 }
99
100 return false;
101}
102
103/// Clone \p instance, but with ports deleted according to
104/// the \p inErasures and \p outErasures BitVectors.
105static InstanceOp cloneWithErasedPorts(InstanceOp &instance,
106 const llvm::BitVector &inErasures,
107 const llvm::BitVector &outErasures) {
108 assert(outErasures.size() >= instance->getNumResults() &&
109 "out_erasures is not at least as large as getNumResults()");
110 assert(inErasures.size() >= instance->getNumOperands() &&
111 "in_erasures is not at least as large as getNumOperands()");
112
113 // Restrict outputs
114 SmallVector<Type> newResultTypes = removeElementsAtIndices<Type>(
115 SmallVector<Type>(instance->result_type_begin(),
116 instance->result_type_end()),
117 outErasures);
118 auto newResultNames = removeElementsAtIndices<mlir::Attribute>(
119 SmallVector<mlir::Attribute>(instance.getResultNames().begin(),
120 instance.getResultNames().end()),
121 outErasures);
122
123 // Restrict inputs
124 auto newOperands = removeElementsAtIndices<mlir::Value>(
125 SmallVector<mlir::Value>(instance->getOperands().begin(),
126 instance->getOperands().end()),
127 inErasures);
128 auto newOperandNames = removeElementsAtIndices<mlir::Attribute>(
129 SmallVector<mlir::Attribute>(instance.getArgNames().begin(),
130 instance.getArgNames().end()),
131 inErasures);
132
133 ImplicitLocOpBuilder builder(instance->getLoc(), instance);
134
135 auto newOpNamesArrayAttr = builder.getArrayAttr(newOperandNames);
136 auto newResultNamesArrayAttr = builder.getArrayAttr(newResultNames);
137
138 auto newInstance = InstanceOp::create(
139 builder, instance->getLoc(), newResultTypes,
140 instance.getInstanceNameAttr(), instance.getModuleName(), newOperands,
141 newOpNamesArrayAttr, newResultNamesArrayAttr, instance.getParameters(),
142 instance.getInnerSymAttr());
143
144 return newInstance;
145}
146
147/// Static method for cloning \p instance of type InstanceOp
148/// with in- and output ports erased based on \p inErasures
149/// and \p outErasures respectively. The users of the results
150/// of the instance are also updated.
151static InstanceOp
153 const llvm::BitVector &inErasures,
154 const llvm::BitVector &outErasures) {
155
156 auto newInstance = cloneWithErasedPorts(instance, inErasures, outErasures);
157
158 // Replace all input operands
159 size_t erased = 0;
160 for (size_t index = 0, e = instance->getNumResults(); index < e; ++index) {
161 auto r1 = instance->getResult(index);
162 if (outErasures[index]) {
163 ++erased;
164 continue;
165 }
166 auto r2 = newInstance->getResult(index - erased);
167 r1.replaceAllUsesWith(r2);
168 }
169
170 return newInstance;
171}
172
173void HWIMDeadCodeElim::markUnknownSideEffectOp(Operation *op) {
174 // For operations with side effects, pessimistically mark results and
175 // operands as alive.
176 for (auto result : op->getResults())
177 markAlive(result);
178 for (auto operand : op->getOperands())
179 markAlive(operand);
180 markBlockUndeletable(op);
181}
182
183void HWIMDeadCodeElim::markInstanceLike(HWInstanceLike instanceLike) {
184
185 for (StringAttr moduleName :
186 instanceLike.getReferencedModuleNamesAttr().getAsRange<StringAttr>()) {
187 auto *node = instanceGraph->lookup(moduleName);
188
189 if (!node)
190 continue;
191
192 auto op = node->getModule();
193
194 // If this is an extmodule, just remember that any inputs and inouts are
195 // alive.
196 // Inputs are exactly what are passed into the module.
197 if (!isa<HWModuleOp>(op.getOperation())) {
198 for (auto operand : instanceLike->getOperands())
199 markAlive(operand);
200
201 markAlive(instanceLike);
202 }
203
204 if (auto moduleLike = dyn_cast<HWModuleLike>(op.getOperation()))
205 markBlockExecutable(moduleLike.getBodyBlock());
206 }
207}
208
209void HWIMDeadCodeElim::markBlockExecutable(Block *block) {
210 if (!block)
211 return;
212
213 if (!executableBlocks.insert(block).second)
214 return; // Already executable.
215
216 // The only case when we do not mark the module alive automatically, is if
217 // it is a private HW module. Blocks nested within other operations of a
218 // module, such as processes, do not affect the liveness of the module.
219 if (auto moduleLike = dyn_cast<HWModuleLike>(block->getParentOp())) {
220 auto module = dyn_cast<HWModuleOp>(moduleLike.getOperation());
221 if (!module)
222 markAlive(moduleLike);
223 else if (module.isPublic())
224 markAlive(module);
225 }
226
227 for (auto &op : *block) {
228 if (auto instance = dyn_cast<HWInstanceLike>(op))
229 markInstanceLike(instance);
230 else if (hasUnknownSideEffect(&op)) {
231 markUnknownSideEffectOp(&op);
232 // Recursively mark any blocks contained within these operations as
233 // executable.
234 for (auto &region : op.getRegions())
235 for (auto &block : region.getBlocks())
236 markBlockExecutable(&block);
237 }
238 }
239}
240/// Propagate liveness backwards through a HWInstanceLike op.
241/// For all possible ModuleLike's that is being instantiated,
242/// - If it is a HWModuleOp, mark outputs selectively based on
243/// their liveness in the module,
244/// - If it is a ModuleLike, but not a HWModuleOp, mark all inputs
245/// as alive.
246/// TODO: this might not be the best idea, since we can still trace
247/// out if something is actually used in a non HWModuleOp.
248void HWIMDeadCodeElim::visitInstanceLike(HWInstanceLike instanceLike) {
249
250 for (mlir::StringAttr moduleName :
251 instanceLike.getReferencedModuleNamesAttr().getAsRange<StringAttr>()) {
252 auto *moduleNode = instanceGraph->lookup(moduleName);
253
254 if (!moduleNode)
255 continue;
256
257 // We apply exact argument liveness iff the module is HW native.
258 if (auto module =
259 dyn_cast<HWModuleOp>(moduleNode->getModule().getOperation())) {
260
261 // All block args are inputs
262 for (auto blockArg : module.getBodyBlock()->getArguments()) {
263 auto portIndex = blockArg.getArgNumber();
264
265 if (isKnownAlive(blockArg))
266 markAlive(instanceLike->getOperand(portIndex));
267 }
268
269 continue;
270 }
271
272 // Otherwise we mark all outputs as alive
273 if (auto extModule =
274 dyn_cast<HWModuleLike>(moduleNode->getModule().getOperation()))
275 markAlive(extModule);
276 }
277}
278
279/// Propagate liveness through \p value.
280/// - If value is a block arg, it means that it had been found
281/// live through propagating within a module, so we mark corresponding
282/// instance inputs as alive.
283/// - If it is the result of an instance op, we mark the corresponding
284/// value in the body of the module as alive.
285/// - Otherwise, we mark all operands of the operation defining `value`
286/// as alive.
287void HWIMDeadCodeElim::visitValue(Value value) {
288 assert(isKnownAlive(value) && "only alive values reach here");
289
290 // Requiring an input port propagates the liveness to each instance.
291 // All arg block elements are inputs
292 if (auto blockArg = dyn_cast<BlockArgument>(value)) {
293 if (auto module =
294 dyn_cast<HWModuleLike>(blockArg.getParentBlock()->getParentOp())) {
295
296 for (auto *instRec : instanceGraph->lookup(module)->uses()) {
297 if (!instRec->getInstance())
298 continue;
299
300 if (auto instance = dyn_cast<HWInstanceLike>(
301 instRec->getInstance().getOperation())) {
302 if (liveElements.contains(instance))
303 markAlive(instance->getOperand(blockArg.getArgNumber()));
304 }
305 }
306 }
307 }
308
309 // Marking an instance port as alive propagates to the corresponding port of
310 // the module.
311 if (auto instanceLike = value.getDefiningOp<HWInstanceLike>()) {
312 auto instanceResult = cast<mlir::OpResult>(value);
313 // Update the src, when it's an instance op.
314
315 // For each module that the instance could refer to,
316 // mark
317 for (mlir::StringAttr moduleName :
318 instanceLike.getReferencedModuleNamesAttr().getAsRange<StringAttr>()) {
319 auto *node = instanceGraph->lookupOrNull(moduleName);
320
321 if (!node)
322 continue;
323
324 Operation *moduleOp = node->getModule().getOperation();
325 auto moduleLike = dyn_cast<HWModuleLike>(moduleOp);
326
327 if (!moduleLike)
328 continue;
329
330 if (!moduleLike.getBodyBlock())
331 continue;
332 auto *moduleOutputOp = moduleLike.getBodyBlock()->getTerminator();
333 auto modulePortVal =
334 moduleOutputOp->getOperand(instanceResult.getResultNumber());
335 markAlive(modulePortVal);
336 markAlive(instanceLike);
337 }
338
339 return;
340 }
341
342 // If the value is defined by an operation, mark its operands alive and any
343 // nested blocks executable.
344 if (auto *op = value.getDefiningOp()) {
345 for (auto operand : op->getOperands())
346 markAlive(operand);
347 for (auto &region : op->getRegions())
348 for (auto &block : region)
349 markBlockExecutable(&block);
350 }
351}
352
353void HWIMDeadCodeElim::runOnOperation() {
354
355 instanceGraph = &getAnalysis<hw::InstanceGraph>();
356
357 for (auto moduleLike : getOperation().getOps<hw::HWModuleLike>()) {
358 // Any ModuleLike that is not a private module will be marked
359 // executable, and all its output ports alive.
360 if (auto module = dyn_cast<HWModuleOp>(moduleLike.getOperation())) {
361 if (!module.isPublic())
362 continue;
363 }
364
365 if (!moduleLike.getBodyBlock())
366 continue;
367
368 markBlockExecutable(moduleLike.getBodyBlock());
369
370 // Do not mark inputs as alive, since they are only
371 // internally relevant.
372
373 // Mark all output values (i.e. SSA vals passed to hw.output) as alive
374 if (moduleLike.getBodyBlock()->empty())
375 continue;
376 auto *moduleOutputOp = moduleLike.getBodyBlock()->getTerminator();
377 if (!dyn_cast<OutputOp>(moduleOutputOp))
378 continue;
379 for (auto port : moduleOutputOp->getOperands())
380 markAlive(port);
381 }
382
383 // If an element changed liveness then propagate liveness through it.
384 while (!worklist.empty()) {
385 auto v = worklist.pop_back_val();
386 if (auto *value = std::get_if<Value>(&v)) {
387 visitValue(*value);
388 } else if (auto *instance = std::get_if<HWInstanceLike>(&v)) {
389 visitInstanceLike(*instance);
390 } else if (std::get_if<HWModuleLike>(&v)) {
391 continue;
392 }
393 }
394
395 if (printLiveness) {
396 auto liveAttr = StringAttr::get(&getContext(), "LIVE");
397 auto deadAttr = StringAttr::get(&getContext(), "DEAD");
398
399 auto getLiveness = [&](bool alive) { return alive ? liveAttr : deadAttr; };
400
401 auto getValLiveness = [&](ValueRange values) {
402 SmallVector<Attribute> liveness;
403 for (auto value : values)
404 liveness.push_back(getLiveness(isKnownAlive(value)));
405 return ArrayAttr::get(&getContext(), liveness);
406 };
407
408 getOperation()->walk([&](Operation *op) {
409 if (auto module = dyn_cast<HWModuleLike>(op)) {
410 if (!module.getBodyBlock())
411 return;
412
413 op->setAttr("op-liveness",
414 getLiveness(isBlockExecutable(module.getBodyBlock())));
415 op->setAttr("val-liveness",
416 getValLiveness(module.getBodyBlock()->getArguments()));
417 return;
418 }
419
420 if (auto outputOp = dyn_cast<OutputOp>(op)) {
421 op->setAttr("val-liveness", getValLiveness(outputOp->getOperands()));
422 return;
423 }
424
425 if (op->getNumResults()) {
426 if (auto instance = dyn_cast<HWInstanceLike>(op))
427 op->setAttr("op-liveness", getLiveness(isKnownAlive(instance)));
428 else
429 op->setAttr("op-liveness", getLiveness(!isAssumedDead(op)));
430 op->setAttr("val-liveness", getValLiveness(op->getResults()));
431 }
432 });
433
434 return;
435 }
436
437 // Rewrite module signatures. Non-executable modules are still rewritten
438 // (dead ports stripped, dead instances removed) but are never erased, to
439 // avoid invalidating symbol references (e.g. sv.verbatim "{{0}}" {symbols =
440 // [@mod]}).
441 for (auto module :
442 llvm::make_early_inc_range(getOperation().getOps<HWModuleOp>()))
443 rewriteModuleSignature(module);
444
445 for (auto module :
446 llvm::make_early_inc_range(getOperation().getOps<HWModuleOp>()))
447 rewriteModuleBody(module);
448
449 for (auto module :
450 llvm::make_early_inc_range(getOperation().getOps<HWModuleOp>())) {
451 eraseEmptyModule(module);
452 }
453
454 // Clean up data structures.
455 executableBlocks.clear();
456 liveElements.clear();
457}
458
459void HWIMDeadCodeElim::rewriteModuleSignature(HWModuleOp module) {
460
461 igraph::InstanceGraphNode *instanceGraphNode = instanceGraph->lookup(module);
462 LLVM_DEBUG(llvm::dbgs() << "Prune ports of module: " << module.getName()
463 << "\n");
464
465 auto replaceInstanceResultWithConst =
466 [&](ImplicitLocOpBuilder &builder, unsigned index, InstanceOp instance) {
467 auto result = instance.getResult(index);
468 assert(isAssumedDead(result));
469
470 auto dummy =
471 mlir::UnrealizedConversionCastOp::create(
472 builder, ArrayRef<Type>{result.getType()}, ArrayRef<Value>{})
473 ->getResult(0);
474 result.replaceAllUsesWith(dummy);
475 return;
476 };
477
478 // First, delete dead instances.
479 for (auto *use : llvm::make_early_inc_range(instanceGraphNode->uses())) {
480 auto maybeInst = use->getInstance();
481 if (!maybeInst)
482 continue;
483
484 auto instance = cast<InstanceOp>(maybeInst);
485
486 if (!isKnownAlive(instance)) {
487 // Replace old instance results with dummy wires.
488 ImplicitLocOpBuilder builder(instance.getLoc(), instance);
489 for (auto index : llvm::seq(0u, instance.getNumResults()))
490 replaceInstanceResultWithConst(builder, index, instance);
491 // Make sure that we update the instance graph.
492 use->erase();
493 instance.erase();
494 }
495 }
496
497 // Ports of public modules cannot be modified.
498 if (module.isPublic())
499 return;
500
501 // Otherwise prepare data structures for tracking dead ports.
502 auto *outputOp = module.getBodyBlock()->getTerminator();
503
504 auto numInPorts = module.getBody().getNumArguments();
505 auto numOutPorts = outputOp->getNumOperands();
506
507 llvm::BitVector deadInPortBitVec(numInPorts);
508 llvm::BitVector deadOutPortBitVec(numOutPorts);
509
510 ImplicitLocOpBuilder builder(module.getLoc(), module.getContext());
511 builder.setInsertionPointToStart(module.getBodyBlock());
512
513 for (auto index : llvm::seq(0u, numInPorts)) {
514 auto inPort = module.getBodyBlock()->getArgument(index);
515 if (isKnownAlive(inPort))
516 continue;
517
518 auto placeholder =
519 mlir::UnrealizedConversionCastOp::create(
520 builder, ArrayRef<Type>{inPort.getType()}, ArrayRef<Value>{})
521 ->getResult(0);
522 inPort.replaceAllUsesWith(placeholder);
523 deadInPortBitVec.set(index);
524 }
525
526 // Find all unused results
527 unsigned erasures = 0;
528 for (auto index : llvm::seq(0u, numOutPorts)) {
529 auto argument = outputOp->getOperand(index - erasures);
530
531 if (isKnownAlive(argument))
532 continue;
533
534 outputOp->eraseOperand(index - erasures);
535 ++erasures;
536
537 deadOutPortBitVec.set(index);
538 }
539
540 // If there is nothing to remove, abort.
541 if (deadInPortBitVec.none() && deadOutPortBitVec.none())
542 return;
543
544 // Erase arguments of the old module from liveSet to prevent from creating
545 // dangling pointers.
546 for (auto arg : module.getBodyBlock()->getArguments())
547 liveElements.erase(arg);
548
549 for (auto op : outputOp->getOperands())
550 liveElements.erase(op);
551
552 // Delete ports from the module.
553 module.erasePorts(SmallVector<unsigned>(deadInPortBitVec.set_bits()),
554 SmallVector<unsigned>(deadOutPortBitVec.set_bits()));
555 module.getBodyBlock()->eraseArguments(deadInPortBitVec);
556
557 // Add arguments of the new module to liveSet.
558 for (auto arg : module.getBodyBlock()->getArguments())
559 liveElements.insert(arg);
560
561 for (auto op : outputOp->getOperands())
562 liveElements.insert(op);
563
564 // Rewrite all instantiation of the module.
565 for (auto *use : llvm::make_early_inc_range(instanceGraphNode->uses())) {
566 auto instance = cast<InstanceOp>(*use->getInstance());
567
568 ImplicitLocOpBuilder builder(instance.getLoc(), instance);
569 // Replace old instance results with dummy constants.
570 for (auto index : deadOutPortBitVec.set_bits())
571 replaceInstanceResultWithConst(builder, index, instance);
572
573 // Since we will rewrite instance op, it is necessary to remove old
574 // instance results from liveSet.
575 for (auto oldResult : instance.getResults())
576 liveElements.erase(oldResult);
577
578 auto newInstance = cloneWithErasePortsAndReplaceUses(
579 instance, deadInPortBitVec, deadOutPortBitVec);
580
581 for (auto newResult : newInstance.getResults())
582 liveElements.insert(newResult);
583
584 instanceGraph->replaceInstance(instance, newInstance);
585 instance->erase();
586 }
587
588 numRemovedPorts += deadInPortBitVec.count() + deadOutPortBitVec.count();
589}
590
591void HWIMDeadCodeElim::rewriteModuleBody(HWModuleOp module) {
592
593 // Walk the IR bottom-up when deleting operations.
594 module.walk<mlir::WalkOrder::PostOrder, mlir::ReverseIterator>(
595 [&](Operation *op) {
596 // Connects to values that we found to be dead can be dropped.
597 LLVM_DEBUG(llvm::dbgs() << "Visit: " << *op << "\n");
598
599 // Remove non-sideeffect op using `isOpTriviallyDead`.
600 // Skip instances - they're handled by
601 // rewriteModuleSignature/eraseEmptyModule and also need erasure from
602 // instanceGraph
603 if (!isa<InstanceOp>(op) && mlir::isOpTriviallyDead(op) &&
604 isAssumedDead(op)) {
605 op->erase();
606 ++numErasedOps;
607 }
608 });
609}
610
611void HWIMDeadCodeElim::eraseEmptyModule(HWModuleOp module) {
612 // Non-executable modules are preserved as empty shells to avoid invalidating
613 // symbol references that may point to them by name.
614 if (!isBlockExecutable(module.getBodyBlock()))
615 return;
616
617 // If the module is not empty, just skip.
618 if (!module.getBodyBlock()->without_terminator().empty())
619 return;
620
621 // It can also be the case that the only `hw.output` is nontrivial, also skip.
622 if (module.getBodyBlock()->getTerminator()->getNumOperands() != 0)
623 return;
624
625 // We cannot delete public modules so generate a warning.
626 if (module.isPublic()) {
627 mlir::emitWarning(module.getLoc())
628 << "module `" << module.getName()
629 << "` is empty but cannot be removed because the module is public";
630 return;
631 }
632
633 // Ok, the module is empty. Delete instances unless they have symbols.
634 LLVM_DEBUG(llvm::dbgs() << "Erase " << module.getName() << "\n");
635 igraph::InstanceGraphNode *instanceGraphNode =
636 instanceGraph->lookup(module.getModuleNameAttr());
637
638 SmallVector<Location> instancesWithSymbols;
639 for (auto *use : llvm::make_early_inc_range(instanceGraphNode->uses())) {
640 auto maybeInst = use->getInstance();
641 if (!maybeInst)
642 continue;
643
644 auto instance = cast<InstanceOp>(maybeInst);
645 if (instance.getInnerSym()) {
646 instancesWithSymbols.push_back(instance.getLoc());
647 continue;
648 }
649 use->erase();
650 instance.erase();
651 }
652
653 // If there is an instance with a symbol, we don't delete the module itself.
654 if (!instancesWithSymbols.empty()) {
655 auto diag = module.emitWarning()
656 << "module `" << module.getName()
657 << "` is empty but cannot be removed because an instance is "
658 "referenced by name";
659 diag.attachNote(FusedLoc::get(&getContext(), instancesWithSymbols))
660 << "these are instances with symbols";
661 return;
662 }
663
664 // We cannot delete alive modules.
665 if (liveElements.contains(module))
666 return;
667
668 instanceGraph->erase(instanceGraphNode);
669 ++numErasedModules;
670}
assert(baseType &&"element must be base type")
static InstanceOp cloneWithErasePortsAndReplaceUses(InstanceOp &instance, const llvm::BitVector &inErasures, const llvm::BitVector &outErasures)
Static method for cloning instance of type InstanceOp with in- and output ports erased based on inEra...
static bool hasUnknownSideEffect(Operation *op)
static InstanceOp cloneWithErasedPorts(InstanceOp &instance, const llvm::BitVector &inErasures, const llvm::BitVector &outErasures)
Clone instance, but with ports deleted according to the inErasures and outErasures BitVectors.
static bool hasUnknownSideEffect(Operation *op)
void erase(igraph::InstanceGraphNode *node) override
Erases a module, updating links to entry.
llvm::iterator_range< UseIterator > uses()
auto getModule()
Get the module that this node is tracking.
InstanceGraphNode * lookupOrNull(StringAttr name)
Lookup an module by name.
virtual void replaceInstance(InstanceOpInterface inst, InstanceOpInterface newInst)
Replaces an instance of a module with another instance.
InstanceGraphNode * lookup(ModuleOpInterface op)
Look up an InstanceGraphNode for a module.
std::map< std::string, std::set< std::string > > InstanceGraph
Iterates over the handshake::FuncOp's in the program to build an instance graph.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
static SmallVector< T > removeElementsAtIndices(ArrayRef< T > input, const llvm::BitVector &indicesToDrop)
Remove elements from the input array corresponding to set bits in indicesToDrop, returning the elemen...
Definition Utils.h:35
Definition hw.py:1